| 16 | SUPPORTED = '/usr/share/i18n/SUPPORTED' |
| 17 | |
| 18 | def parse(filename): |
| 19 | |
| 20 | with open(filename, encoding='latin1') as f: |
| 21 | lines = list(f) |
| 22 | # Remove mojibake in /usr/share/X11/locale/locale.alias. |
| 23 | # b'\xef\xbf\xbd' == '\ufffd'.encode('utf-8') |
| 24 | lines = [line for line in lines if '\xef\xbf\xbd' not in line] |
| 25 | data = {} |
| 26 | for line in lines: |
| 27 | line = line.strip() |
| 28 | if not line: |
| 29 | continue |
| 30 | if line[:1] == '#': |
| 31 | continue |
| 32 | locale, alias = line.split() |
| 33 | # Fix non-standard locale names, e.g. ks_IN@devanagari.UTF-8 |
| 34 | if '@' in alias: |
| 35 | alias_lang, _, alias_mod = alias.partition('@') |
| 36 | if '.' in alias_mod: |
| 37 | alias_mod, _, alias_enc = alias_mod.partition('.') |
| 38 | alias = alias_lang + '.' + alias_enc + '@' + alias_mod |
| 39 | # Strip ':' |
| 40 | if locale[-1] == ':': |
| 41 | locale = locale[:-1] |
| 42 | # Lower-case locale |
| 43 | locale = locale.lower() |
| 44 | # Ignore one letter locale mappings (except for 'c') |
| 45 | if len(locale) == 1 and locale != 'c': |
| 46 | continue |
| 47 | # Normalize encoding, if given |
| 48 | if '.' in locale: |
| 49 | lang, encoding = locale.split('.')[:2] |
| 50 | encoding = encoding.replace('-', '') |
| 51 | encoding = encoding.replace('_', '') |
| 52 | locale = lang + '.' + encoding |
| 53 | data[locale] = alias |
| 54 | return data |
| 55 | |
| 56 | def parse_glibc_supported(filename): |
| 57 | |