[PATCH] Add in a locale mapping to avoid incorrect system settings (#858591).

Chris Lumens clumens at redhat.com
Wed Oct 3 18:29:15 UTC 2012


This is pretty terrible, sorry.

Basically the problem is that we need to write out full locale settings to
/etc/sysconfig/i18n or lots and lots of things on the system are broken.
For instance, "de_DE.UTF-8" is good but "de.UTF-8" is not.

Unfortunately I can find no suitable way to extract this information via
python-babel.  I think our intention is that using geoip will get us the
full locale, but there's no time to do that now.  lang-table used to contain
this mapping for us, but I really don't want to add that file back.  This
fix should be considered temporary.
---
 pyanaconda/localization.py | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py
index e4b9b40..3d2bdc8 100644
--- a/pyanaconda/localization.py
+++ b/pyanaconda/localization.py
@@ -100,6 +100,26 @@ class LocaleInfo(object):
     def __eq__(self, other):
         return repr(self) == repr(other)
 
+def mangleLocale(inLocale):
+    mangleMap = {"af":  "af_ZA",  "am":  "am_ET",  "ar":  "ar_SA",  "as":  "as_IN",
+                 "ast": "ast_ES", "bg":  "bg_BG",  "bn":  "bn_BD",  "ca":  "ca_ES",
+                 "cs":  "cs_CZ",  "cy":  "cy_GB",  "da":  "da_DK",  "de":  "de_DE",
+                 "el":  "el_GR",  "en":  "en_US",  "es":  "es_ES",  "et":  "et_EE",
+                 "fa":  "fa_IR",  "fi":  "fi_FI",  "fr":  "fr_FR",  "gl":  "gl_ES",
+                 "gu":  "gu_IN",  "he":  "he_IL",  "hi":  "hi_IN",  "hr":  "hr_HR",
+                 "hu":  "hu_HU",  "id":  "id_ID",  "ilo": "ilo_PH", "is":  "is_IS",
+                 "it":  "it_IT",  "ja":  "ja_JP",  "kk":  "kk_KK",  "kn":  "kn_IN",
+                 "ko":  "ko_KR",  "lt":  "lt_LT",  "lv":  "lv_LV",  "mai": "mai_IN",
+                 "mk":  "mk_MK",  "ml":  "ml_IN",  "mr":  "mr_IN",  "ms":  "ms_MY",
+                 "nb":  "nb_NO",  "nds": "nds_DE", "ne":  "ne_NP",  "nl":  "nl_NL",
+                 "nn":  "nn_NO",  "nso": "nso_ZA", "or":  "or_IN",  "pa":  "pa_IN",
+                 "pl":  "pl_PL",  "pt":  "pt_PT",  "ro":  "ro_RO",  "ru":  "ru_RU",
+                 "si":  "si_LK",  "sk":  "sk_SK",  "sl":  "sl_SI",  "sq":  "sq_AL",
+                 "sr":  "sr_RS",  "sv":  "sv_SE",  "ta":  "ta_IN",  "te":  "te_IN",
+                 "tg":  "tg_TG",  "th":  "th_TH",  "tr":  "tr_TR",  "uk":  "uk_UA",
+                 "ur":  "ur_PK",  "vi":  "vi_VN",  "zu":  "zu_ZA"}
+
+    return mangleMap.get(inLocale, inLocale)
 
 # XXX this should probably be somewhere else
 def partition(seq, func=bool, func_range=(True, False)):
@@ -144,7 +164,7 @@ def get_available_translations(domain=None, localedir=None):
 
     for langcode in languages:
         try:
-            localedata = babel.Locale.parse(langcode)
+            localedata = babel.Locale.parse(mangleLocale(langcode))
         except babel.core.UnknownLocaleError:
             continue
 
@@ -268,8 +288,8 @@ class Language(object):
     def __init__(self, preferences={}, territory=None):
         self.translations = {repr(locale):locale for locale in get_available_translations()}
         self.locales = {repr(locale):locale for locale in get_all_locales()}
-        self.preferred_translation = self.translations['en.UTF-8']
-        self.preferred_locales = [self.locales['en.UTF-8']]
+        self.preferred_translation = self.translations['en_US.UTF-8']
+        self.preferred_locales = [self.locales['en_US.UTF-8']]
         self.preferred_locale = self.preferred_locales[0]
 
         self.all_preferences = preferences
-- 
1.7.11.2



More information about the anaconda-patches mailing list