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