Multi language support - moevm/mse_visual_map_editor_for_duckietown GitHub Wiki
Multi-language support
App has multi-language support available with QtTranslator for Python.
Supported languages:
- English
- Russian
Switching languages
The required language is specified using an argument when starting the application (default: English language)
python3 main.py ru
-
UI translation: Directory
resources/lang/qmshould contain the file of the corresponding translation. (Filename format:lang_<language_code>.qm, <language_code>:en,it,fr,ru)- If qm-file does not exist, app use default language (English).
-
Element info translation: File doc/info.json must contain the required language in the
lang-field forcategoriesandinfo- If
lang-field does not contains selected language, app use default language (English - it should always be, otherwise how did you add this element?).
- If
UI translation
In app we use something similar to the code below:
_translate = QtCore.QCoreApplication.translate
translated_string = _translate("MainWindow", "Map characteristics")
QtCore.QCoreApplication.translate - QTranslator.translate
This allows to translate specific strings with the installed QtTranslator.
Such strings must be translated into the desired language in advance.
Adding new language for UI
For getting the strings, that must be translated, we use the pylupdate5 tool
# Example
pylupdate5 main.py -ts lang_en.ts
It creates *.ts-file, which contains strings in xml-format. For example, resources/lang/ts/lang_en.ts
- Place the translation in the appropriate tag, remove attr
type
<translation type="unfinished"></translation>
- Create *.qm file from *.ts by
lreleasetool
lrelease lang_it.ts
- Move created *.qm file to
resources/lang/qmdirectory
Example resources/lang/ts/lang_ru.ts
File resources/lang/ts/lang_en.ts contains all the currently required strings, use it to translate into other languages.
Warning: application is not finished and will be improved, which means that new strings may be added
Element's info translation
For storing translations in doc/info.json, we use the following format for elements in categories and info:
"lang": {
"ru": {
"name": "Блоки дороги"
},
"en": {
"name": "Road tiles"
}
}
----------
"lang": {
"ru": {
"name": "Осторожно, уточки",
"info": "Специальный знак. Обозначает место перехода уточками дорогу."
},
"en": {
"name": "Duck crossing",
"info": "Special sign. Indicates the place where ducks cross the road."
}
}
Adding new language for element's info
Add translation to desired language in lang-field in file doc/info.json for categories and info.
If you don't want to translate something - it's okay. Application will use English by default if there is no translation.