diff options
| author | Sebastian Sangervasi <s.ebastian.sangervasi@gmail.com> | 2017-06-27 16:50:26 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-02-23 14:49:00 -0500 |
| commit | 7905815510fb1eae99010ccc0039249d981a121c (patch) | |
| tree | ea3dbc6433091d66e87f5007ad3ab61f687ec895 /docs | |
| parent | 5033999153f7303a18d94ea2f08ed78545c0f3df (diff) | |
Fixed #27449 -- Added django.utils.translation.get_supported_language_variant().
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/utils.txt | 17 | ||||
| -rw-r--r-- | docs/releases/2.1.txt | 3 |
2 files changed, 19 insertions, 1 deletions
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt index d6127e3fed..581156b5d8 100644 --- a/docs/ref/utils.txt +++ b/docs/ref/utils.txt @@ -1092,6 +1092,23 @@ functions without the ``u``. for whether its path begins with a language code listed in the :setting:`LANGUAGES` setting. +.. function:: get_supported_language_variant(lang_code, strict=False) + + .. versionadded:: 2.1 + + Returns ``lang_code`` if it's in the :setting:`LANGUAGES` setting, possibly + selecting a more generic variant. For example, ``'es'`` is returned if + ``lang_code`` is ``'es-ar'`` and ``'es'`` is in :setting:`LANGUAGES` but + ``'es-ar'`` isn't. + + If ``strict`` is ``False`` (the default), a country-specific variant may + be returned when neither the language code nor its generic variant is found. + For example, if only ``'es-co'`` is in :setting:`LANGUAGES`, that's + returned for ``lang_code``\s like ``'es'`` and ``'es-ar'``. Those matches + aren't returned if ``strict=True``. + + Raises :exc:`LookupError` if nothing is found. + .. function:: to_locale(language) Turns a language name (en-us) into a locale name (en_US). diff --git a/docs/releases/2.1.txt b/docs/releases/2.1.txt index b1fc5015f6..0963862f17 100644 --- a/docs/releases/2.1.txt +++ b/docs/releases/2.1.txt @@ -162,7 +162,8 @@ Generic Views Internationalization ~~~~~~~~~~~~~~~~~~~~ -* ... +* Added the :meth:`~django.utils.translation.get_supported_language_variant` + function. Management Commands ~~~~~~~~~~~~~~~~~~~ |
