Translation helper functions.
Class |
|
Set up the GNUTranslations context with regard to output charset. |
Class |
|
Simulate a dict for DjangoTranslation._catalog so as multiple catalogs with different plural equations are kept separate. |
Function | activate |
Fetch the translation object for a given language and install it as the current translation object for the current thread. |
Function | all |
Return a list of paths to user-provides languages files. |
Function | catalog |
Return the current active catalog for further processing. This can be used if you need to modify the catalog or want to access the whole message catalog instead of just translating one string. |
Function | check |
Check whether there is a global language file for the given language code. This is used to decide whether a user-provided language is available. |
Function | deactivate |
Uninstall the active translation object so that further _() calls resolve to the default translation object. |
Function | deactivate |
Make the active translation object a NullTranslations() instance. This is useful when we want delayed translations to appear as the original string for some reason. |
Function | do |
Undocumented |
Function | get |
Return the currently selected language. |
Function | get |
Return selected language's BiDi layout. |
Function | get |
Return the language code if there's a valid language code found in `path`. |
Function | get |
Analyze the request to find what language the user wants the system to show. Only languages listed in settings.LANGUAGES are taken into account. If the user requests a sublanguage where we have a main language, we send out the main language. |
Function | get |
Cache of settings.LANGUAGES in a dictionary for easy lookups by key. Convert keys to lowercase as they should be treated as case-insensitive. |
Function | get |
Return the language code that's listed in supported languages, possibly selecting a more generic variant. Raise LookupError if nothing is found. |
Function | gettext |
Translate the 'message' string. It uses the current thread to find the translation object to use. If no current translation is activated, the message will be run through the default translation object. |
Function | gettext |
Mark strings for translation but don't translate them now. This can be used to store strings in global variables that should stay in the base language (because they might be used externally) and will be translated later. |
Function | ngettext |
Return a string of the translation of either the singular or plural, based on the number. |
Function | npgettext |
Undocumented |
Function | parse |
Parse the value of the Accept-Language header up to a maximum length. |
Function | pgettext |
Undocumented |
Function | reset |
Reset global state when LANGUAGES setting has been changed, as some languages should no longer be accepted. |
Function | translation |
Return a translation object in the default 'django' domain. |
Constant | ACCEPT |
Undocumented |
Constant | CONTEXT |
Undocumented |
Variable | accept |
Undocumented |
Variable | language |
Undocumented |
Variable | language |
Undocumented |
Function | _parse |
Parse the lang_string, which is the body of an HTTP Accept-Language header, and return a tuple of (lang, q-value), ordered by 'q' values. |
Variable | _active |
Undocumented |
Variable | _default |
Undocumented |
Variable | _translations |
Undocumented |
Fetch the translation object for a given language and install it as the current translation object for the current thread.
Return the current active catalog for further processing. This can be used if you need to modify the catalog or want to access the whole message catalog instead of just translating one string.
Check whether there is a global language file for the given language code. This is used to decide whether a user-provided language is available. lru_cache should have a maxsize to prevent from memory exhaustion attacks, as the provided language codes are taken from the HTTP request. See also <https://www.djangoproject.com/weblog/2007/oct/26/security-fix/>.
Uninstall the active translation object so that further _() calls resolve to the default translation object.
Make the active translation object a NullTranslations() instance. This is useful when we want delayed translations to appear as the original string for some reason.
Return selected language's BiDi layout. * False = left-to-right layout * True = right-to-left layout
Return the language code if there's a valid language code found in `path`. If `strict` is False (the default), look for a country-specific variant when neither the language code nor its generic variant is found.
Analyze the request to find what language the user wants the system to show. Only languages listed in settings.LANGUAGES are taken into account. If the user requests a sublanguage where we have a main language, we send out the main language. If check_path is True, the URL path prefix will be checked for a language code, otherwise this is skipped for backwards compatibility.
Cache of settings.LANGUAGES in a dictionary for easy lookups by key. Convert keys to lowercase as they should be treated as case-insensitive.
def get_supported_language_variant(lang_code, strict=False): (source) ¶
Return the language code that's listed in supported languages, possibly selecting a more generic variant. Raise LookupError if nothing is found. If `strict` is False (the default), look for a country-specific variant when neither the language code nor its generic variant is found. lru_cache should have a maxsize to prevent from memory exhaustion attacks, as the provided language codes are taken from the HTTP request. See also <https://www.djangoproject.com/weblog/2007/oct/26/security-fix/>.
Translate the 'message' string. It uses the current thread to find the translation object to use. If no current translation is activated, the message will be run through the default translation object.
Mark strings for translation but don't translate them now. This can be used to store strings in global variables that should stay in the base language (because they might be used externally) and will be translated later.
Parse the value of the Accept-Language header up to a maximum length. The value of the header is truncated to a maximum length to avoid potential denial of service and memory exhaustion attacks. Excessive memory could be used if the raw value is very large as it would be cached due to the use of functools.lru_cache() to avoid repetitive parsing of common header values.
Reset global state when LANGUAGES setting has been changed, as some languages should no longer be accepted.