Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,46 +7,36 @@ from operator import itemgetter
|
|
7 |
# TODO: reverse transliterate?
|
8 |
|
9 |
|
10 |
-
def get_lang_description_from_mapping_name(string_to_check):
|
11 |
if "generic-Latn" == string_to_check:
|
12 |
return "Generic Latin Script"
|
13 |
|
14 |
if len(string_to_check)<2:
|
15 |
return None
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
except LanguageTagError as e:
|
33 |
-
if any(["out of place" in str(e), "must be followed by something" in str(e)]):
|
34 |
-
# print("*****")
|
35 |
-
# print(e)
|
36 |
-
# LanguageTagError: This extlang subtag, 'red', is out of place. Expected territory, variant, extension, or end of string.
|
37 |
-
# LanguageTagError: This script subtag, 'east', is out of place. Expected territory, variant, extension, or end of string.
|
38 |
-
# LanguageTagError: The subtag 'p' must be followed by something
|
39 |
-
substrings = string_to_check.split("-")
|
40 |
-
substrings = substrings[:-1] # remove the last one
|
41 |
-
string_to_check = "-".join(substrings)
|
42 |
-
desc = get_lang_description_from_mapping_name(string_to_check)
|
43 |
-
if substrings[-1] == "red":
|
44 |
-
desc = desc + " (reduced)"
|
45 |
-
return desc
|
46 |
-
else:
|
47 |
-
print("*****")
|
48 |
-
print(e)
|
49 |
-
return None
|
50 |
|
51 |
|
52 |
def get_valid_epitran_mappings_list():
|
|
|
7 |
# TODO: reverse transliterate?
|
8 |
|
9 |
|
10 |
+
def get_lang_description_from_mapping_name(string_to_check):
|
11 |
if "generic-Latn" == string_to_check:
|
12 |
return "Generic Latin Script"
|
13 |
|
14 |
if len(string_to_check)<2:
|
15 |
return None
|
16 |
+
|
17 |
+
substrings = string_to_check.split("-")
|
18 |
+
substrings = substrings[:2] # the first two
|
19 |
+
print(substrings)
|
20 |
+
string_to_check = "-".join(substrings)
|
21 |
|
22 |
+
|
23 |
+
|
24 |
+
description = None
|
25 |
+
lang = langcodes.get(string_to_check)
|
26 |
+
if lang:
|
27 |
+
items = []
|
28 |
+
for key, value in lang.describe().items():
|
29 |
+
if key == "language":
|
30 |
+
iso_code = lang.to_alpha3()
|
31 |
+
value = f"[{value}](https://iso639-3.sil.org/code/{iso_code})"
|
32 |
+
items.append(f"{key}: {value}")
|
33 |
+
|
34 |
+
|
35 |
+
description = ", ".join(items)
|
36 |
+
if substrings[-1] == "red":
|
37 |
+
description = description + " (reduced)"
|
38 |
+
return description
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
|
42 |
def get_valid_epitran_mappings_list():
|