Reference: Languages

This module contains the languages for the Translations app.

Important

The examples are assumed to be executed using these settings.

LANGUAGE_CODE = 'en-us'
LANGUAGES = (
    ('en', 'English'),
    ('en-gb', 'English (Great Britain)'),
    ('de', 'German'),
    ('tr', 'Turkish'),
)

Please keep these settings in mind in order to understand the examples better.

translations.languages._get_supported_language(lang)[source]

Return the supported language code of a custom language code.

Searches the LANGUAGES in the settings for the custom language code, if the exact custom language code is found, it returns it, otherwise searches for the unaccented form of the custom language code, if the unaccented form of the custom language code is found, it returns it, otherwise it throws an error stating there is no such language supported in the settings.

Parameters

lang (str) – The custom language code to get the supported language code of.

Returns

The supported language code of the custom language code.

Return type

str

Raises

ValueError – If the language code is not specified in the LANGUAGES setting.

To get the supported language code of a custom language code (an unaccented language code):

from translations.languages import _get_supported_language

# get the supported language
custom = _get_supported_language('en')

print(custom)
en

To get the supported language code of a custom language code (an existing accented language code):

from translations.languages import _get_supported_language

# get the supported language
custom = _get_supported_language('en-gb')

print(custom)
en-gb

To get the supported language code of a custom language code (a non-existing accented language code):

from translations.languages import _get_supported_language

# get the supported language
custom = _get_supported_language('en-us')

print(custom)
en
translations.languages._get_default_language()[source]

Return the supported language code of the default language code.

Returns

The supported language code of the default language code.

Return type

str

Raises

ValueError – If the default language code is not supported.

To get the supported language code of the default language code:

from translations.languages import _get_default_language

# get the default language
default = _get_default_language()

print(default)
en
translations.languages._get_active_language()[source]

Return the supported language code of the active language code.

Returns

The supported language code of the active language code.

Return type

str

Raises

ValueError – If the active language code is not supported.

To get the supported language code of the active language code (assume en):

from translations.languages import _get_active_language

# get the active language
active = _get_active_language()

print(active)
en
translations.languages._get_all_languages()[source]

Return all the supported language codes.

Returns

All the supported language codes.

Return type

list(str)

To get all the supported language codes:

from translations.languages import _get_all_languages

# get all the languages
languages = _get_all_languages()

print(languages)
[
    'en',
    'en-gb',
    'de',
    'tr',
]
translations.languages._get_all_choices()[source]

Return all the supported language choices.

Returns

All the supported language choices.

Return type

list(tuple(str, str))

To get all the supported language choices:

from translations.languages import _get_all_choices

# get all the language choices
choices = _get_all_choices()

print(choices)
[
    (None, '---------'),
    ('en', 'English'),
    ('en-gb', 'English (Great Britain)'),
    ('de', 'German'),
    ('tr', 'Turkish'),
]
translations.languages._get_translation_languages()[source]

Return the translation language codes.

Returns

The translation language codes.

Return type

list(str)

To get the translation language codes:

from translations.languages import _get_translation_languages

# get the translation languages
languages = _get_translation_languages()

print(languages)
[
    'en-gb',
    'de',
    'tr',
]
translations.languages._get_translation_choices()[source]

Return the translation language choices.

Returns

The translation language choices.

Return type

list(tuple(str, str))

Raises

ValueError – If the default language code is not supported.

To get the translation language choices:

from translations.languages import _get_translation_choices

# get the translation language choices
choices = _get_translation_choices()

print(choices)
[
    (None, '---------'),
    ('en-gb', 'English (Great Britain)'),
    ('de', 'German'),
    ('tr', 'Turkish'),
]
translations.languages._get_translate_language(lang=None)[source]

Return the supported language code of a translate language code.

If the translate language code is passed in, it returns the supported language code of it, otherwise it returns the supported language code of the active language code.

Parameters

lang (str or None) – The translate language code to get the supported language code of. None means use the active language code.

Returns

The supported language code of the translate language code.

Return type

str

Raises

ValueError – If the translate language code is not supported.

To get the supported language code of a translate language code (the active language code - assume en):

from translations.languages import _get_translate_language

# get the translate language
translate = _get_translate_language()

print(translate)
en

To get the supported language code of a translate language code (a custom language code):

from translations.languages import _get_translate_language

# get the translate language
translate = _get_translate_language('en-us')

print(translate)
en
translations.languages._get_probe_language(lang=None)[source]

Return the supported language code(s) of some probe language code(s).

If the probe language code(s) is (are) passed in, it returns the supported language code(s) of it (them), otherwise it returns the supported language code of the active language code.

Parameters

lang (str or list or None) – The probe language code(s) to get the supported language code(s) of. None means use the active language code.

Returns

The supported language code(s) of the probe language code(s).

Return type

str

Raises

ValueError – If the probe language code(s) is (are) not supported.

To get the supported language code(s) of some probe language code(s) (the active language code - assume en):

from translations.languages import _get_probe_language

# get the probe language
probe = _get_probe_language()

print(probe)
en

To get the supported language code(s) of some probe language code(s) (a custom language code):

from translations.languages import _get_probe_language

# get the probe language
probe = _get_probe_language('en-us')

print(probe)
en

To get the supported language code(s) of some probe language code(s) (multiple custom language codes):

from translations.languages import _get_probe_language

# get the probe language
probe = _get_probe_language(['en-us', 'en-gb'])

print(probe)
[
    'en',
    'en-gb',
]
class translations.languages._TRANSLATE[source]

A class which provides standard translate language codes.

DEFAULT

Return the default language code.

To get the default language code.

from translations.languages import translate

# get the default language
default = translate.DEFAULT

print(default)
en
ACTIVE

Return the active language code.

To get the active language code. (assume en)

from translations.languages import translate

# get the active language
active = translate.ACTIVE

print(active)
en
class translations.languages._PROBE[source]

A class which provides standard probe language codes.

DEFAULT

Return the default language code.

To get the default language code.

from translations.languages import probe

# get the default language
default = probe.DEFAULT

print(default)
en
ACTIVE

Return the active language code.

To get the active language code. (assume en)

from translations.languages import probe

# get the active language
active = probe.ACTIVE

print(active)
en
DEFAULT_ACTIVE

Return the default language and active language codes.

To get the default language and active language codes. (assume en)

from translations.languages import probe

# get the default and active language
defact = probe.DEFAULT_ACTIVE

print(defact)
en

To get the default language and active language codes. (assume de)

from translations.languages import probe

# get the default and active language
defact = probe.DEFAULT_ACTIVE

print(defact)
[
    'en',
    'de',
]
TRANSLATION

Return the translation language codes.

To get the translation language codes.

from translations.languages import probe

# get the translation language
translation = probe.TRANSLATION

print(translation)
[
    'en-gb',
    'de',
    'tr',
]
ALL

Return all the supported language codes.

To get all the supported language codes.

from translations.languages import probe

# get all the language
all = probe.ALL

print(all)
[
    'en',
    'en-gb',
    'de',
    'tr',
]
translations.languages.translate

An object which provides standard translate language codes.

An instance of _TRANSLATE

translations.languages.probe

An object which provides standard probe language codes.

An instance of _PROBE