forked from lucaswerkmeister/tool-lexeme-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage.py
47 lines (34 loc) · 1.51 KB
/
language.py
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
"""Module to convert between different kinds of language codes.
There are three kinds of language codes relevant for this tool:
- MediaWiki language codes
- HTML language codes (aka BCP47 language tags)
- Babel language codes
Additionally, MediaWiki language codes differ by usage between:
- lexicographical data language codes
- user interface language codes
Templates specify lexicographical data MediaWiki language codes;
translations are given for user interface language codes.
These language codes cannot be converted to one another losslessly,
and this module does not provide functions for all possible
conversions; rather, it only implements conversions to less specific
codes, which may lose some information."""
def lang_lex2int(code: str) -> str:
"""Convert a MediaWiki language code from lexicographical data usage
to user interface usage."""
return {
# Manbhumi reuses the standard Bengali messages
'bn-x-Q6747180': 'bn',
}.get(code, code)
def lang_int2html(code: str) -> str:
"""Convert a MediaWiki user interface language code to an HTML one."""
# no changes needed so far
return code
def lang_int2babel(code: str) -> str:
"""Convert a MediaWiki user interface language code to a Babel one."""
# remove everything after -, interpreted differently by Babel
code, separator, rest = code.partition('-')
return {
# Latin and Venetian are not in CLDR, Italian is similar for our purposes
'la': 'it',
'vec': 'it',
}.get(code, code)