sol.i18n – Internationalization utilities

sol.i18n.DOMAIN = 'sol-server'

The translation domain of the server side

sol.i18n.gettext(s, **kw)

Immediately translate the given string with current request locale

Parameters:
  • s – either a string or a TranslationString instance
  • just_subst – by default False, True to disable the actual translation and perform only mapping substitution
sol.i18n.ngettext(s, p, n, **kw)

Immediately translate the singular or plural form with current request locale

Parameters:
  • s – either a string or a TranslationString instance with the singular form
  • p – either a string or a TranslationString instance with the plural form
  • n – an integer
sol.i18n.setAcceptedLanguagesLocale(event, _available_languages=[])

Recognize the user preferred language.

Parameters:
  • event – a Pyramid event
  • _available_languages – the list of available languages (this is used as a cache, computed at the first call to this function)

This function is automatically executed at each new request, and sets the _LOCALE_ attribute of the request itself.

sol.i18n.translatable_string(msgid, mapping=None, default=None)

A function to make a translatable string.

sol.i18n.translator(request)

Return a function that translates a given string in the specified request

Parameters:request – either None or a Pyramid request instance

This is an helper function that handle the case when the request does not exist, for example while testing:

>>> t = translator(None)
>>> t('$first $last', mapping=dict(first='Foo', last='Bar'))
'Foo Bar'

Previous topic

SoL modules

Next topic

sol.models – SQLAlchemy modelization

This Page