Permalink
Browse files

Aliased trans_null.to_locale() to trans_real.to_locale().

The implementations have unintentionally diverged.
  • Loading branch information...
hramezani authored and timgraham committed May 11, 2018
1 parent a5a2cee commit ac59ec8f1a34ea0e82bdb3c77422694e8016e0a7
Showing with 4 additions and 6 deletions.
  1. +3 −6 django/utils/translation/trans_null.py
  2. +1 −0 tests/i18n/tests.py
@@ -4,6 +4,8 @@
from django.conf import settings
+from .trans_real import to_locale as trans_real_to_locale
+

This comment has been minimized.

Show comment Hide comment
@charettes

charettes May 12, 2018

Member

@hramezani, @timgraham I think that this import defeats the whole purpose of the logic in django.utils.translation.__init__ which is to avoid importing from trans_real in order to not to load the translation machinery if settings.USE_I18N is False.

@charettes

charettes May 12, 2018

Member

@hramezani, @timgraham I think that this import defeats the whole purpose of the logic in django.utils.translation.__init__ which is to avoid importing from trans_real in order to not to load the translation machinery if settings.USE_I18N is False.

This comment has been minimized.

Show comment Hide comment
@timgraham

timgraham May 12, 2018

Member

I thought that might be the case. So I guess we should just duplicate the method?

@timgraham

timgraham May 12, 2018

Member

I thought that might be the case. So I guess we should just duplicate the method?

This comment has been minimized.

Show comment Hide comment
@charettes

charettes May 12, 2018

Member

I think that'd be necessary in this case.

@charettes

charettes May 12, 2018

Member

I think that'd be necessary in this case.

This comment has been minimized.

Show comment Hide comment
@timgraham

timgraham May 12, 2018

Member

Or... the implementation can go in __init__.py and there's no need for two copies in trans_null and trans_real?

@timgraham

timgraham May 12, 2018

Member

Or... the implementation can go in __init__.py and there's no need for two copies in trans_null and trans_real?

This comment has been minimized.

Show comment Hide comment
@charettes

charettes May 12, 2018

Member

yeah that'd be even better!

@charettes

charettes May 12, 2018

Member

yeah that'd be even better!

This comment has been minimized.

Show comment Hide comment
@hramezani

hramezani May 12, 2018

Contributor

I can do it. I am going to make a pull request for it. is it ok?

@hramezani

hramezani May 12, 2018

Contributor

I can do it. I am going to make a pull request for it. is it ok?

This comment has been minimized.

Show comment Hide comment
@timgraham

timgraham May 12, 2018

Member

done in #9943

def gettext(message):
return message
@@ -52,12 +54,7 @@ def check_for_language(x):
return True
-def to_locale(language):
- p = language.find('-')
- if p >= 0:
- return language[:p].lower() + '_' + language[p + 1:].upper()
- else:
- return language.lower()
+to_locale = trans_real_to_locale
def get_language_from_request(request, check_path=False):
View
@@ -286,6 +286,7 @@ def test_to_locale(self):
for lang, locale in tests:
with self.subTest(lang=lang):
self.assertEqual(to_locale(lang), locale)
+ self.assertEqual(trans_null.to_locale(lang), locale)
def test_to_language(self):
self.assertEqual(trans_real.to_language('en_US'), 'en-us')

0 comments on commit ac59ec8

Please sign in to comment.