[PATCH] Rewrite expand_langs to return more items
Radek Vykydal
rvykydal at redhat.com
Fri Sep 7 11:39:45 UTC 2012
Ack.
On 09/07/2012 11:48 AM, Vratislav Podzimek wrote:
> On Thu, 2012-09-06 at 22:30 +0200, Vratislav Podzimek wrote:
>> 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.
> I've just tested using kickstart with and without this patch and with a
> simple modification (returning list instead of set) it fixes the
> problem. Please review, so I can push it before next anaconda build,
> otherwise we would break again things that commit
> 823b15785ae74f73f643f89a04e72f2595fec499 fixed.
>
>> 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
>>
More information about the anaconda-patches
mailing list