Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

education.04.lang.md 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. Title: Education: 04. Language
  2. Date: 2019-06-18 00:00
  3. Category: Page
  4. Slug: education.04.lang
  5. Lang: en
  6. | < Back | Index | Next > |
  7. |---|---|---|
  8. | [03. Site][prev] | [Education][index] | [05. Blog][next] |
  9. </div><div class="contents">
  10. In this document we add language selection.
  11. Estimated completion time: 10 minutes.
  12. **Table of contents**
  13. * [01. Localization](#localization)
  14. * [02. Investigate `pskov.cfg` file](#cfg)
  15. * [03. Investigate template files](#item)
  16. * [04. Investigate Markdown files](#md)
  17. * [05. Launch LFSA and generate the site](#gen)
  18. * [06. Summary](#summary)
  19. <a name="localization"/>
  20. ## 01. Localization
  21. Now that you have your web site in English you start to wonder why there's no Russian version, you're Russian after all!
  22. You set on to create the following [directory structure][02-files]:
  23. * `pskov.cfg`
  24. * `en/item.template`
  25. * `en/about.md`
  26. * `en/cv.md`
  27. * `ru/item.template`
  28. * `ru/about.md`
  29. * `ru/cv.md`
  30. Let's look at the contents of these files closer.
  31. <a name="cfg"/>
  32. ## 02. Investigate `pskov.cfg` file
  33. `pskov.cfg` file has the following contents:
  34. ```
  35. input = en;ru
  36. item = item.template
  37. ```
  38. As you see, `input` can accept multiple directories separated by `;` symbol: **PSKOV** will go over each directory specified and run as before.
  39. In this case, both `en/` and `ru/` directories have their own `item.template` file.
  40. <a name="item"/>
  41. ## 03. Investigate template files
  42. * `en/item.template` contents:
  43. ```
  44. - - - - Collapsed for brevity - - - -
  45. <title>Serov</title>
  46. </head>
  47. <body>
  48. <div id="header">
  49. <strong>Serov</strong>
  50. <a href="about.html">About me</a>
  51. <a href="cv.html">CV</a>
  52. <div id="lang">
  53. <a href="../en/PSKOV_ITEM_URL">EN</a>
  54. <a href="../ru/PSKOV_ITEM_URL">RU</a>
  55. </div>
  56. </div>
  57. <center>
  58. - - - - Collapsed for brevity - - - -
  59. ```
  60. * `ru/item.template` contents:
  61. ```
  62. - - - - Collapsed for brevity - - - -
  63. <title>Серов</title>
  64. </head>
  65. <body>
  66. <div id="header">
  67. <strong>Серов</strong>
  68. <a href="about.html">Обо мне</a>
  69. <a href="cv.html">Резюме</a>
  70. <div id="lang">
  71. <a href="../en/PSKOV_ITEM_URL">EN</a>
  72. <a href="../ru/PSKOV_ITEM_URL">RU</a>
  73. </div>
  74. </div>
  75. <center>
  76. - - - - Collapsed for brevity - - - -
  77. ```
  78. **Note**: beginning and ending were collapsed for brevity.
  79. As you can see, both `en/item.template` and `ru/item.template` look similar to `item.template` we saw [before][prev].
  80. The changes include:
  81. * use of `<div id="lang">...</div>` section to present language selection
  82. * localization of titles into English and Russian
  83. Language selection uses new **PSKOV** constant:
  84. | PSKOV constant | Description |
  85. |---|---|
  86. | `PSKOV_ITEM_URL` | Provides generated page's file name |
  87. As you see, `PSKOV_ITEM_URL` is all you need to have your page in as many languages as you please.
  88. <a name="md"/>
  89. ## 04. Investigate Markdown files
  90. `en/about.md` and `en/cv.md` files look almost exactly as [before][prev]. `ru/about.md` and `ru/cv.md` are simply Russian variants of corresponding pages.
  91. For example, `ru/cv.md` has the following contents:
  92. ```
  93. Title: Резюме
  94. Slug: cv
  95. Здесь вы можете увидеть моё резюме в том случае, если мои произведения всё ещё вас интересуют. Я использовал современный подход ИТ для структурирования своего резюме в виде пар ключ-значение словаря (карты). Наслаждайтесь!
  96. | Ключ | Значение |
  97. |---|---|
  98. | Имя | Валентин Серов |
  99. | Возраст | 46 |
  100. | Семейное положение | Женат |
  101. | Страна | Российская Империя |
  102. | Учёба | Императорская Академия художеств |
  103. | Звания | * академик ИАХ (1898) <br> * действительный член ИАХ (1903) |
  104. ```
  105. **Note**: Russian page has exactly the same `Slug` value as English one.
  106. <a name="gen"/>
  107. ## 05. Launch LFSA and generate the site
  108. Launch [LFSA][lfsa] so that it points to directory with the files we just observed:
  109. ```
  110. $ /path/to/lfsa_1.0.0.py /path/to/dir/02.Language
  111. ```
  112. Generate the site:
  113. * Go to [Tool][tool] page
  114. * Press `Generate` button
  115. * Open generated `en/about.html` or `ru/about.html` from the site's directory locally
  116. * Switch language to verify language selection works fine
  117. <a name="summary"/>
  118. ## 06. Summary
  119. You have successfully added language selection. [Check out the result][02-sample].
  120. Introduced PSKOV constants include:
  121. | PSKOV constant | Description |
  122. |---|---|
  123. | `PSKOV_ITEM_URL` | Provides generated page's file name |
  124. </div><div class="contents">
  125. | < Back | Index | Next > |
  126. |---|---|---|
  127. | [03. Site][prev] | [Education][index] | [05. Blog][next] |
  128. [index]: education.html
  129. [prev]: education.03.site.html
  130. [next]: education.05.blog.html
  131. [02-files]: https://github.com/OGStudio/site-pskov-sample/tree/master/02.Language
  132. [02-sample]: http://opengamestudio.org/pskov/sample/02.Language/en/about.html
  133. [lfsa]: http://opengamestudio.org/lfsa
  134. [tool]: http://opengamestudio.org/pskov