Skip to content

Commit

Permalink
This unfortunately broke with the recent babel upgrade. (#2757)
Browse files Browse the repository at this point in the history
Fix locale parsing. This unfortunately broke with the recent babel upgrade.

Make sure we use Locale.parse, this also adds a test that makes
sure we now can resolve all language codes that reside
in AMO_LANGUAGES.

Fixes #2753
  • Loading branch information
EnTeQuAk committed May 26, 2016
1 parent e78aeb6 commit b3c2ffe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/olympia/amo/tests/test_utils_.py
Expand Up @@ -3,11 +3,14 @@

import mock
import pytest
from babel import Locale
from django.conf import settings

from olympia import amo
from olympia.amo.tests import TestCase, addon_factory
from olympia.amo.utils import (
attach_trans_dict, translations_for_field, walkfiles)
attach_trans_dict, translations_for_field, walkfiles,
get_locale_from_lang)
from olympia.addons.models import Addon
from olympia.versions.models import Version

Expand Down Expand Up @@ -172,3 +175,19 @@ def bar(self):
del foo.bar
assert foo.bar == 'original value'
assert callme.call_count == 1


@pytest.mark.parametrize('lang', settings.AMO_LANGUAGES)
def test_get_locale_from_lang(lang):
"""Make sure all languages in settings.AMO_LANGUAGES can be resolved."""
locale = get_locale_from_lang(lang)

assert isinstance(locale, Locale)
assert locale.language == lang[:2]

separator = filter(
None, [sep if sep in lang else None for sep in ('-', '_')])

if separator:
territory = lang.split(separator[0])[1]
assert locale.territory == territory
3 changes: 2 additions & 1 deletion src/olympia/amo/utils.py
Expand Up @@ -597,7 +597,8 @@ def get_locale_from_lang(lang):
# Special fake language can just act like English for formatting and such
if not lang or lang == 'dbg':
lang = 'en'
return Locale(translation.to_locale(lang))

return Locale.parse(translation.to_locale(lang))


class HttpResponseSendFile(http.HttpResponse):
Expand Down

0 comments on commit b3c2ffe

Please sign in to comment.