Skip to content

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). context is usually the page class name, which keeps entries grouped in the .ts file.
  • Translation sources: i18n/zh_CN.ts and i18n/en_US.ts are XML translation sources, editable with Qt Linguist or updatable via scripts.
  • Compiling to .qm: use lrelease to compile .ts into binary .qm files. At runtime core.settings.apply_language() loads the matching .qm and calls installTranslator.
  • Chinese as the source language: when the language is zh_CN the 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) and docs/en/ with identical structure.
  • mkdocs.yml uses the i18n plugin (docs_structure: folder) and builds a site per language based on the zh / en subfolder name.
  • Chinese navigation labels are mapped to English through nav_translations, so the navigation does not need to be duplicated under en/.
  • When adding a doc page, always create it in both zh/ and en/ 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.