Package translate :: Package lang :: Module data
[hide private]
[frames] | no frames]

Module data

source code

This module stores information and functionality that relates to plurals.

Functions [hide private]
 
simplercode(code)
This attempts to simplify the given language code by ignoring country codes, for example.
source code
 
languagematch(languagecode, otherlanguagecode)
matches a languagecode to another, ignoring regions in the second
source code
 
tr_lang(langcode=None)
Gives a function that can translate a language name, even in the form "language (country)", into the language with iso code langcode, or the system language if no language is specified.
source code
 
_fix_language_name(name)
Identify and replace some unsightly names present in iso-codes.
source code
 
gettext_lang(langcode=None)
Returns a gettext function to translate language names into the given language, or the system language if no language is specified.
source code
 
gettext_country(langcode=None)
Returns a gettext function to translate country names into the given language, or the system language if no language is specified.
source code
 
normalize(string, normal_form='NFC')
Return a unicode string in its normalized form
source code
Unicode
forceunicode(string)
Ensures that the string is in unicode.
source code
 
normalized_unicode(string)
Forces the string to unicode and does normalization.
source code
 
normalize_code(code) source code
 
simplify_to_common(language_code, languages={'af': (u'Afrikaans', 2, '(n != 1)'), 'ak': (u'Akan', 2, 'n > ...)
Simplify language code to the most commonly used form for the language, stripping country information for languages that tend not to be localized differently for different countries
source code
Variables [hide private]
  languages = {'af': (u'Afrikaans', 2, '(n != 1)'), 'ak': (u'Aka...
Dictionary of language data.
  _fixed_names = {u'Asturian; Bable; Leonese; Asturleonese': u'A...
  expansion_factors = {'af': 0.1, 'ar': -0.09, 'es': 0.21, 'fr':...
Source to target string length expansion factors.
  iso639 = {}
ISO 639 language codes
  iso3166 = {}
ISO 3166 country codes
  langcode_re = re.compile(r'^[a-z]{2,3}([_-][A-Z]{2,3}|)(@[a-zA...
  variant_re = re.compile(r'^[_-][A-Z]{2,3}(@[a-zA-Z0-9]+|)$')
  dialect_name_re = re.compile(r'(.+)\s\(([^\)\d]+)\)$')

Imports: unicodedata, StringElem, gettext, locale, re, os


Function Details [hide private]

simplercode(code)

source code 

This attempts to simplify the given language code by ignoring country codes, for example.

_fix_language_name(name)

source code 

Identify and replace some unsightly names present in iso-codes.

If the name is present in _fixed_names we assume it is untranslated and we replace it with a more usable rendering.

normalize(string, normal_form='NFC')

source code 

Return a unicode string in its normalized form

Parameters:
  • string - The string to be normalized
  • normal_form - NFC (default), NFD, NFCK, NFDK
Returns:
Normalized string

forceunicode(string)

source code 

Ensures that the string is in unicode.

Parameters:
  • string (Unicode, String) - A text string
Returns: Unicode
String converted to Unicode and normalized as needed.

Variables Details [hide private]

languages

Dictionary of language data. The language code is the dictionary key (which may contain country codes and modifiers). The value is a tuple: (Full name in English from iso-codes, nplurals, plural equation).

Note that the English names should not be used in user facing places - it should always be passed through the function returned from tr_lang(), or at least passed through _fix_language_name().

Value:
{'af': (u'Afrikaans', 2, '(n != 1)'),
 'ak': (u'Akan', 2, 'n > 1'),
 'am': (u'Amharic', 2, 'n > 1'),
 'ar': (u'Arabic',
        6,
        'n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : \
n%100>=11 ? 4 : 5'),
 'arn': (u'Mapudungun; Mapuche', 2, 'n > 1'),
...

_fixed_names

Value:
{u'Asturian; Bable; Leonese; Asturleonese': u'Asturian',
 u'Bokmål, Norwegian; Norwegian Bokmål': u'Norwegian Bokmål',
 u'Catalan; Valencian': u'Catalan',
 u'Central Khmer': u'Khmer',
 u'Chichewa; Chewa; Nyanja': u'Chewa; Nyanja',
 u'Divehi; Dhivehi; Maldivian': u'Divehi',
 u'Dutch; Flemish': u'Dutch',
 u'Filipino; Pilipino': u'Filipino',
...

expansion_factors

Source to target string length expansion factors.

Value:
{'af': 0.1, 'ar': -0.09, 'es': 0.21, 'fr': 0.28, 'it': 0.2}

langcode_re

Value:
re.compile(r'^[a-z]{2,3}([_-][A-Z]{2,3}|)(@[a-zA-Z0-9]+|)$')