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
enandde, adding an underscore to define sub-languages likeen_gbanden_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
domainargument may specify a domain to use when checking for files. By default, all domains are checked.This internally uses the
globbuilt-in module and thei18n.lang.formatconfig option to find suitable filenames. It then applies the regex ini18n.discover_regexto 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
langparameter 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
setlangaction 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.langconfig value.
-