Latest Version: 0.9.6.1

translation

Translation/Localization functions.

Provides gettext translation functions via an app's pylons.translator and get/set_lang for changing the language translated to.


Functions

f N_(value) ...

Mark a string for translation without translating it. Returns value.

Used for global strings, e.g.:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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'

f _(value) ...

Mark a string for translation. Returns the localized unicode string of value.

Mark a string to be localized as follows:

1
_('This should be in lots of languages')

f add_fallback(lang, **kwargs) ...

Add a fallback language from which words not matched in other languages will be translated to.

f get_lang() ...

Return the current i18n language used

f gettext(value) ...

Mark a string for translation. Returns the localized string of value.

Mark a string to be localized as follows:

1
gettext('This should be in lots of languages')

f gettext_noop(value) ...

Mark a string for translation without translating it. Returns value.

Used for global strings, e.g.:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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'

f lazy_gettext(*args, **kwargs) ...

Lazy-evaluated version of the gettext function

Mark a string for translation. Returns the localized string of value.

Mark a string to be localized as follows:

1
gettext('This should be in lots of languages')

f lazy_ngettext(*args, **kwargs) ...

Lazy-evaluated version of the ngettext function

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:

1
2
ngettext('There is %(num)d file here', 'There are %(num)d files here',
         n) % {'num': n}

f lazy_ugettext(*args, **kwargs) ...

Lazy-evaluated version of the ugettext function

Mark a string for translation. Returns the localized unicode string of

value.

Mark a string to be localized as follows:

1
_('This should be in lots of languages')

f lazy_ungettext(*args, **kwargs) ...

Lazy-evaluated version of the ungettext function

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:

1
2
ungettext('There is %(num)d file here', 'There are %(num)d files here',
          n) % {'num': n}

f ngettext(singular, plural, n) ...

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:

1
2
ngettext('There is %(num)d file here', 'There are %(num)d files here',
         n) % {'num': n}

f set_lang(lang, **kwargs) ...

Set the i18n language used

f ugettext(value) ...

Mark a string for translation. Returns the localized unicode string of value.

Mark a string to be localized as follows:

1
_('This should be in lots of languages')

f ungettext(singular, plural, 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:

1
2
ungettext('There is %(num)d file here', 'There are %(num)d files here',
          n) % {'num': n}

Classes

C LanguageError(...) ...

Exception raised when a problem occurs with changing languages

This class contains 2 members.

See the source for more information.

Top