Skip to content

Commit

Permalink
Fix locale parsing. This unfortunately broke with the recent babel up…
Browse files Browse the repository at this point in the history
…grade.

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 fa272a0 commit 010ba0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/olympia/amo/tests/test_utils_.py
Expand Up @@ -3,11 +3,13 @@

import mock
import pytest
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 +174,9 @@ 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."""
get_locale_from_lang(lang)
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 010ba0c

Please sign in to comment.