gui2/title_screen: Give the Language button its label back
This makes the Language button use one of the new title screen button definitions so it has an actual label in addition to its icon. However, it also makes the label dynamic to reflect the current language choice. More specifically, it reflects the current locale's language name, which turns out requires a surprising amount of effort on our part to obtain.
This commit is contained in:
parent
df9f12568e
commit
da7d8c6aed
2 changed files with 21 additions and 1 deletions
|
@ -480,7 +480,7 @@ where
|
|||
horizontal_alignment = "right"
|
||||
[button]
|
||||
id = "language"
|
||||
definition = "action_language"
|
||||
definition = "titlescreen_language"
|
||||
label = _ "Language"
|
||||
tooltip = _ "Change the language"
|
||||
[/button]
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "gui/dialogs/preferences_dialog.hpp"
|
||||
#include "gui/dialogs/screenshot_notification.hpp"
|
||||
#include "gui/dialogs/simple_item_selector.hpp"
|
||||
#include "language.hpp"
|
||||
#include "log.hpp"
|
||||
#include "preferences/game.hpp"
|
||||
//#define DEBUG_TOOLTIP
|
||||
|
@ -59,6 +60,8 @@
|
|||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include <boost/algorithm/string/erase.hpp>
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define ERR_CF LOG_STREAM(err, log_config)
|
||||
#define WRN_CF LOG_STREAM(warn, log_config)
|
||||
|
@ -311,6 +314,23 @@ 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();
|
||||
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());
|
||||
}
|
||||
|
||||
//
|
||||
// Preferences
|
||||
//
|
||||
|
|
Loading…
Add table
Reference in a new issue