cdleong commited on
Commit
31730d4
1 Parent(s): 726b8f4

Rewriting code to not put URLs in dropdown, but yes put in description after selection

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -8,26 +8,19 @@ from collections import defaultdict
8
  # TODO: reverse transliterate?
9
 
10
 
11
-
12
- def get_lang_description_from_mapping_name(string_to_check):
 
13
  if "generic-Latn" == string_to_check:
14
- return "Generic Latin Script"
15
-
16
- if len(string_to_check)<2:
17
- return None
18
-
19
- substrings = string_to_check.split("-")
20
- substrings = substrings[:2] # first two are ISO 639-3 language, and ISO 15924 script
21
- string_to_check = "-".join(substrings)
22
 
23
 
24
 
25
- description = None
26
- lang = langcodes.get(string_to_check)
27
  if lang:
28
  items = []
29
  for key, value in lang.describe().items():
30
- if key == "language":
31
  iso_code = lang.to_alpha3()
32
  value = f"[{value}](https://iso639-3.sil.org/code/{iso_code})"
33
  items.append(f"{key}: {value}")
@@ -38,6 +31,22 @@ def get_lang_description_from_mapping_name(string_to_check):
38
  description = description + " (reduced)"
39
  return description
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  @st.cache
42
  def get_valid_epitran_mappings_list():
43
  map_path = Path(epitran.__path__[0]) / "data" / "map"
@@ -84,10 +93,11 @@ if __name__ == "__main__":
84
  selected_mapping = st.selectbox("Select input language/script:",
85
  valid_epitran_mappings,
86
  index=index_of_desired_default,
87
- format_func=get_lang_description_from_mapping_name)
 
88
 
89
 
90
- description = get_lang_description_from_mapping_name(selected_mapping)
91
  st.write(f"Selected input language/script: {description}")
92
 
93
  st.info("attempting to instantiate epitran transliterator for your language/script")
 
8
  # TODO: reverse transliterate?
9
 
10
 
11
+ @st.cache
12
+ def get_lang_description_from_mapping_name(string_to_check, add_iso_url=False):
13
+ description = None
14
  if "generic-Latn" == string_to_check:
15
+ return "Generic Latin Script text"
 
 
 
 
 
 
 
16
 
17
 
18
 
19
+ lang = get_langcode_lang(string_to_check)
 
20
  if lang:
21
  items = []
22
  for key, value in lang.describe().items():
23
+ if key == "language" and add_iso_url:
24
  iso_code = lang.to_alpha3()
25
  value = f"[{value}](https://iso639-3.sil.org/code/{iso_code})"
26
  items.append(f"{key}: {value}")
 
31
  description = description + " (reduced)"
32
  return description
33
 
34
+
35
+ @st.cache
36
+ def get_langcode_lang_from_mapping_name(string_to_check):
37
+
38
+ if len(string_to_check)<2:
39
+ return None
40
+
41
+ substrings = string_to_check.split("-")
42
+ iso_lang_and_iso_script = substrings[:2] # first two are ISO 639-3 language, and ISO 15924 script
43
+ string_to_check = "-".join(iso_lang_and_iso_script )
44
+ lang = langcodes.get(string_to_check)
45
+ return lang
46
+
47
+
48
+
49
+
50
  @st.cache
51
  def get_valid_epitran_mappings_list():
52
  map_path = Path(epitran.__path__[0]) / "data" / "map"
 
93
  selected_mapping = st.selectbox("Select input language/script:",
94
  valid_epitran_mappings,
95
  index=index_of_desired_default,
96
+ format_func=get_lang_description_from_mapping_name,
97
+ )
98
 
99
 
100
+ description = get_lang_description_from_mapping_name(selected_mapping, add_iso_url=True)
101
  st.write(f"Selected input language/script: {description}")
102
 
103
  st.info("attempting to instantiate epitran transliterator for your language/script")