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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#!/usr/bin/env python2.7
import json
import os
import re
import sys
import codecs
from xml import sax
class Iso3166(sax.handler.ContentHandler, dict):
def startElement(self, name, attrs):
if 'alpha_2_code' in attrs:
self[attrs['alpha_2_code'].lower()] = attrs['name']
class Iso639(sax.handler.ContentHandler, dict):
def startElement(self, name, attrs):
if 'iso_639_1_code' in attrs:
self[attrs['iso_639_1_code']] = attrs['name']
if 'iso_639_2B_code' in attrs:
self[attrs['iso_639_2B_code']] = attrs['name']
class Iso639_3(sax.handler.ContentHandler, dict):
def startElement(self, name, attrs):
if 'id' in attrs:
self[attrs['id']] = attrs['name']
if 'part1_code' in attrs:
self[attrs['part1_code']] = attrs['name']
if 'part2_code' in attrs and not attrs['part2_code'] in self:
self[attrs['part2_code']] = attrs['name']
if os.path.exists('/usr/share/iso-codes/json/iso_639-2.json'):
with open('/usr/share/iso-codes/json/iso_639-2.json') as fh:
iso639 = {}
for data in json.load(fh)['639-2']:
for k in ('alpha_2', 'alpha_3', 'bibliographic'):
if k in data:
iso639[data[k]] = data['name']
with open('/usr/share/iso-codes/json/iso_639-3.json') as fh:
iso639_3 = {}
for data in json.load(fh)['639-3']:
for k in ('alpha_2', 'alpha_3', 'bibliographic'):
if k in data:
iso639_3[data[k]] = \
data.get('inverted_name') or data['name']
with open('/usr/share/iso-codes/json/iso_3166-1.json') as fh:
iso3166 = {}
for data in json.load(fh)['3166-1']:
if 'alpha_2' in data:
iso3166[data['alpha_2'].lower()] = data['name']
else:
parser = sax.make_parser()
iso639_3 = Iso639_3()
parser.setContentHandler(iso639_3)
parser.parse('/usr/share/xml/iso-codes/iso_639_3.xml')
iso639 = Iso639()
parser.setContentHandler(iso639)
parser.parse('/usr/share/xml/iso-codes/iso_639.xml')
iso3166 = Iso3166()
parser.setContentHandler(iso3166)
parser.parse('/usr/share/xml/iso-codes/iso_3166.xml')
recommends = {}
with open('debian/l10n/recommends') as f:
for line in f.readlines():
lang, value = line.split(':')
recommends[lang.strip()] = value.strip()
RE = re.compile(r'^([^,\(]+)(?:, *([^\(]+) *)?(?: *\(.*\))?$')
ICEWEASEL_L10N = set((
'ach', 'af', 'an', 'ar', 'as', 'ast', 'az', 'be', 'bg', 'bn-bd', 'bn-in', 'br',
'bs', 'ca', 'cs', 'cy', 'da', 'de', 'dsb', 'el', 'en-gb', 'en-za', 'eo',
'es-ar', 'es-cl', 'es-es', 'es-mx', 'et', 'eu', 'fa', 'ff', 'fi', 'fr',
'fy-nl', 'ga-ie', 'gd', 'gl', 'gn', 'gu-in', 'he', 'hi-in', 'hr', 'hsb', 'hu',
'hy-am', 'id', 'is', 'it', 'ja', 'kk', 'km', 'kn', 'ko', 'lij', 'lt', 'lv',
'mai', 'mk', 'ml', 'mr', 'ms', 'nb-no', 'nl', 'nn-no', 'or', 'pa-in', 'pl',
'pt-br', 'pt-pt', 'rm', 'ro', 'ru', 'si', 'sk', 'sl', 'son', 'sq', 'sr',
'sv-se', 'ta', 'te', 'th', 'tr', 'uk', 'uz', 'vi', 'xh', 'zh-cn', 'zh-tw',
))
for code in sys.argv[1:]:
if '-' in code:
lang, country = code.split('-')
else:
lang = code
country = None
if lang in iso639_3:
str = iso639_3[lang.lower()]
else:
str = iso639[lang.lower()]
m = RE.match(str)
if m.group(2):
str = ' '.join([m.group(2).strip(), m.group(1).strip()])
else:
str = m.group(1).strip()
if country:
country_ = iso3166.get(country.lower())
if country_:
country = country_
else:
country = {
'valencia': 'Valencia',
}[country.lower()]
if ',' in country:
country = country[:country.index(',')]
str += ' (' + country + ')'
print()
print('%define L10N_LANG', code.lower())
print('%define L10N_LANGUAGE', str)
if code.lower() in recommends:
print('%define L10N_RECOMMENDS', recommends[code.lower()])
else:
print('%undef L10N_RECOMMENDS')
if code.lower() in ICEWEASEL_L10N:
print('%define L10N_TRANSITION 1')
else:
print('%undef L10N_TRANSITION')
print('%include @PRODUCT@-l10n.control.in')
|