зеркало из https://github.com/mozilla/bedrock.git
Fix bug 1100539: Default language has all the tags.
This commit is contained in:
Родитель
ba4f86349b
Коммит
76b2db3a1c
|
@ -25,7 +25,10 @@ from jinja2 import Markup
|
|||
from tower import tweak_message
|
||||
from product_details import product_details
|
||||
|
||||
from lib.l10n_utils.utils import ContainsEverything
|
||||
|
||||
|
||||
ALL_THE_THINGS = ContainsEverything()
|
||||
FORMAT_IDENTIFIER_RE = re.compile(r"""(%
|
||||
(?:\((\w+)\))? # Mapping key
|
||||
s)""", re.VERBOSE)
|
||||
|
@ -230,6 +233,9 @@ def lang_file_tag_set(path, lang=None):
|
|||
:param lang: the language code or the lang of the request if omitted
|
||||
:return: set of strings
|
||||
"""
|
||||
if settings.DEV or lang == settings.LANGUAGE_CODE:
|
||||
return ALL_THE_THINGS
|
||||
|
||||
lang = lang or fix_case(translation.get_language())
|
||||
rel_path = os.path.join('locale', lang, '%s.lang' % path)
|
||||
cache_key = 'tag:%s' % rel_path
|
||||
|
@ -269,9 +275,6 @@ def lang_file_has_tag(path, lang=None, tag='active'):
|
|||
alphanumerics and "_".
|
||||
@return: bool
|
||||
"""
|
||||
if settings.DEV or lang == settings.LANGUAGE_CODE:
|
||||
return True
|
||||
|
||||
return tag in lang_file_tag_set(path, lang)
|
||||
|
||||
|
||||
|
|
|
@ -19,8 +19,10 @@ from jinja2 import Environment
|
|||
|
||||
from dotlang import (parse as parse_lang, get_lang_path,
|
||||
get_translations_for_langfile, lang_file_tag_set)
|
||||
from lib.l10n_utils.utils import ContainsEverything
|
||||
|
||||
|
||||
ALL_THE_THINGS = ContainsEverything()
|
||||
REGEX_URL = re.compile(r'.* (\S+/\S+\.[^:]+).*')
|
||||
cache = get_cache('l10n')
|
||||
|
||||
|
@ -192,6 +194,9 @@ def template_tag_set(path, lang):
|
|||
:param lang: language code
|
||||
:return: set of strings
|
||||
"""
|
||||
if settings.DEV or lang == settings.LANGUAGE_CODE:
|
||||
return ALL_THE_THINGS
|
||||
|
||||
cache_key = 'template_tag_set:{path}:{lang}'.format(lang=lang, path=path)
|
||||
tag_set = cache.get(cache_key)
|
||||
if tag_set is None:
|
||||
|
@ -212,9 +217,6 @@ def template_has_tag(path, lang, tag):
|
|||
:param tag: the tag in question
|
||||
:return: boolean
|
||||
"""
|
||||
if settings.DEV:
|
||||
return True
|
||||
|
||||
return tag in template_tag_set(path, lang)
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ from nose.tools import eq_, ok_
|
|||
|
||||
from lib.l10n_utils.gettext import (_append_to_lang_file, langfiles_for_path,
|
||||
parse_python, parse_template,
|
||||
po_msgs, pot_to_langfiles, template_is_active)
|
||||
po_msgs, pot_to_langfiles, template_is_active,
|
||||
_get_template_tag_set, template_has_tag)
|
||||
from lib.l10n_utils.tests import TempFileMixin
|
||||
from bedrock.mozorg.tests import TestCase
|
||||
|
||||
|
@ -65,6 +66,16 @@ class TestTemplateTagFuncs(TestCase):
|
|||
get_lang_path):
|
||||
"""Should return a unique set of tags from all lang files."""
|
||||
parse_template_mock.return_value = ['dude', 'walter']
|
||||
lang_file_tag_set.side_effect = [set(['dude', 'donny']),
|
||||
set(['dude', 'uli', 'bunny']),
|
||||
set(['walter', 'brandt'])]
|
||||
self.assertSetEqual(_get_template_tag_set('stuff', 'es'),
|
||||
set(['dude', 'walter', 'donny', 'uli', 'bunny', 'brandt']))
|
||||
|
||||
@override_settings(LANGUAGE_CODE='en-US')
|
||||
def test_template_tag_set_default_locale(self):
|
||||
"""The default language should always have every tag."""
|
||||
ok_(template_has_tag('the_dude', 'en-US', 'active'))
|
||||
|
||||
|
||||
class TestPOFiles(TestCase):
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# coding=utf-8
|
||||
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
from nose.tools import ok_
|
||||
|
||||
from lib.l10n_utils.utils import ContainsEverything
|
||||
|
||||
|
||||
def test_contains_everything():
|
||||
all_the_things = ContainsEverything()
|
||||
ok_('dude' in all_the_things)
|
||||
ok_(42 in all_the_things)
|
||||
ok_(list in all_the_things)
|
|
@ -0,0 +1,11 @@
|
|||
# coding=utf-8
|
||||
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
|
||||
class ContainsEverything(object):
|
||||
"""An object whose instances will claim to contain anything."""
|
||||
def __contains__(self, item):
|
||||
return True
|
Загрузка…
Ссылка в новой задаче