Repository navigation
API turboframe.i18n
Source: turboframe/i18n.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.
The languages of TurboFrame's own texts: gettext catalogues of the turboframe domain.
TurboFrame's texts are written in English and marked _("..."); locale/<lang>/LC_MESSAGES/turboframe.mo holds each translation. An application keeps its own domain for its own texts, and calls use() with the language it chose, so both speak the same one. Until it does, TurboFrame speaks English, so an English-only application never shows a translated framework text. A language without a catalogue is English.
An application's own texts are a Domain (its name and its locale folder): Domain.use() switches both, so the application and TurboFrame always speak the same language. choose_language picks it the way divide does: an environment variable, then --language on the command line, then the stored setting, then the system's.
turboframe.i18n_tools extracts, updates and compiles a domain's catalogues (with Babel, a development tool); turboframe.testing.i18n checks them in an application's tests.
DOMAIN, LOCALE_DIR, SOURCE, available, current, system_language, use, _, N_, ngettext, Domain, argv_language, choose_language
'turboframe'
<the turboframe package>/locale (a Path)
'en'
def available() -> list[str]English and the languages with a compiled catalogue.
'en'
def system_language() -> strdef use(language: str) -> strTranslate into language from now on (English when there is no catalogue). Returns it.
def _(text: str) -> strtext in the interface's language.
def N_(text: str) -> strMark text for translation without translating it now: a text made at import, before the application chose its language, is translated with _() where it is shown.
def ngettext(singular: str, plural: str, n: int) -> strclass Domain
Domain(name: str, locale_dir: Path, source: str = 'en')An application's own texts: the gettext domain name in locale_dir (<locale_dir>/<lang>/LC_MESSAGES/<name>.mo).
use() switches the application's texts and TurboFrame's to the same language. The application
exposes the domain's _, N_ and ngettext:
_domain = Domain("myapp", Path(__file__).parent / "locale")
_, N_, ngettext = _domain.gettext, N_, _domain.ngettext
_domain.use(choose_language(env="MYAPP_LANGUAGE", program="myapp", setting=config.load().get("language")))-
available() -> list[str]: The source language and those with a compiled catalogue. -
use(language: str) -> str: Translate intolanguagefrom now on (the source language when there is no catalogue), the application's texts and TurboFrame's. Returns the language in use. -
gettext(text: str) -> str:textin the interface's language. ngettext(singular: str, plural: str, n: int) -> str
def argv_language(program: str, argv: list[str] | None = None) -> str | None--language X (or --language=X) given to program's command. An application's texts may be made when its modules are imported, before its main parses the arguments, so the language is read here first; None when the command is not program's or has no such option.
def choose_language(*, env: str | None = None, program: str | None = None, setting: str | None = None, argv: list[str] | None = None) -> strThe language to use, the first one of: the environment variable env (the tests and the screenshots set it), --language given to program (argv_language), the stored setting (an Options > Language), the system's. "auto" (or nothing) passes to the next one.
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links