Classes | Functions | Variables
tornado::locale Namespace Reference

Classes

class  CSVLocale
class  GettextLocale
class  Locale

Functions

def get
def get_supported_locales
def load_gettext_translations
def load_translations
def set_default_locale

Variables

string _default_locale = "en_US"
tuple _supported_locales = frozenset([_default_locale])
dictionary _translations = {}
 _use_gettext = False
dictionary LOCALE_NAMES

Function Documentation

def tornado.locale.get (   locale_codes)
Returns the closest match for the given locale codes.

We iterate over all given locale codes in order. If we have a tight
or a loose match for the code (e.g., "en" for "en_US"), we return
the locale. Otherwise we move to the next code in the list.

By default we return ``en_US`` if no translations are found for any of
the specified locales. You can change the default locale with
`set_default_locale()`.

Definition at line 60 of file locale.py.

Returns a list of all the supported locale codes.

Definition at line 197 of file locale.py.

def tornado.locale.load_gettext_translations (   directory,
  domain 
)
Loads translations from `gettext`'s locale tree

Locale tree is similar to system's ``/usr/share/locale``, like::

    {directory}/{lang}/LC_MESSAGES/{domain}.mo

Three steps are required to have you app translated:

1. Generate POT translation file::

    xgettext --language=Python --keyword=_:1,2 -d mydomain file1.py file2.html etc

2. Merge against existing POT file::

    msgmerge old.po mydomain.po > new.po

3. Compile::

    msgfmt mydomain.po -o {directory}/pt_BR/LC_MESSAGES/mydomain.mo

Definition at line 154 of file locale.py.

def tornado.locale.load_translations (   directory)
Loads translations from CSV files in a directory.

Translations are strings with optional Python-style named placeholders
(e.g., ``My name is %(name)s``) and their associated translations.

The directory should have translation files of the form ``LOCALE.csv``,
e.g. ``es_GT.csv``. The CSV files should have two or three columns: string,
translation, and an optional plural indicator. Plural indicators should
be one of "plural" or "singular". A given string can have both singular
and plural forms. For example ``%(name)s liked this`` may have a
different verb conjugation depending on whether %(name)s is one
name or a list of names. There should be two rows in the CSV file for
that string, one with plural indicator "singular", and one "plural".
For strings with no verbs that would change on translation, simply
use "unknown" or the empty string (or don't include the column at all).

The file is read using the `csv` module in the default "excel" dialect.
In this format there should not be spaces after the commas.

Example translation ``es_LA.csv``::

    "I love you","Te amo"
    "%(name)s liked this","A %(name)s les gustó esto","plural"
    "%(name)s liked this","A %(name)s le gustó esto","singular"

Definition at line 88 of file locale.py.

Sets the default locale.

The default locale is assumed to be the language used for all strings
in the system. The translations loaded from disk are mappings from
the default locale to the destination locale. Consequently, you don't
need to create a translation file for the default locale.

Definition at line 74 of file locale.py.


Variable Documentation

Definition at line 54 of file locale.py.

Definition at line 56 of file locale.py.

Definition at line 55 of file locale.py.

Definition at line 57 of file locale.py.

Definition at line 448 of file locale.py.



rosbridge_server
Author(s): Jonathan Mace
autogenerated on Thu Jun 6 2019 21:51:51