Translation/Localization functions.
Provides gettext translation functions via an app’s pylons.translator and get/set_lang for changing the language translated to.
Exception raised when a problem occurs with changing languages
Has a number of lazily evaluated functions replicating a string. Just override the eval() method to produce the actual value.
This method copied from TurboGears.
Decorator to return a lazy-evaluated version of the original
Mark a string for translation without translating it. Returns value.
Used for global strings, e.g.:
foo = N_('Hello')
class Bar:
def __init__(self):
self.local_foo = _(foo)
h.set_lang('fr')
assert Bar().local_foo == 'Bonjour'
h.set_lang('es')
assert Bar().local_foo == 'Hola'
assert foo == 'Hello'
Mark a string for translation. Returns the localized string of value.
Mark a string to be localized as follows:
gettext('This should be in lots of languages')
Mark a string for translation. Returns the localized unicode string of value.
Mark a string to be localized as follows:
_('This should be in lots of languages')
Mark a string for translation. Returns the localized string of the pluralized value.
This does a plural-forms lookup of a message id. singular is used as the message id for purposes of lookup in the catalog, while n is used to determine which plural form to use. The returned message is a string.
Mark a string to be localized as follows:
ngettext('There is %(num)d file here', 'There are %(num)d files here',
n) % {'num': n}
Mark a string for translation. Returns the localized unicode string of the pluralized value.
This does a plural-forms lookup of a message id. singular is used as the message id for purposes of lookup in the catalog, while n is used to determine which plural form to use. The returned message is a Unicode string.
Mark a string to be localized as follows:
ungettext('There is %(num)d file here', 'There are %(num)d files here',
n) % {'num': n}
Set the current language used for translations.
lang should be a string or a list of strings. If a list of strings, the first language is set as the main and the subsequent languages are added as fallbacks.
Return the current i18n language used
Add a fallback language from which words not matched in other languages will be translated to.
This fallback will be associated with the currently selected language – that is, resetting the language via set_lang() resets the current fallbacks.
This function can be called multiple times to add multiple fallbacks.