Permalink
Browse files

Support all regional versions of newsletter languages.

bug 799283.
  • Loading branch information...
1 parent 96751c6 commit c69b097ea3ce74a68d223a44b3d3ff73faaff387 @pmac pmac committed with rik Nov 13, 2012
Showing with 26 additions and 23 deletions.
  1. +20 −16 apps/mozorg/forms.py
  2. +5 −6 apps/mozorg/tests/test_middleware.py
  3. +1 −1 settings/base.py
View
@@ -29,17 +29,20 @@ def strip_parenthetical(lang_name):
def get_lang_choices():
"""
- Return a list of choices for language localized for the given locale.
+ Return a localized list of choices for language.
"""
lang_choices = []
for lang in LANGS:
- try:
+ if lang in product_details.languages:
lang_name = product_details.languages[lang]['native']
- except KeyError:
- continue
- if lang in LANGS_TO_STRIP:
- lang_name = strip_parenthetical(lang_name)
- lang_choices.append([lang, lang_name])
+ else:
+ try:
+ locale = [loc for loc in product_details.languages.keys()
+ if loc.startswith(lang)][0]
+ except IndexError:
+ continue
+ lang_name = product_details.languages[locale]['native']
+ lang_choices.append([lang, strip_parenthetical(lang_name)])
return sorted(lang_choices, key=itemgetter(1))
@@ -88,23 +91,24 @@ class NewsletterForm(forms.Form):
privacy = forms.BooleanField(widget=PrivacyWidget)
source_url = forms.URLField(verify_exists=False, required=False)
+ LANG_CHOICES = get_lang_choices()
+
def __init__(self, locale, *args, **kwargs):
regions = product_details.get_regions(locale)
regions = sorted(regions.iteritems(), key=lambda x: x[1])
- lang_choices = get_lang_choices()
- lang_initial = locale if locale in LANGS else 'en-US'
- ccode = locale.lower()
- if '-' in ccode:
- ccode = ccode.split('-')[1]
+ lang = country = locale.lower()
+ if '-' in lang:
+ lang, country = lang.split('-', 1)
+ lang = lang if lang in LANGS else 'en'
super(NewsletterForm, self).__init__(*args, **kwargs)
self.fields['country'] = forms.ChoiceField(choices=regions,
- initial=ccode,
+ initial=country,
required=False)
- self.fields['lang'] = forms.ChoiceField(choices=lang_choices,
- initial=lang_initial,
- required=False)
+ self.fields['lang'] = forms.ChoiceField(choices=self.LANG_CHOICES,
+ initial=lang,
+ required=False)
class ContributeForm(forms.Form):
@@ -34,22 +34,21 @@ def test_country_selected(self):
def test_language_selected(self):
"""
The correct language for the locale should be initially selected or
- en-US if it's not an option.
+ 'en' if it's not an option.
"""
with self.activate('fr'):
resp = self.client.get(reverse(self.view_name))
-
doc = pq(resp.content)
eq_(doc('#id_lang option[selected="selected"]').val(), 'fr')
+ # with hyphenated regional locale, should have only lang
with self.activate('pt-BR'):
resp = self.client.get(reverse(self.view_name))
-
doc = pq(resp.content)
- eq_(doc('#id_lang option[selected="selected"]').val(), 'pt-BR')
+ eq_(doc('#id_lang option[selected="selected"]').val(), 'pt')
+ # not supported. should default to 'en'
with self.activate('ak'):
resp = self.client.get(reverse(self.view_name))
-
doc = pq(resp.content)
- eq_(doc('#id_lang option[selected="selected"]').val(), 'en-US')
+ eq_(doc('#id_lang option[selected="selected"]').val(), 'en')
View
@@ -30,7 +30,7 @@
'sv-SE', 'sw', 'ta', 'ta-LK', 'te', 'th', 'tr', 'uk',
'vi', 'wo', 'zh-CN', 'zh-TW', 'zu')
DEV_LANGUAGES = list(DEV_LANGUAGES) + ['en-US']
-NEWSLETTER_LANGUAGES = ['de', 'en-US', 'es', 'fr', 'id', 'pt-BR', 'ru']
+NEWSLETTER_LANGUAGES = ['de', 'en', 'es', 'fr', 'id', 'pt', 'ru']
FEED_CACHE = 3900
DOTLANG_CACHE = 60

0 comments on commit c69b097

Please sign in to comment.