Permalink
Browse files

Moved to_language() to django.utils.translation.

Follow up to 1b7d524.
  • Loading branch information...
timgraham committed May 12, 2018
1 parent 35319bf commit 1e0cbc72e5bcb1c1e235b3cd82a92800ed3c84b8
Showing with 15 additions and 15 deletions.
  1. +10 −1 django/utils/translation/__init__.py
  2. +1 −10 django/utils/translation/trans_real.py
  3. +4 −4 tests/i18n/tests.py
@@ -10,7 +10,7 @@
'activate', 'deactivate', 'override', 'deactivate_all',
'get_language', 'get_language_from_request',
'get_language_info', 'get_language_bidi',
- 'check_for_language', 'to_locale', 'templatize',
+ 'check_for_language', 'to_language', 'to_locale', 'templatize',
'gettext', 'gettext_lazy', 'gettext_noop',
'ugettext', 'ugettext_lazy', 'ugettext_noop',
'ngettext', 'ngettext_lazy',
@@ -193,6 +193,15 @@ def check_for_language(lang_code):
return _trans.check_for_language(lang_code)
+def to_language(locale):
+ """Turn a locale name (en_US) into a language name (en-us)."""
+ p = locale.find('_')
+ if p >= 0:
+ return locale[:p].lower() + '-' + locale[p + 1:].lower()
+ else:
+ return locale.lower()
+
+
def to_locale(language):
"""Turn a language name (en-us) into a locale name (en_US)."""
language = language.lower()
@@ -16,7 +16,7 @@
from django.dispatch import receiver
from django.utils.safestring import SafeData, mark_safe
-from . import LANGUAGE_SESSION_KEY, to_locale
+from . import LANGUAGE_SESSION_KEY, to_language, to_locale
# Translations are cached in a dictionary for every language.
# The active translations are stored by threadid to make them thread local.
@@ -57,15 +57,6 @@ def reset_cache(**kwargs):
get_supported_language_variant.cache_clear()
-def to_language(locale):
- """Turn a locale name (en_US) into a language name (en-us)."""
- p = locale.find('_')
- if p >= 0:
- return locale[:p].lower() + '-' + locale[p + 1:].lower()
- else:
- return locale.lower()
-
-
class DjangoTranslation(gettext_module.GNUTranslations):
"""
Set up the GNUTranslations context with regard to output charset.
View
@@ -30,8 +30,8 @@
LANGUAGE_SESSION_KEY, activate, check_for_language, deactivate,
get_language, get_language_bidi, get_language_from_request,
get_language_info, gettext, gettext_lazy, ngettext, ngettext_lazy,
- npgettext, npgettext_lazy, pgettext, to_locale, trans_null, trans_real,
- ugettext, ugettext_lazy, ungettext, ungettext_lazy,
+ npgettext, npgettext_lazy, pgettext, to_language, to_locale, trans_null,
+ trans_real, ugettext, ugettext_lazy, ungettext, ungettext_lazy,
)
from .forms import CompanyForm, I18nForm, SelectDateForm
@@ -288,8 +288,8 @@ def test_to_locale(self):
self.assertEqual(to_locale(lang), locale)
def test_to_language(self):
- self.assertEqual(trans_real.to_language('en_US'), 'en-us')
- self.assertEqual(trans_real.to_language('sr_Lat'), 'sr-lat')
+ self.assertEqual(to_language('en_US'), 'en-us')
+ self.assertEqual(to_language('sr_Lat'), 'sr-lat')
def test_language_bidi(self):
self.assertIs(get_language_bidi(), False)

0 comments on commit 1e0cbc7

Please sign in to comment.