summaryrefslogtreecommitdiff
path: root/Tools/i18n/makelocalealias.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-10-02 10:21:43 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2014-10-02 10:21:43 +0300
commitcc7f36e1c2cb6865100f3cc6d400c1780f7f9ada (patch)
tree2997077c4f0abcdaed33cd337b0acef8419eb02b /Tools/i18n/makelocalealias.py
parent5eba438c058b89e4027939b82ecdc25b4db0a052 (diff)
parent296d8c3f1e74805037cdbaf2fe917979bfb309b4 (diff)
downloadcpython-cc7f36e1c2cb6865100f3cc6d400c1780f7f9ada.tar.gz
Issue #20076: Apply optimization in makelocalealias.py repeatedly.
Remove just added the sr_rs.utf8@latn alias because it is derived from sr_rs@latin.
Diffstat (limited to 'Tools/i18n/makelocalealias.py')
-rwxr-xr-xTools/i18n/makelocalealias.py56
1 files changed, 50 insertions, 6 deletions
diff --git a/Tools/i18n/makelocalealias.py b/Tools/i18n/makelocalealias.py
index 10887ce338..25cb337b96 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'
@@ -44,10 +45,37 @@ def parse(filename):
encoding = encoding.replace('-', '')
encoding = encoding.replace('_', '')
locale = lang + '.' + encoding
- if encoding.lower() == 'utf8':
- # Ignore UTF-8 mappings - this encoding should be
- # available for all locales
- continue
+ 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
@@ -92,9 +120,25 @@ 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))
- data = optimize(data)
+ if args.glibc_supported:
+ data.update(parse_glibc_supported(args.glibc_supported))
+ data.update(parse(args.locale_alias))
+ while True:
+ # Repeat optimization while the size is decreased.
+ n = len(data)
+ data = optimize(data)
+ if len(data) == n:
+ break
print_differences(data, locale.locale_alias)
print()
print('locale_alias = {')