In this document we add language selection.
Estimated completion time: ? minutes.
Table of contents
cfg
fileNow that you have your web site in English you start to wonder why there's no Russian version, you're Russian after all!
You set on to create the following directory structure:
cfg
en/item.template
en/index.md
en/cv.md
ru/item.template
ru/index.md
ru/cv.md
Let's look at the contents of these files closer.
cfg
filecfg
file has the following contents:
input = en;ru
item = item.template
As you see, input
can accept multiple directories separated by ;
symbol: PSKOV will go over each directory specified and run as before.
In this case, both en/
and ru/
directories have their own item.template
file.
en/item.template
contents:
- - - - Collapsed for brevity - - - -
<title>Serov</title>
</head>
<body>
<div id="header">
<strong>Serov</strong>
<a href="index.html">About me</a>
<a href="cv.html">CV</a>
<div id="lang">
<a href="../en/PSKOV_ITEM_URL">EN</a>
<a href="../ru/PSKOV_ITEM_URL">RU</a>
</div>
</div>
<center>
- - - - Collapsed for brevity - - - -
ru/item.template
contents:
- - - - Collapsed for brevity - - - -
<title>Серов</title>
</head>
<body>
<div id="header">
<strong>Серов</strong>
<a href="index.html">Обо мне</a>
<a href="cv.html">Резюме</a>
<div id="lang">
<a href="../en/PSKOV_ITEM_URL">EN</a>
<a href="../ru/PSKOV_ITEM_URL">RU</a>
</div>
</div>
<center>
- - - - Collapsed for brevity - - - -
Note: beginning and ending were collapsed for brevity.
As you can see, both en/item.template
and ru/item.template
look similar to item.template
we saw before.
The changes include:
<div id="lang">...</div>
section to present language selectionLanguage selection uses new PSKOV constant:
PSKOV constant | Description |
---|---|
PSKOV_ITEM_URL |
Provides <slug>.html value for the page |
As you see, PSKOV_ITEM_URL
is all you need to have your page in as many languages as you please.
en/index.md
and en/cv.md
files look exactly as before. ru/index.md
and ru/cv.md
are simply Russian variants of the same pages.
For example, ru/cv.md
has the following contents:
Title: Резюме
Slug: cv
Здесь вы можете увидеть моё резюме в том случае, если мои произведения всё ещё вас интересуют. Я использовал современный подход ИТ для структурирования своего резюме в виде пар ключ-значение словаря (карты). Наслаждайтесь!
| Ключ | Значение |
|---|---|
| Имя | Валентин Серов |
| Возраст | 46 |
| Семейное положение | Женат |
| Страна | Российская Империя |
| Учёба | Императорская Академия художеств |
| Звания | * академик ИАХ (1898) <br> * действительный член ИАХ (1903) |
Note: Russian page has exactly the same Slug:
value as English one.
Launch LFSA so that it points to directory with the files we just observed:
$ /path/to/local-file-system-access.py /path/to/dir/02.Language
Generate the site:
Generate
buttonen/index.html
or ru/index.html
from the site's directory locallyTake time to observe just how little effort you spent to have your web site localized.