diff --git a/README.md b/README.md index 62304c1..4407e34 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,11 @@ or to run it in Pycharm, use the run template that's specified and it should wor ## Translations -The site uses babel for translations. +The site uses PyBabel for translations. -Text to translate is marked up in html and py templates and files, then a messages.pot is build via pybabel, which -collates all the text to translate into a single file. +Text to translate is marked up in `.html` and `.py` templates and files with the [gettext](https://en.wikipedia.org/wiki/Gettext) mechanism. Then a `messages.pot` file is build via Pybabel, which collates all the text to translate. Based on the content of the `.pot` file translation files `messages.po` are created for all specified language codes. Finally, the `.po` files are compiled into `.mo` files, which are then used on the page. + +1. Extract text to translation To build/re-build the translation messages.pot use: @@ -39,16 +40,19 @@ To build/re-build the translation messages.pot use: pipenv run pybabel extract -F babel.cfg -o rh_ui/translations/messages.pot . ``` +2. Create new language file +> [!CAUTION] +> Follow this step only when you want to add translation for a new language. Running it for an existing language code will overwrite the existing translations. + To create a new language messages file, run the following, changing the 2 character language code at the end to the required language code. Only generate a individual language file once. -Note that this implementation includes an English translation. This is needed due to an issue with implementing pybabel -with aiohttp. - ``` pipenv run pybabel init -i rh_ui/translations/messages.pot -d rh_ui/translations -l cy ``` +3. Update translation files + Once created, you can update the existing language messages.po files to include changes in the messages.pot by running the following. This will update ALL language files. @@ -56,9 +60,12 @@ the following. This will update ALL language files. pipenv run pybabel update -i rh_ui/translations/messages.pot -d rh_ui/translations ``` +4. Compile the translations + +> [!NOTE] +> Double check your translation files (messages.po) for the `#, fuzzy` comment. This indicates that the tranlsation isn't an exact match and won't be rendered on the page. Double check the translations and remove any incorrectly matched lines, then remove the `fuzzy` comment. + To compile updates to the messages.po files into messages.mo (the file actually used by the site) use: -(If you've only changes made one small change and there's a `#, fuzzy` entry in the translation, -double-check the translation then remove the comment before compiling) ``` pipenv run pybabel compile -d rh_ui/translations ``` diff --git a/rh_ui/templates/base.html b/rh_ui/templates/base.html index 1d723a2..7354c61 100644 --- a/rh_ui/templates/base.html +++ b/rh_ui/templates/base.html @@ -9,11 +9,6 @@