pyra.locales#

Functions related to localization.

Localization (also referred to as l10n) is the process of adapting a product or service to a specific locale. Translation is only one of several elements in the localization process. In addition to translation, the localization process may also include: - Adapting design and layout to properly display translated text in the language of the locale - Adapting sorting functions to the alphabetical order of a specific locale - Changing formats for date and time, addresses, numbers, currencies, etc. for specific target locales - Adapting graphics to suit the expectations and tastes of a target locale - Modifying content to suit the tastes and consumption habits of a target locale

The aim of localization is to give a product or service the look and feel of having been created specifically for a target market, no matter their language, cultural preferences, or location.

pyra.locales.get_all_locales() dict[source]#

Get a dictionary of all possible locales for use with babel.

Dictionary keys will be locale_id and value with be locale_display_name. This is a shortened example of the returned value.

{
  'de': 'Deutsch',
  'en': 'English',
  'en_GB': 'English (United Kingdom)',
  'en_US': 'English (United States)',
  'es': 'español',
  'fr': 'français',
  'it': 'italiano',
  'ru': 'русский'
}
Returns:
dict

Dictionary of all possible locales.

Examples

>>> get_all_locales()
{... 'en': 'English', ... 'en_GB': 'English (United Kingdom)', ... 'es': 'español', ... 'fr': 'français', ...}
pyra.locales.get_locale() str[source]#

Verify the locale.

Verify the locale from the config against supported locales and returns appropriate locale.

Returns:
str

The locale set in the config if it is valid, otherwise the default locale (en).

Examples

>>> get_locale()
'en'
pyra.locales.get_text() gettext[source]#

Install the language defined in the conifg.

This function installs the language defined in the config and allows translations in python code.

Returns:
gettext.gettext

The gettext.gettext method.

Examples

>>> get_text()
<bound method GNUTranslations.gettext of <gettext.GNUTranslations object at 0x...>>