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

Commit ec0b807

Browse files
author
Rob Hudson
committed
Follow SHORTER_LANGUAGES when creating app manifests (bug 835407)
This also fixes a bug in the translations app where we were comparing the lowercase locale to settings.HIDDEN_LANGUAGES which (for Marketplace) had locales of the form xx-YY. The result was no translation saved for locales in HIDDEN_LANGUAGES. This updates them to go through amo.utils.to_language which returns the xx-YY form. It also switches from using settings.LANGUAGES (lowercase locales) to settings.AMO_LANGUAGES.
1 parent afae594 commit ec0b807

5 files changed

Lines changed: 47 additions & 10 deletions

File tree

apps/files/utils.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,7 @@ def parse(self, fileorpath):
265265
'default_locale': default_locale}
266266

267267
def trans_locale(self, locale):
268-
# TODO(Kumar) translate all possible locale differences.
269-
# 'en' might be the only one in need of translating.
270-
if locale == 'en':
271-
locale = 'en-us'
272-
return to_language(locale)
268+
return to_language(settings.SHORTER_LANGUAGES.get(locale, locale))
273269

274270
def trans_all_locales(self, locale_dict):
275271
trans = {}

apps/translations/fields.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def __set__(self, instance, value):
136136
elif getattr(instance, self.field.attname, None) is None:
137137
super(TranslationDescriptor, self).__set__(instance, None)
138138

139-
140139
def translation_from_string(self, instance, lang, string):
141140
"""Create, save, and return a Translation from a string."""
142141
try:
@@ -165,11 +164,12 @@ def translation_from_dict(self, instance, lang, dict_):
165164
166165
If one of the locales matches lang, that Translation will be returned.
167166
"""
167+
from amo.utils import to_language as amo_to_language
168+
168169
rv = None
169170
for locale, string in dict_.items():
170-
loc = locale.lower()
171-
if (loc not in settings.LANGUAGES and
172-
loc not in settings.HIDDEN_LANGUAGES):
171+
loc = amo_to_language(locale)
172+
if loc not in settings.AMO_LANGUAGES + settings.HIDDEN_LANGUAGES:
173173
continue
174174
# The Translation is created and saved in here.
175175
trans = self.translation_from_string(instance, locale, string)

apps/translations/tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def test_update_with_dict(self):
201201
trans_eq(get_model().name, 'oui', 'fr')
202202

203203
def test_dict_with_hidden_locale(self):
204-
with self.settings(HIDDEN_LANGUAGES=['xxx']):
204+
with self.settings(HIDDEN_LANGUAGES=('xxx',)):
205205
o = TranslatedModel.objects.get(id=1)
206206
o.name = {'en-US': 'active language', 'xxx': 'hidden language',
207207
'de': 'another language'}

mkt/submit/tests/test_views.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,17 @@ def test_premium(self):
353353
self.assertSetEqual(app.device_types, [amo.DEVICE_GAIA])
354354
eq_(app.premium_type, amo.ADDON_PREMIUM)
355355

356+
def test_short_locale(self):
357+
# This manifest has a locale code of "pt" which is in the
358+
# SHORTER_LANGUAGES setting and should get converted to "pt-PT".
359+
self.manifest = self.manifest_path('short-locale.webapp')
360+
self.upload = self.get_upload(abspath=self.manifest)
361+
addon = self.post_addon()
362+
eq_(addon.default_locale, 'pt-PT')
363+
356364
def test_unsupported_detail_locale(self):
365+
# This manifest has a locale code of "en-GB" which is unsupported, so
366+
# we default to "en-US".
357367
self.manifest = self.manifest_path('unsupported-default-locale.webapp')
358368
self.upload = self.get_upload(abspath=self.manifest)
359369
addon = self.post_addon()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"version": "1.0",
3+
"name": "MozillaBall ょ",
4+
"description": "God save the Queen!",
5+
"icons": {
6+
"16": "/img/icon-16.png",
7+
"48": "/img/icon-48.png",
8+
"128": "/img/icon-128.png"
9+
},
10+
"widget": {
11+
"path": "/widget.html",
12+
"width": 100,
13+
"height": 200
14+
},
15+
"developer": {
16+
"name": "Mozilla Labs",
17+
"url": "http://mozillalabs.com"
18+
},
19+
"installs_allowed_from": [
20+
"*"
21+
],
22+
"locales": {
23+
"es": {
24+
"description": "¡Acción abierta emocionante del desarrollo del Web!",
25+
"developer": {
26+
"url": "http://es.mozillalabs.com/"
27+
}
28+
}
29+
},
30+
"default_locale": "pt"
31+
}

0 commit comments

Comments
 (0)