Package turbogears :: Package i18n :: Module format

Module format

source code

Localized formatting functions.

These functions extract localization data from config files located in the data/directory.

Functions
 
is_locale_format(locale)
Check if locale is supported.
source code
 
get_locale_module(locale)
Get i18n module supporting the locale.
source code
 
get(locale, name, default=None)
Get an attribute value for the locale.
source code
 
get_countries(locale=None)
Get all supported countries.
source code
 
get_country(key, locale=None)
Get localized name of country based on international country code.
source code
 
get_languages(locale=None)
Get all supported languages.
source code
 
get_language(key, locale=None)
Get localized name of language based on language code.
source code
 
get_month_names(locale=None)
Get list of full month names, starting with January.
source code
 
get_abbr_month_names(locale=None)
Get list of abbreviated month names, starting with Jan.
source code
 
get_weekday_names(locale=None)
Get list of full weekday names.
source code
 
get_abbr_weekday_names(locale=None)
Get list of abbreviated weekday names.
source code
 
get_decimal_format(locale=None)
Get decimal point for the locale.
source code
 
get_group_format(locale=None)
Get digit group separator for thousands for the locale.
source code
 
format_number(value, locale=None)
Get number formatted with grouping for thousands.
source code
 
format_decimal(value, num_places, locale=None)
Get number formatted with grouping for thousands and decimal places.
source code
 
format_currency(value, locale=None)
Get formatted currency value.
source code
 
parse_number(value, locale=None)
Take localized number string and return a long integer.
source code
 
parse_decimal(value, locale=None)
Take localized decimal string and return a float.
source code
 
get_date_format(format, locale=None)
Get localized date format.
source code
 
format_date(dt, format='medium', locale=None, time_format='', date_format='')
Get formatted date value.
source code
Function Details

get_countries(locale=None)

source code 

Get all supported countries.

Returns a list of tuples, consisting of international country code and localized name, e.g. ('AU', 'Australia').

get_languages(locale=None)

source code 

Get all supported languages.

Returns a list of tuples, with language code and localized name, e.g. ('en', 'English').

format_number(value, locale=None)

source code 

Get number formatted with grouping for thousands.

E.g. 5000000 will be formatted as 5,000,000.

format_decimal(value, num_places, locale=None)

source code 

Get number formatted with grouping for thousands and decimal places.

E.g. 5000000.898 will be formatted as 5,000,000.898.

parse_number(value, locale=None)

source code 

Take localized number string and return a long integer.

Throws ValueError if bad format.

parse_decimal(value, locale=None)

source code 

Take localized decimal string and return a float.

Throws ValueError if bad format.

format_date(dt, format='medium', locale=None, time_format='', date_format='')

source code 

Get formatted date value.

format can be "full", "long", "medium" or "short". To have complete control over formatting, use time_format and date_format parameters.

Parameters:
  • dt (datetime.datetime) - datetime
  • format (string) - format('full', 'long', 'medium', 'short')
  • locale (string) - the locale
  • time_format (s tring) - standard time formatting string, e.g. %H:%M
  • time_format (s tring) - date formatting template string. Template variables include standard date formatting string like %d or %Y plus a few locale-specific names: %%(abbrmonthname)s, %%(dayname)s, %%(abbrmonthname)s and %%(monthname)s.