Repository: inducer/relate

Issue:
Bug: Course specific language related bug
If settings.LANGUAGES is overrided for the purpose of course specific language, the translated language_code(s) also need to be specified in settings.LANGUAGES, or his translation will not be used and will fallback to en-us.

I'll modify checks to add warning about that, and update tests.



Discussion:

Resolving patch:
diff --git a/local_settings.example.py b/local_settings.example.py
--- a/local_settings.example.py
+++ b/local_settings.example.py
@@ -339,11 +339,15 @@
 
 #LANGUAGE_CODE = 'en-us'
 
-# It's recommended to configure LANGUAGES if you want to filter languages allowed
-# for course-specific languages. The format of languages should be a list/tuple of
-# 2-tuples: (language_code, language_description). If there are entries with the
-# same language_code, its language_description will use the one presents latest.
-# If LANGUAGE is not configured, django.conf.global_settings.LANGUAGES will be used.
+# You can (and it's recommended to) override Django's built-in LANGUAGES settings
+# if you want to filter languages allowed for course-specific languages.
+# The format of languages should be a list/tuple of 2-tuples:
+# (language_code, language_description). If there are entries with the same
+# language_code, language_description will be using the one which comes latest.
+#.If LANGUAGES is not configured, django.conf.global_settings.LANGUAGES will be
+# used.
+# Note: make sure LANGUAGE_CODE you used is also in LANGUAGES, if it is not
+# the default "en-us". Otherwise translation of that language will not work.
 
 # LANGUAGES = [
 #     ('en', 'English'),
diff --git a/relate/checks.py b/relate/checks.py
--- a/relate/checks.py
+++ b/relate/checks.py
@@ -377,18 +377,17 @@ def check_relate_settings(app_configs, **kwargs):
             )
         else:
             from collections import OrderedDict
-            all_options = (
-                ((settings.LANGUAGE_CODE, None),) + tuple(settings.LANGUAGES))
-            filtered_options_dict = OrderedDict(all_options)
-            all_lang_codes = [lang_code for lang_code, lang_descr in all_options]
-            for lang_code in filtered_options_dict.keys():
+            options_dict = OrderedDict(tuple(settings.LANGUAGES))
+            all_lang_codes = [lang_code for lang_code, lang_descr
+                              in tuple(settings.LANGUAGES)]
+            for lang_code in options_dict.keys():
                 if all_lang_codes.count(lang_code) > 1:
                     errors.append(Warning(
                         msg=(
                             "Duplicate language entries were found in "
                             "settings.LANGUAGES for '%s', '%s' will be used "
                             "as its language_description"
-                            % (lang_code, filtered_options_dict[lang_code])),
+                            % (lang_code, options_dict[lang_code])),
                         id="relate_languages.W001"
                     ))
 


Test patch:
diff --git a/tests/test_checks.py b/tests/test_checks.py
--- a/tests/test_checks.py
+++ b/tests/test_checks.py
@@ -580,19 +580,13 @@ def test_lang_type_string(self):
 
     def test_item_having_same_lang_code_with_settings_language_code(self):
         with override_settings(LANGUAGES=self.VALID_CONF1, LANGUAGE_CODE="en"):
-            self.assertCheckMessages(
-                expected_ids=["relate_languages.W001"],
-
-                # 'my English' is used for language description of 'en'
-                # instead of 'English'
-                expected_msgs=[
-                    "Duplicate language entries were found in "
-                    "settings.LANGUAGES for 'en', 'my English' "
-                    "will be used as its language_description"]
-            )
+            # This should not generate warning of duplicate language entries
+            # since that is how Django works.
+            self.assertCheckMessages([])
 
     def test_item_duplicated_inside_settings_languages(self):
-        with override_settings(LANGUAGES=self.VALID_WITH_WARNNING_CONF):
+        with override_settings(LANGUAGES=self.VALID_WITH_WARNNING_CONF,
+                               LANGUAGE_CODE="en-us"):
             self.assertCheckMessages(
                 expected_ids=["relate_languages.W001"],
 
@@ -605,12 +599,6 @@ def test_item_duplicated_inside_settings_languages(self):
                     "language_description"]
             )
 
-    def test_item_duplicated_mixed(self):
-        with override_settings(LANGUAGES=self.VALID_WITH_WARNNING_CONF,
-                               LANGUAGE_CODE="en"):
-            self.assertCheckMessages(
-                ["relate_languages.W001", "relate_languages.W001"])
-
 
 class CheckRelateSiteName(CheckRelateSettingsBase):
     msg_id_prefix = "relate_site_name"