[PATCH] Rewrite expand_langs to return more items

Vratislav Podzimek vpodzime at redhat.com
Thu Sep 6 20:30:11 UTC 2012


Since we now use "en.UTF-8" as language instead of "en", we need
to reflect this also in expand_langs. Otherwise e.g. using 'lang en'
in kickstart wouldn't work.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 pyanaconda/localization.py | 50 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 15 deletions(-)

diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py
index d3dda8a..fdfa9db 100644
--- a/pyanaconda/localization.py
+++ b/pyanaconda/localization.py
@@ -148,30 +148,50 @@ def get_available_translations(domain=None, localedir=None):
 def expand_langs(astring):
     """
     Converts a single language into a "language search path". For example,
-    fr_FR.utf8 at euro would become "fr_FR.utf8 at euro fr_FR.utf8 fr_FR fr"
+    for "fr_FR.UTF-8 at euro" would return set containing:
+    "fr", "fr_FR", "fr_FR.UTF-8 at euro", "fr.UTF-8 at euro", "fr_FR at euro",
+    "fr_FR.UTF-8", "fr at euro", "fr.UTF-8"
+
+    @rtype: set of strings
 
     """
 
-    langs = [astring]
-    charset = None
+    langs = set([astring])
+
     base = None
+    loc = None
+    encoding = None
+    script = None
+
+    if "@" in astring:
+        (astring, script) = astring.split("@", 1)
+
+    if "." in astring:
+        (astring, encoding) = astring.split(".", 1)
+
+    if "_" in astring:
+        (astring, loc) = astring.split("_", 1)
+
+    base = astring
 
-    # remove charset ...
-    if '.' in astring:
-        langs.append(astring.split('.')[0])
+    if not base:
+        return langs
 
-    if '@' in astring:
-        charset = astring.split('@')[1]
+    if not encoding:
+        encoding = "UTF-8"
 
-    if '_' in astring:
-        base = astring.split('_')[0]
+    langs.add(base)
+    langs.add("%s.%s" % (base, encoding))
 
-        if charset:
-            langs.append("%s@%s" % (base, charset))
+    if loc:
+        langs.add("%s_%s" % (base, loc))
+        langs.add("%s_%s.%s" %(base, loc, encoding))
+    if script:
+        langs.add("%s@%s" % (base, script))
+        langs.add("%s.%s@%s" % (base, encoding, script))
 
-        langs.append(base)
-    else:
-        langs.append(astring[:2])
+    if loc and script:
+        langs.add("%s_%s@%s" % (base, loc, script))
 
     return langs
 
-- 
1.7.11.4



More information about the anaconda-patches mailing list