summaryrefslogtreecommitdiffstats
path: root/Tools/i18n
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-10-01 20:42:30 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-10-01 20:42:30 (GMT)
commitea4f0573b416de413df25246a59d8fa95c90a8a0 (patch)
tree8775b00ad147a60af19a8c4091c05a2e796f88e8 /Tools/i18n
parentcf4d6997a3f421a9c5b83dcd92984182a8a5d98f (diff)
downloadcpython-ea4f0573b416de413df25246a59d8fa95c90a8a0.zip
cpython-ea4f0573b416de413df25246a59d8fa95c90a8a0.tar.gz
cpython-ea4f0573b416de413df25246a59d8fa95c90a8a0.tar.bz2
Issue #20079: Added locales supported in glibc 2.18 to locale alias table.
The makelocalealias.py script now can parse the SUPPORTED file from glibc sources and supports command line options for source paths.
Diffstat (limited to 'Tools/i18n')
-rwxr-xr-xTools/i18n/makelocalealias.py45
1 files changed, 44 insertions, 1 deletions
diff --git a/Tools/i18n/makelocalealias.py b/Tools/i18n/makelocalealias.py
index 10887ce..ca69daa 100755
--- a/Tools/i18n/makelocalealias.py
+++ b/Tools/i18n/makelocalealias.py
@@ -8,6 +8,7 @@
"""
import locale
import sys
+_locale = locale
# Location of the alias file
LOCALE_ALIAS = '/usr/share/X11/locale/locale.alias'
@@ -51,6 +52,37 @@ def parse(filename):
data[locale] = alias
return data
+def parse_glibc_supported(filename):
+
+ with open(filename, encoding='latin1') as f:
+ lines = list(f)
+ data = {}
+ for line in lines:
+ line = line.strip()
+ if not line:
+ continue
+ if line[:1] == '#':
+ continue
+ if '/' not in line:
+ continue
+ line = line.rstrip('\\').rstrip()
+ alias, _, alias_encoding = line.partition('/')
+ # Lower-case locale
+ locale = alias.lower()
+ # Normalize encoding, if given
+ if '.' in locale:
+ lang, encoding = locale.split('.')[:2]
+ encoding = encoding.replace('-', '')
+ encoding = encoding.replace('_', '')
+ locale = lang + '.' + encoding
+ # Add an encoding to alias
+ alias, _, modifier = alias.partition('@')
+ alias = _locale._replace_encoding(alias, alias_encoding)
+ if modifier and not (modifier == 'euro' and alias_encoding == 'ISO-8859-15'):
+ alias += '@' + modifier
+ data[locale] = alias
+ return data
+
def pprint(data):
items = sorted(data.items())
for k, v in items:
@@ -92,8 +124,19 @@ def check(data):
return errors
if __name__ == '__main__':
+ import argparse
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--locale-alias', default=LOCALE_ALIAS,
+ help='location of the X11 alias file '
+ '(default: %a)' % LOCALE_ALIAS)
+ parser.add_argument('--glibc-supported',
+ help='location of the glibc SUPPORTED locales file')
+ args = parser.parse_args()
+
data = locale.locale_alias.copy()
- data.update(parse(LOCALE_ALIAS))
+ if args.glibc_supported:
+ data.update(parse_glibc_supported(args.glibc_supported))
+ data.update(parse(args.locale_alias))
data = optimize(data)
print_differences(data, locale.locale_alias)
print()