These two patches do almost the same as the two patches proposed in the bugreport. While they are more general (PATCH 1/2) they doesn't fix the problem with sr_RS@latin displayed as Serbian (Serbia) instead of Serbian (Latin). I'm not sure this is a big deal and I believe user should be able to see which one is the @latin one by switching between them. However these translations both appear to use cyrilic variant (Another bug? Where? $lang is set correctly.).
Vratislav Podzimek (2): Handle locale's encoding and script in a better way Some more stuff for the mangleMap (#866730)
pyanaconda/localization.py | 102 +++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 27 deletions(-)
Encoding should go between _territory and @script. Neither script nor is not parsed by babel.Locale.parse.
Related: rhbz#866730 --- pyanaconda/localization.py | 68 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-)
diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py index c343888..bdfc64b 100644 --- a/pyanaconda/localization.py +++ b/pyanaconda/localization.py @@ -40,8 +40,19 @@ class LocalizationConfigError(Exception):
class LocaleInfo(object):
- def __init__(self, localedata): + def __init__(self, localedata, encoding="", script=""): + """ + @param encoding: encoding from the locale specification, e.g. UTF-8 + (localedata object has no attribute for that) + @param script: script from the locale specification (e.g. latin) + (changing localedata.script attribute results in + problems) + + """ + self._localedata = localedata + self._encoding = encoding or "UTF-8" + self._script = script
@property def language(self): @@ -53,13 +64,17 @@ class LocaleInfo(object):
@property def script(self): - return self._localedata.script + return self._script
@property def variant(self): return self._localedata.variant
@property + def encoding(self): + return self._encoding + + @property def english_name(self): return self._localedata.english_name or u''
@@ -79,17 +94,14 @@ class LocaleInfo(object): formatstr = '{0.language}' if self.territory is not None: formatstr += '_{0.territory}' - if self.script is not None: + if self.encoding: + formatstr += '.{0.encoding}' + if self.script: formatstr += '@{0.script}' if self.variant is not None: formatstr += '#{0.variant}'
- langcode = formatstr.format(self) - if "." not in langcode: - # add enconding suffix - langcode = langcode + ".UTF-8" - - return langcode + return formatstr.format(self)
def __str__(self): return self.english_name.encode('ascii', 'replace') @@ -144,7 +156,11 @@ def get_all_locales(): except babel.core.UnknownLocaleError: continue
- locale = LocaleInfo(localedata) + # BUG: babel.Locale.parse does not parse @script + script = _get_locale_script(localename) + encoding = _get_locale_encoding(localename) + + locale = LocaleInfo(localedata, encoding, script) if repr(locale) not in localeset: localeset.add(repr(locale)) yield locale @@ -168,7 +184,13 @@ def get_available_translations(domain=None, localedir=None): except babel.core.UnknownLocaleError: continue
- yield LocaleInfo(localedata) + encoding = _get_locale_encoding(langcode) + + # BUG: babel.Locale.parse does not parse @script + script = _get_locale_script(langcode) + + localeinfo = LocaleInfo(localedata, encoding, script) + yield localeinfo
def expand_langs(astring): """ @@ -220,6 +242,30 @@ def expand_langs(astring):
return list(langs)
+def _get_locale_encoding(locale): + """ + If locale specification includes encoding (e.g. cs_CZ.UTF-8) returns + the encoding. Otherwise returns "". + + """ + + if "@" in locale: + # remove @script suffix + locale = locale.split("@", -1)[0] + + if "." in locale: + return locale.split(".", -1)[1] + else: + return "" + +def _get_locale_script(locale): + """Same as _get_locale_encoding but with the script.""" + + if "@" in locale: + return locale.split("@", -1)[1] + else: + return "" + def write_language_configuration(lang, root): """ Write language configuration to the $root/etc/sysconfig/i18n and the
This is only for F18, we really need a better solution for the future. --- pyanaconda/localization.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py index bdfc64b..3b243ae 100644 --- a/pyanaconda/localization.py +++ b/pyanaconda/localization.py @@ -114,22 +114,24 @@ class LocaleInfo(object):
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_KZ", "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_TJ", "th": "th_TH", "tr": "tr_TR", "uk": "uk_UA", - "ur": "ur_PK", "vi": "vi_VN", "zu": "zu_ZA"} + "ast": "ast_ES", "be": "be_BY", "bg": "bg_BG", "bn": "bn_BD", + "bs": "bs_BA", "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", "eu": "eu_ES", "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", + "hy": "hy_AM", "id": "id_ID", "ilo": "ilo_PH", "is": "is_IS", + "it": "it_IT", "ja": "ja_JP", "ka": "ka_GE", "kk": "kk_KZ", + "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", "sr@latin": "sr_RS@latin", + "sv": "sv_SE", "ta": "ta_IN", "te": "te_IN", "tg": "tg_TJ", + "th": "th_TH", "tr": "tr_TR", "uk": "uk_UA", "ur": "ur_PK", + "vi": "vi_VN", "zu": "zu_ZA"}
return mangleMap.get(inLocale, inLocale)
On Fri, Nov 02, 2012 at 11:56:45PM +0100, Vratislav Podzimek wrote:
These two patches do almost the same as the two patches proposed in the bugreport. While they are more general (PATCH 1/2) they doesn't fix the problem with sr_RS@latin displayed as Serbian (Serbia) instead of Serbian (Latin). I'm not sure this is a big deal and I believe user should be able to see which one is the @latin one by switching between them. However these translations both appear to use cyrilic variant (Another bug? Where? $lang is set correctly.).
Vratislav Podzimek (2): Handle locale's encoding and script in a better way Some more stuff for the mangleMap (#866730)
pyanaconda/localization.py | 102 +++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 27 deletions(-)
-- 1.7.11.7
Ack. I'll git-am these for the 18.24 build
anaconda-patches@lists.fedorahosted.org