Translation/Localization functions.
Provides gettext translation functions via an app’s pylons.translator and get/set_lang for changing the language translated to.
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.
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}