API

dresende edited this page Mar 22, 2011 · 4 revisions
Clone this wiki locally

API

locale.setlocale(type, locale)

Change current locale to locale (ie. "en_US"). type should be one of locale.LC_ALL, locale.LC_MONETARY, etc..

locale.bindtextdomain(domain, path)

Set the base path for a text domain. This path should have a child folder with the name of the locale in use. This child folder should have another child folder called LC_MESSAGES with a pot file called domain.po.

locale.textdomain(domain)

Prepare to use a specific domain.

locale.gettext(msgid)

Translate msgid text using current current domain. This text should be a msgid in you message files. Otherwise it will return msgid unmodified.

locale.dgettext(domain, msgid)

This is the same as doing locale.textdomain(domain) and then locale.gettext(msgid).

locale.ngettext(msgid, msgid_plural, n)

Translate msgid or msgid_plural based on current locale and n value. It will use msgid_plural (which should be the plural form of msgid) or just msgid depending on n.

locale.dngettext(domain, msgid, msgid_plural, n)

This is the same as doing locale.textdomain(domain) and then locale.ngettext(msgid, msgid_plural, n).

locale.monetary.strfmon(format, value)

Return value formatted as a monetary value, based on current locale. format is a string that accepts everything that C function strfmon() accepts.

locale.time.strftime(format, value)

Return value formatted as a date value, based on current locale. format is a string that accepts everything that C function strftime() accepts. value should be a Date object or a numeric value representing Unix timestamp in miliseconds.

locale.time.strptime(string, format)

Returns an Object with the Date parameters that were extracted from the string, using the format. This format is the same as in the C function strptime().

locale.time.monthname(value[, abbreviated = false])

Returns a month name based on the value. This is a Date object or a numeric value representing Unix timestamp in miliseconds. If you use the second argument and set it to true, the month name returned will be the abbreviated form. Note that this is the same as calling locale.strftime("%b", value) or locale.strftime("%B", value) depending on the situation.

locale.time.weekdayname(value[, abbreviated = false])

Returns a weekday name based on the value. This is a Date object or a numeric value representing Unix timestamp in miliseconds. If you use the second argument and set it to true, the weekday name returned will be the abbreviated form. Note that this is the same as calling locale.strftime("%a", value) or locale.strftime("%A", value) depending on the situation.

locale.time.tzname()

Returns current timezone.

locale.time.timezone()

Returns current timezone difference from UTC.

locale.time.daylight()

Returns true if in daylight savings mode.

locale.ctype.isalpha(character)

Returns true character is an alpha character in current locale.

locale.ctype.isalnum(character)

Returns true character is an alphanumeric character in current locale.

locale.ctype.isdigit(character)

Returns true character is a digit (0-9) character in current locale.

locale.ctype.isxdigit(character)

Returns true character is an hex digit (0-9, a-f or A-F) character.

locale.ctype.isblank(character)

Returns true character is a blank (space or tab) character in current locale.

locale.ctype.isspace(character)

Returns true character is a space (space, \f, \n, \r, \t or \v) character.