diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
commit | 458120dd40db6b4df55a4e96b650e16798ef06a0 (patch) | |
tree | 8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/src/cmd/python/Tools/i18n/makelocalealias.py | |
parent | 3a742c699f6806c1145aea5149bf15de15a0afd7 (diff) |
add hg and python
Diffstat (limited to 'sys/src/cmd/python/Tools/i18n/makelocalealias.py')
-rw-r--r-- | sys/src/cmd/python/Tools/i18n/makelocalealias.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/sys/src/cmd/python/Tools/i18n/makelocalealias.py b/sys/src/cmd/python/Tools/i18n/makelocalealias.py new file mode 100644 index 000000000..43df35a0a --- /dev/null +++ b/sys/src/cmd/python/Tools/i18n/makelocalealias.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +""" + Convert the X11 locale.alias file into a mapping dictionary suitable + for locale.py. + + Written by Marc-Andre Lemburg <mal@genix.com>, 2004-12-10. + +""" +import locale + +# Location of the alias file +LOCALE_ALIAS = '/usr/lib/X11/locale/locale.alias' + +def parse(filename): + + f = open(filename) + lines = f.read().splitlines() + data = {} + for line in lines: + line = line.strip() + if not line: + continue + if line[:1] == '#': + continue + locale, alias = line.split() + # Strip ':' + if locale[-1] == ':': + locale = locale[:-1] + # Lower-case locale + locale = locale.lower() + # Ignore one letter locale mappings (except for 'c') + if len(locale) == 1 and locale != 'c': + continue + # Normalize encoding, if given + if '.' in locale: + lang, encoding = locale.split('.')[:2] + encoding = encoding.replace('-', '') + encoding = encoding.replace('_', '') + locale = lang + '.' + encoding + if encoding.lower() == 'utf8': + # Ignore UTF-8 mappings - this encoding should be + # available for all locales + continue + data[locale] = alias + return data + +def pprint(data): + + items = data.items() + items.sort() + for k,v in items: + print ' %-40s%r,' % ('%r:' % k, v) + +def print_differences(data, olddata): + + items = olddata.items() + items.sort() + for k, v in items: + if not data.has_key(k): + print '# removed %r' % k + elif olddata[k] != data[k]: + print '# updated %r -> %r to %r' % \ + (k, olddata[k], data[k]) + # Additions are not mentioned + +if __name__ == '__main__': + data = locale.locale_alias.copy() + data.update(parse(LOCALE_ALIAS)) + print_differences(data, locale.locale_alias) + print + print 'locale_alias = {' + pprint(data) + print '}' |