Internationalization
UI text is translated between Chinese and English through Qt's translation system (QTranslator + .ts / .qm); the documentation itself is bilingual via the mkdocs i18n plugin using the docs/zh and docs/en folders.
Internationalization in code
- Marking strings: wrap all user-visible text with
QCoreApplication.translate(context, text).contextis usually the page class name, which keeps entries grouped in the.tsfile. - Translation sources:
i18n/zh_CN.tsandi18n/en_US.tsare XML translation sources, editable with Qt Linguist or updatable via scripts. - Compiling to
.qm: uselreleaseto compile.tsinto binary.qmfiles. At runtimecore.settings.apply_language()loads the matching.qmand callsinstallTranslator. - Chinese as the source language: when the language is
zh_CNthe translator is uninstalled and the Chinese strings in source code are shown directly.
Example
When adding a page, in the constructor:
python
btn.setText(QCoreApplication.translate("XinGongneng", "Compute"))
Then fill in the English translation in the corresponding <message> of i18n/en_US.ts.
Internationalization in docs
- Docs are split into two independent folders
docs/zh/(default) anddocs/en/with identical structure. mkdocs.ymluses thei18nplugin (docs_structure: folder) and builds a site per language based on thezh/ensubfolder name.- Chinese navigation labels are mapped to English through
nav_translations, so the navigation does not need to be duplicated underen/. - When adding a doc page, always create it in both
zh/anden/with the same filename and relative path.
Warning
After deleting or renaming a page under zh/, update en/ and the nav in mkdocs.yml as well, otherwise mkdocs build --strict will report broken links.