Translate the pages#
The pages are in English and German. People get the language of their browser; the names of the languages at the bottom of every page switch it, and the choice is kept in a cookie. The addresses stay the same in every language, so links and badges keep working.
What is translated#
The templates in
community_insights/templates/: texts are in{% translate %}and{% blocktranslate %}.Texts of Python code that people see, such as the messages after a form and the titles of the errors:
gettextandgettext_lazy.The texts the JavaScript in
static/js/writes into the page:_("..."), from Django’s JavaScript catalog at/jsi18n/. In node,_returns the English text, so the tests of the JavaScript need no catalog.
The details of the errors, the names of the variables of queries, the charts and the exported files are in English.
Change or add a text#
Install GNU gettext, for example
sudo apt install gettext.Mark the new text in the template, the Python code or the JavaScript as above.
Update the catalogs and compile them:
make messagesTranslate the new entries in
locale/de/LC_MESSAGES/django.poanddjangojs.po, for example with Poedit or a text editor. Remove thefuzzymark of entries you checked.Compile again and check the catalogs:
make test-translations
The tests in tests/i18n/ fail if a text has no translation, if a translation lost a placeholder such as %(name)s or an HTML tag, or if the compiled .mo files are older than the .po files. The CI runs make test-translations.
The German texts address people informally, with a capital letter as in a letter: Du, Dir, Dein.
Add a language#
Add the language to
LANGUAGESincommunity_insights/settings.py, such as("fr", "Français").Create its catalogs:
make messages LANGUAGES="de fr", and add it toLANGUAGES ?=in theMakefile.Translate
locale/fr/LC_MESSAGES/*.poand runmake test-translations.