peng3d.i18n
- Lightweight Translation Manager¶
-
class
peng3d.i18n.
TranslationManager
(peng)[source]¶ Manages sets of translation files in multiple languages.
This Translation System uses language codes to identify languages, there is no requirement to follow a specific standard, but it is recommended to use simple 2-digit codes like
en
andde
, adding an underscore to define sub-languages likeen_gb
anden_us
.Whenever a new translation file is needed, it will be parsed and then cached. This speeds up access times and also practically eliminates load times when switching languages.
Several events are sent by this class, see peng3d:i18n.* Events Category.
Most of these events are also sent as actions, these actions are described in the methods that cause them.
There are also severale config options that determine the behaviour of this class. See Translation Options for more information.
This Manager requires the
ResourceManager()
to be already initialized.-
discoverLangs
(domain='*')[source]¶ Generates a list of languages based on files found on disk.
The optional
domain
argument may specify a domain to use when checking for files. By default, all domains are checked.This internally uses the
glob
built-in module and thei18n.lang.format
config option to find suitable filenames. It then applies the regex ini18n.discover_regex
to extract the language code.
-
setLang
(lang)[source]¶ Sets the default language for all domains.
For recommendations regarding the format of the language code, see
TranslationManager
.Note that the
lang
parameter of bothtranslate()
andtranslate_lazy()
will override this setting.Also note that the code won’t be checked for existence or plausibility. This may cause the fallback strings to be displayed instead if the language does not exist.
Calling this method will cause the
setlang
action and the :peng3d:event`peng3d:i18n.set_lang` event to be triggered. Note that both action and event will be triggered even if the language did not actually change.This method also automatically updates the
i18n.lang
config value.
-