This module defines API for i18n and L10n support.
cache of loaded translations (speedup)
Returns the locale to be used for current request as babel.Locale object. If used outside of a request, it return default locale as specified by settings.DEFAULT_LOCALE.
Returns the timezone to be used for current request as pytz.timezone object. If used outside of a request, it return default timezone as specified by settings.DEFAULT_TIMEZONE.
Returns gettext translations to be used for current locale.
Translates the given string with current locale and passes the given keyword variables as a mapping to format the string. The returned value is a lazy instance which will be translated when it is actually used.
Example:
h1 = gettext('Hello World!')
h2 = gettext('Hello %(name)s!', name='World')
@web.route('/say')
def say():
return h1
| Parameters: |
|
|---|---|
| Returns: | a lazy instance to delay actual translation, translation will be performed when result is actually used. |
Loads gettext translations for the given locale from the specified package represented by the given import name.
Translates the given string with current locale and passes the given keyword variables as a mapping to format the string.
It does a plural-forms lookup of a given string depending on the num and uses plural instead of string if num represents plural in the current locale.
The returned value is a lazy instance which will be translated when it is actually used.
Example:
ngettext('%(num)d Apple', '%(num)d Apples!', num=len(apples))
| Parameters: |
|
|---|---|
| Returns: | a lazy instance to delay actual translation, translation will be performed when result is actually used. |
Returns a date formated according to the given format in the context of current locale. If date is None, current date is assumed.
| Parameters: |
|
|---|---|
| Returns: | formated date as string |
Returns a datetime formated according to the given format in the context of current locale. If datetime is None, current time is assumed.
| Parameters: |
|
|---|---|
| Returns: | formated datetime as string |
Returns a formatted decimal value in the context of current locale. The appropriate thousands grouping and the decimal separator are used according to the current locale.
For example:
>>> format_decimal(12345.4321, digits=2)
... '12,345.43'
>>> format_decimal(Decimal('12345.4321'), digits=2)
... '12,345.43'
| Parameters: |
|
|---|
Returns a formatted decimal value in the context of current locale.
| Parameters: | number – an integer value |
|---|
Returns a time formated according to the given format in the context of current locale. If time is None, current time is assumed.
| Parameters: |
|
|---|---|
| Returns: | formated time as string |
Parse a date from a string.
Parse a datetime from a string.
Parse a localized decimal string into a float if force_decimal is False, else into a real decimal.Decimal value.
| Parameters: |
|
|---|
Parse a localized number string into a long integer.
Parse a time from a string.