Z-Sans ships with built-in support for English and Chinese (zh_CN / en), implemented on top of standard gettext (.po / .mo).

Directory Structure

i18n/
├── en/LC_MESSAGES/
│   ├── messages.po    # Source strings
│   └── messages.mo    # Compiled binary
└── zh_CN/LC_MESSAGES/
    ├── messages.po
    └── messages.mo

Configuration

language:
  default_language: en      # zh_CN or en
  supported_languages:
    - zh_CN
    - en
  locale_dir: i18n          # Language files directory

How It Works

  1. main() first parses -c/--config with a pre-parser to obtain the config file path
  2. setup_i18n(config) loads the language:
  3. Reads the default language and supported list from the language section of the config
  4. Default language not in the supported list → warning and fallback to zh_CN
  5. locale_dir is resolved relative to the project root; directory does not exist → error and fallback to i18n
  6. gettext.translation('messages', ...) loads the language pack and calls install()
  7. Falls back to English on failure
  8. argparse._ = _: injects the translation function into argparse so built-in texts like -h/--help go through the same translation
  9. Logs and prompts are all wrapped with _()

Developer Usage

Use it in code:

from core.i18n import _

logger.info(_("Breeding engine started"))
engine.start(_("Scanning..."))

After adding new strings, update the .po file and recompile it to .mo (tools such as Babel / msgfmt).

Querying the Current Language

from core.i18n import get_current_language
lang = get_current_language()   # 'zh_CN' | 'en'

The HTML report and the Web console UI language also follow this config:

  • HTML report: zh prefix → lang="zh-CN"
  • Web console: GET /api/i18n returns {lang, dict} (80+ frontend text keys), the frontend looks them up via t(key)