blob: a52bc280ebf4b92bbac3cf6bf97cd514c6ce76db [file] [log] [blame]
Marc-André Lemburgbb4f1bd2004-12-10 21:58:14 +00001#!/usr/bin/env python
2"""
3 Convert the X11 locale.alias file into a mapping dictionary suitable
4 for locale.py.
5
6 Written by Marc-Andre Lemburg <mal@genix.com>, 2004-12-10.
7
8"""
9import locale
10
11# Location of the alias file
12LOCALE_ALIAS = '/usr/lib/X11/locale/locale.alias'
13
14def parse(filename):
15
16 f = open(filename)
17 lines = f.read().splitlines()
18 data = {}
19 for line in lines:
20 line = line.strip()
21 if not line:
22 continue
23 if line[:1] == '#':
24 continue
25 locale, alias = line.split()
26 # Strip ':'
27 if locale[-1] == ':':
28 locale = locale[:-1]
29 # Lower-case locale
30 locale = locale.lower()
31 # Ignore one letter locale mappings (except for 'c')
32 if len(locale) == 1 and locale != 'c':
33 continue
34 # Normalize encoding, if given
35 if '.' in locale:
36 lang, encoding = locale.split('.')[:2]
37 encoding = encoding.replace('-', '')
38 encoding = encoding.replace('_', '')
39 locale = lang + '.' + encoding
40 data[locale] = alias
41 return data
42
43def pprint(data):
44
45 items = data.items()
46 items.sort()
47 for k,v in items:
48 print ' %-40s%r,' % ('%r:' % k, v)
49
50def print_differences(data, olddata):
51
52 items = olddata.items()
53 items.sort()
54 for k, v in items:
55 if not data.has_key(k):
56 print '# removed %r' % k
57 elif olddata[k] != data[k]:
58 print '# updated %r -> %r to %r' % \
59 (k, olddata[k], data[k])
60 # Additions are not mentioned
61
62if __name__ == '__main__':
63 data = locale.locale_alias.copy()
64 data.update(parse(LOCALE_ALIAS))
65 print_differences(data, locale.locale_alias)
66 print
67 print 'locale_alias = {'
68 pprint(data)
69 print '}'
70