From 7905815510fb1eae99010ccc0039249d981a121c Mon Sep 17 00:00:00 2001 From: Sebastian Sangervasi Date: Tue, 27 Jun 2017 16:50:26 -0700 Subject: Fixed #27449 -- Added django.utils.translation.get_supported_language_variant(). --- docs/ref/utils.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'docs/ref') 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). -- cgit v1.3