Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Check hidden langs for translations (bug 787375)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumar303 committed Sep 25, 2012
1 parent 7bdb1bf commit 770ca52
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apps/translations/fields.py
Expand Up @@ -167,7 +167,9 @@ def translation_from_dict(self, instance, lang, dict_):
"""
rv = None
for locale, string in dict_.items():
if locale.lower() not in settings.LANGUAGES:
loc = locale.lower()
if (loc not in settings.LANGUAGES and
loc not in settings.HIDDEN_LANGUAGES):
continue
# The Translation is created and saved in here.
trans = self.translation_from_string(instance, locale, string)
Expand Down
10 changes: 10 additions & 0 deletions apps/translations/tests/test_models.py
Expand Up @@ -200,6 +200,16 @@ def test_update_with_dict(self):
translation.activate('fr')
trans_eq(get_model().name, 'oui', 'fr')

def test_dict_with_hidden_locale(self):
with self.settings(HIDDEN_LANGUAGES=['xxx']):
o = TranslatedModel.objects.get(id=1)
o.name = {'en-US': 'active language', 'xxx': 'hidden language',
'de': 'another language'}
o.save()
ts = Translation.objects.filter(id=o.name_id)
eq_(sorted(ts.values_list('locale', flat=True)),
['de', 'en-US', 'xxx'])

def test_dict_bad_locale(self):
m = TranslatedModel.objects.get(id=1)
m.name = {'de': 'oof', 'xxx': 'bam', 'es': 'si'}
Expand Down
13 changes: 13 additions & 0 deletions mkt/settings.py
Expand Up @@ -348,3 +348,16 @@ def APPCACHE_MEDIA_DEBUG():
AMO_LANGUAGES = ('en-US', 'es', 'pt-BR')
LANGUAGES = lazy(lazy_langs, dict)(AMO_LANGUAGES)
LANGUAGE_URL_MAP = dict([(i.lower(), i) for i in AMO_LANGUAGES])

# Not shown on the site, but .po files exist and these are available on the
# L10n dashboard. Generally languages start here and move into AMO_LANGUAGES.
# This list also enables translation edits.
HIDDEN_LANGUAGES = (
# List of languages from AMO's settings (excluding mkt's active locales).
'af', 'ar', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'eu', 'fa',
'fi', 'fr', 'ga-IE', 'he', 'hu', 'id', 'it', 'ja', 'ko', 'mn', 'nl', 'pl',
'pt-PT', 'ro', 'ru', 'sk', 'sl', 'sq', 'sv-SE', 'uk', 'vi',
'zh-CN', 'zh-TW',
# The hidden list from AMO's settings:
'cy', 'sr', 'sr-Latn', 'tr',
)

0 comments on commit 770ca52

Please sign in to comment.