Skip to content

Commit 9014781

Browse files
authored
Merge pull request #62 from NSoiffer/GUIAddCountrySupportForLanguages
Update MathCATPreferences.py to support language variants
2 parents d37adee + 6915eb3 commit 9014781

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

addon/globalPlugins/MathCAT/MathCATPreferences.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,28 @@ def GetLanguages(self):
251251
self.m_choiceLanguage.Clear()
252252
self.m_choiceLanguage.Append(_("Use Voice's Language") + " (Auto)")
253253
#populate the available language names in the dialog
254-
for f in os.listdir(UserInterface.path_to_languages_folder()):
255-
if os.path.isdir(UserInterface.path_to_languages_folder()+"\\"+f):
256-
if languages_dict.get(f, 'missing') == 'missing':
257-
self.m_choiceLanguage.Append(f + " (" + f + ")")
258-
else:
259-
self.m_choiceLanguage.Append(languages_dict[f] + " (" + f + ")")
254+
#the implemented languages are in folders named using the relevant ISO 639-1 code https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
255+
for language in os.listdir(UserInterface.path_to_languages_folder()):
256+
if os.path.isdir(os.path.join(UserInterface.path_to_languages_folder(),language)):
257+
path_to_language_folder = os.path.join(UserInterface.path_to_languages_folder(), language)
258+
#only add this language if there is a xxx_Rules.yaml file
259+
files = glob.glob(os.path.join(path_to_language_folder,"*_Rules.yaml"))
260+
if files:
261+
#add to the listbox the text for this language together with the language code
262+
if languages_dict.get(language, 'missing') != 'missing':
263+
self.m_choiceLanguage.Append(languages_dict[language] + " (" + language + ")")
264+
else:
265+
self.m_choiceLanguage.Append(language + " (" + language + ")")
266+
#the country variants are in folders named using ISO 3166-1 alpha-2 codes https://en.wikipedia.org/wiki/ISO_3166-2
267+
#check if there are countries in the language folder
268+
for country in os.listdir(path_to_language_folder):
269+
if os.path.isdir(os.path.join(path_to_language_folder, country)):
270+
if country != "SharedRules":
271+
#add to the listbox the text for this language together with the language and country codes
272+
if languages_dict.get(language, 'missing') != 'missing':
273+
self.m_choiceLanguage.Append(languages_dict[language] + " (" + language + "-" + country + ")")
274+
else:
275+
self.m_choiceLanguage.Append(language + " (" + language + "-" + country + ")")
260276

261277
def GetLanguageCode(self):
262278
lang_selection = self.m_choiceLanguage.GetStringSelection()

0 commit comments

Comments
 (0)