Uranium
Application Framework
|
Wraps a gettext translation catalog for simplified use. More...
Public Member Functions | |
None | __init__ (self, str name=None, str language="default") |
Creates a new catalogue. | |
bool | hasTranslationLoaded (self) |
Whether the translated texts are loaded into this catalogue. | |
str | i18n (self, str text, *Any args) |
Mark a string as translateable. | |
str | i18nc (self, str context, str text, *Any args) |
Mark a string as translatable and provide a context for translators. | |
str | i18np (self, str single, str multiple, int counter, *Any args) |
Mark a string as translatable with plural forms. | |
str | i18ncp (self, str context, str single, str multiple, int counter, *Any args) |
Mark a string as translatable with plural forms and a context for translators. | |
None | setTagReplacements (cls, Dict[str, str] replacements) |
Change the global tags that are replaced in every internationalised string. | |
setApplication (cls, application) | |
Set the Application instance to request the language and application name from. | |
None | setApplicationName (cls, str applicationName) |
None | setLanguage (cls, str language) |
Protected Member Functions | |
str | _replaceTags (self, str string) |
Replace formatting tags in the string with globally-defined replacement values. | |
None | _update (self) |
Fill the catalogue by loading the translated texts from file (again). | |
Wraps a gettext translation catalog for simplified use.
This class wraps a gettext translation catalog to simplify its use. It will load the translation catalog from Resources' i18nLocation and allows specifying which language to load.
To use this class, create an instance of it with the name of the catalog to load. Then call i18n
or i18nc
on the instance to perform a look up in the catalog.
The translation system relies upon a set of standard contexts and HTML-like translation tags. Please see the translation guide for details.
None UM.i18n.i18nCatalog.__init__ | ( | self, | |
str | name = None , |
||
str | language = "default" |
||
) |
Creates a new catalogue.
name | The name of the catalog to load. |
language | The language to load. Valid values are language codes or "default". When "default" is specified, the language to load will be determined based on the system"s language settings. \note When <tt>language</tt> is <tt>default</tt>, the language to load can be overridden using the "LANGUAGE" environment variable. |
|
protected |
Replace formatting tags in the string with globally-defined replacement values.
Which tags are replaced can be defined using the setTagReplacements
method.
string | The text to replace tags in. |
bool UM.i18n.i18nCatalog.hasTranslationLoaded | ( | self | ) |
Whether the translated texts are loaded into this catalogue.
If there are translated texts, it is safe to request the text with the gettext
method and so on.
True
if texts are loaded into this catalogue, or False
if they aren't. str UM.i18n.i18nCatalog.i18n | ( | self, | |
str | text, | ||
*Any | args | ||
) |
Mark a string as translateable.
text | The string to mark as translatable |
args | Formatting arguments. These will replace formatting elements in the translated string. See python str.format() . |
str UM.i18n.i18nCatalog.i18nc | ( | self, | |
str | context, | ||
str | text, | ||
*Any | args | ||
) |
Mark a string as translatable and provide a context for translators.
context | The context of the string, i.e. something that explains the use of the text. |
text | The text to mark translatable. |
args | Formatting arguments. These will replace formatting elements in the translated string. See python str.format() . |
str UM.i18n.i18nCatalog.i18ncp | ( | self, | |
str | context, | ||
str | single, | ||
str | multiple, | ||
int | counter, | ||
*Any | args | ||
) |
Mark a string as translatable with plural forms and a context for translators.
context | The context of this string. |
single | The singular form of the string. |
multiple | The plural form of the string. |
counter | The value that determines whether the singular or plural form should be used. |
args | Formatting arguments. These will replace formatting elements in the translated string. See python str.format() . |
str UM.i18n.i18nCatalog.i18np | ( | self, | |
str | single, | ||
str | multiple, | ||
int | counter, | ||
*Any | args | ||
) |
Mark a string as translatable with plural forms.
single | The singular form of the string. |
multiple | The plural form of the string. |
counter | The value that determines whether the singular or plural form should be used. |
args | Formatting arguments. These will replace formatting elements in the translated string. See python str.format() . |
UM.i18n.i18nCatalog.setApplication | ( | cls, | |
application | |||
) |
Set the Application
instance to request the language and application name from.
application | The Application instance of the application that is running. |
None UM.i18n.i18nCatalog.setTagReplacements | ( | cls, | |
Dict[str, str] | replacements | ||
) |
Change the global tags that are replaced in every internationalised string.
If a text contains something of the form <key>
or </key>
, then the word key
will get replaced by whatever is in this dictionary at the specified key.
replacements | A dictionary of strings to strings, indicating which words between tags should get replaced. |