Skip to content

Translations

Kyle Gabriel edited this page Sep 11, 2022 · 8 revisions

Easy Method

Weblate has been set up as the primary way for contributing to Mycodo translations, at http://translate.kylegabriel.com:8080/engage/mycodo/. Please read How To Contribute to Language Translations in Mycodo for information about how to use Weblate. Any questions or issues can be discussed on the Mycodo Forum.

Manual Method

Adding and editing translation files can also be done manually. The below information is not the recommended method to contribute to translations anymore and is here merely for reference.

Each language translation is contained in a messages.po file, and this file is all that's required for Mycodo to translate texts.

Creating a New Translation

cd ~/Mycodo/mycodo

Create a messages.pot file from searching all files that contain translatable text.

../env/bin/pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot .

Create the translation for the new language (in this case it is 'es' for Spanish).

../env/bin/pybabel init -i messages.pot -d mycodo_flask/translations -l es

There will now be the file 'messages.po' created in ~/Mycodo/mycodo/mycodo_flask/translations/es/LC_MESSAGES/messages.po. Edit this file (I used poedit) by entering the translation to each English word or phrase, then save.

If this is a new language, add the appropriate name and language code to Mycodo/mycodo/config.py in the LANGUAGES dictionary:

LANGUAGES = {
    'en': 'English',
    'fr': 'Français (French)',
    'es': 'Español (Spanish)',
    'ko': '한국어 (Korean)'
}

Then, compile the new translation.

../env/bin/pybabel compile -d mycodo_flask/translations

Finally, restart the web interface to test the display in Mycodo.

sudo service mycodoflask restart

Automatically translating PO files

The Google translation toolkit was a great resource for importing and automatically translating PO translation files. However, this service was shut down at the end of 2019. An alternative that I've used with success is naskio/po-auto-translation.

Update a Preexisting Translation

If you would like to rescan for new translatable texts and update a preexisting messages.po file without losing previous translation work, use the following commands instead of the above commands. Then edit with poedit (or similar app) and compile for it to take effect.

cd ~/Mycodo/mycodo
../env/bin/pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot .
../env/bin/pybabel update --ignore-obsolete -i messages.pot -d mycodo_flask/translations
../env/bin/pybabel compile -d mycodo_flask/translations

Reading

Refer to The Flask Mega-Tutorial, Part XIV: I18n and L10n for more details of this process.