(filename)
| 17 | SUPPORTED = '/usr/share/i18n/SUPPORTED' |
| 18 | |
| 19 | def parse(filename): |
| 20 | |
| 21 | with open(filename, encoding='latin1') as f: |
| 22 | lines = list(f) |
| 23 | # Remove mojibake in /usr/share/X11/locale/locale.alias. |
| 24 | # b'\xef\xbf\xbd' == '\ufffd'.encode('utf-8') |
| 25 | lines = [line for line in lines if '\xef\xbf\xbd' not in line] |
| 26 | data = {} |
| 27 | for line in lines: |
| 28 | line = line.strip() |
| 29 | if not line: |
| 30 | continue |
| 31 | if line[:1] == '#': |
| 32 | continue |
| 33 | locale, alias = line.split() |
| 34 | # Fix non-standard locale names, e.g. ks_IN@devanagari.UTF-8 |
| 35 | if '@' in alias: |
| 36 | alias_lang, _, alias_mod = alias.partition('@') |
| 37 | if '.' in alias_mod: |
| 38 | alias_mod, _, alias_enc = alias_mod.partition('.') |
| 39 | alias = alias_lang + '.' + alias_enc + '@' + alias_mod |
| 40 | # Strip ':' |
| 41 | if locale[-1] == ':': |
| 42 | locale = locale[:-1] |
| 43 | # Lower-case locale |
| 44 | locale = locale.lower() |
| 45 | # Ignore one letter locale mappings (except for 'c') |
| 46 | if len(locale) == 1 and locale != 'c': |
| 47 | continue |
| 48 | if '@' in locale and '@' not in alias: |
| 49 | # Do not simply remove the "@euro" modifier. |
| 50 | # Glibc generates separate locales with the "@euro" modifier, and |
| 51 | # not always generates a locale without it with the same encoding. |
| 52 | # It can also affect collation. |
| 53 | if locale.endswith('@euro') and not locale.endswith('.utf-8@euro'): |
| 54 | alias += '@euro' |
| 55 | # Normalize encoding, if given |
| 56 | if '.' in locale: |
| 57 | lang, encoding = locale.split('.')[:2] |
| 58 | encoding = encoding.replace('-', '') |
| 59 | encoding = encoding.replace('_', '') |
| 60 | locale = lang + '.' + encoding |
| 61 | data[locale] = alias |
| 62 | # Conflict with glibc. |
| 63 | data.pop('el_gr@euro', None) |
| 64 | data.pop('uz_uz@cyrillic', None) |
| 65 | data.pop('uz_uz.utf8@cyrillic', None) |
| 66 | return data |
| 67 | |
| 68 | def parse_glibc_supported(filename): |
| 69 |
no test coverage detected
searching dependent graphs…