~ubuntu-china-devs/ubuntu-chinese/langpack-o-matic

60 by martin at piware
add update-maps script
1
#!/usr/bin/python
2
3
# this is part of langpack-o-matic, by Martin Pitt <martin.pitt@canonical.com>
4
#
5
# (C) 2006 Canonical Ltd.
6
# Author: Martin Pitt <martin.pitt@canonical.com>
7
#
233 by Arne Goetje
* added split for zh into zh-hans and zh-hant. zh-hans contains zh_CN and ZH_SG, while zh-hant contains zh_HK and zh_TW. This is only done for releases >= 9.10
8
# Update maps/{languages,countries,scripts} from currently installed iso-codes package.
60 by martin at piware
add update-maps script
9
10
import xml.dom.minidom
11
12
def write_sorted_dict(filename, dict):
13
    f = open(filename, 'w')
14
    keys = dict.keys()
15
    keys.sort()
16
    for k in keys:
17
	print >> f, '%s:%s' % (k, dict[k])
18
19
# ISO-639: List of languages, create maps/languages
20
iso639 = {}
21
dom = xml.dom.minidom.parse('/usr/share/xml/iso-codes/iso_639.xml')
22
for entry in dom.getElementsByTagName('iso_639_entry'):
23
    iso639[entry.attributes.get('iso_639_1_code',
24
	entry.attributes['iso_639_2B_code']).nodeValue.encode("UTF-8")] = \
25
	entry.attributes['name'].nodeValue.encode("UTF-8")
26
205 by Arne Goetje
* update-maps: added code to parse iso639-3 list for maps/languages
27
dom = xml.dom.minidom.parse('/usr/share/xml/iso-codes/iso_639_3.xml')
28
for entry in dom.getElementsByTagName('iso_639_3_entry'):
29
    iso639[entry.attributes.get('id',).nodeValue.encode("UTF-8")] = \
30
	entry.attributes['name'].nodeValue.encode("UTF-8")
31
60 by martin at piware
add update-maps script
32
write_sorted_dict('maps/languages', iso639)
33
34
# ISO-3166: List of countries, create maps/countries
35
iso3166 = {}
36
dom = xml.dom.minidom.parse('/usr/share/xml/iso-codes/iso_3166.xml')
37
for entry in dom.getElementsByTagName('iso_3166_entry'):
38
    iso3166[entry.attributes['alpha_2_code'].nodeValue.encode("UTF-8")] = \
39
	entry.attributes['name'].nodeValue.encode("UTF-8")
40
41
write_sorted_dict('maps/countries', iso3166)
233 by Arne Goetje
* added split for zh into zh-hans and zh-hant. zh-hans contains zh_CN and ZH_SG, while zh-hant contains zh_HK and zh_TW. This is only done for releases >= 9.10
42
43
# ISO-15924: List of scripts, create maps/scripts
44
iso15924 = {}
45
dom = xml.dom.minidom.parse('/usr/share/xml/iso-codes/iso_15924.xml')
46
for entry in dom.getElementsByTagName('iso_15924_entry'):
47
    iso15924[entry.attributes['alpha_4_code'].nodeValue.encode("UTF-8")] = \
48
	entry.attributes['name'].nodeValue.encode("UTF-8")
49
50
write_sorted_dict('maps/scripts', iso15924)