MCPcopy Create free account
hub / github.com/TypesettingTools/Aegisub / PickLanguage

Method PickLanguage

src/aegisublocale.cpp:81–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81std::string AegisubLocale::PickLanguage() {
82 if (active_language.empty()) {
83 wxString os_ui_language = GetTranslations()->GetBestTranslation(AEGISUB_CATALOG);
84 if (!os_ui_language.empty())
85 return from_wx(os_ui_language);
86 }
87
88 wxArrayString langs = GetTranslations()->GetAvailableTranslations(AEGISUB_CATALOG);
89
90 // No translations available, so don't bother asking the user
91 if (langs.empty() && active_language.empty())
92 return "en_US";
93
94 langs.insert(langs.begin(), "en_US");
95
96 // Check if user local language is available, if so, make it first
97 const wxLanguageInfo *info = wxLocale::GetLanguageInfo(wxLocale::GetSystemLanguage());
98 if (info) {
99 auto it = std::find(langs.begin(), langs.end(), info->CanonicalName);
100 if (it != langs.end())
101 std::rotate(langs.begin(), it, it + 1);
102 }
103
104 // Generate names
105 wxArrayString langNames;
106 for (auto const& lang : langs)
107 langNames.push_back(LocalizedLanguageName(lang));
108
109 long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCENTRE;
110 if (!active_language.empty())
111 style |= wxCANCEL;
112
113 wxSingleChoiceDialog dialog(nullptr, "Please choose a language:", "Language", langNames,
114 (void **)nullptr,
115 style);
116 if (dialog.ShowModal() == wxID_OK) {
117 int picked = dialog.GetSelection();
118 auto new_lang = from_wx(langs[picked]);
119 if (new_lang != active_language)
120 return new_lang;
121 }
122
123 return "";
124}

Callers 2

OnInitMethod · 0.80
app_languageClass · 0.80

Calls 8

from_wxFunction · 0.85
GetSystemLanguageFunction · 0.85
rotateFunction · 0.85
LocalizedLanguageNameFunction · 0.85
push_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
ShowModalMethod · 0.45

Tested by

no test coverage detected