Skip to content

Commit

Permalink
gui2/title_screen: Fix edge case with "c.UTF-8" on the Language button
Browse files Browse the repository at this point in the history
This also refactors boost_name out of a lambda expression so we don't
create the same string a dozen times.
  • Loading branch information
irydacea committed Oct 15, 2021
1 parent 5bcf506 commit ce08eda
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/gui/dialogs/title_screen.cpp
Expand Up @@ -316,19 +316,27 @@ void title_screen::pre_show(window& win)

if(auto* lang_button = find_widget<button>(&win, "language", false, false); lang_button) {
const auto& locale = translation::get_effective_locale_info();
// Just assume everything is UTF-8 (it should be as long as we're called Wesnoth)
// and strip the charset from the Boost locale identifier.
const auto& boost_name = boost::algorithm::erase_first_copy(locale.name(), ".UTF-8");
const auto& langs = get_languages(true);

auto lang_def = std::find_if(langs.begin(), langs.end(), [&](language_def const& lang) {
// Just assume everything is UTF-8 (it should be as long as we're called Wesnoth)
// and strip the charset from the Boost locale identifier.
const auto& boost_name = boost::algorithm::erase_first_copy(locale.name(), ".UTF-8");
// std::cerr << lang.localename << '/' << boost_name << '\n';
return lang.localename == boost_name;
});

// If somehow the locale doesn't match a known translation, use the
// locale identifier as a last resort
lang_button->set_label(lang_def != langs.end() ? lang_def->language.str() : locale.name());
if(lang_def != langs.end()) {
lang_button->set_label(lang_def->language.str());
} else if(boost_name == "c" || boost_name == "C") {
// HACK: sometimes System Default doesn't match anything on the list. If you fork
// Wesnoth and change the neutral language to something other than US English, you
// want to change this too.
lang_button->set_label("English (US)");
} else {
// If somehow the locale doesn't match a known translation, use the
// locale identifier as a last resort
lang_button->set_label(boost_name);
}
}

//
Expand Down

0 comments on commit ce08eda

Please sign in to comment.