GUI2: cleaned up utils::string_map usage when appropriate

This commit is contained in:
Charles Dang 2016-09-22 19:41:50 +11:00
parent c1ca0e360e
commit 23106671f6
7 changed files with 34 additions and 58 deletions

View file

@ -95,10 +95,7 @@ twindow* build(CVideo& video, const twindow_builder::tresolution* definition)
{
if(window->has_linked_size_group(lg.id)) {
utils::string_map symbols;
symbols["id"] = lg.id;
t_string msg = vgettext(
"Linked '$id' group has multiple definitions.", symbols);
t_string msg = vgettext("Linked '$id' group has multiple definitions.", {{"id", lg.id}});
FAIL(msg);
}

View file

@ -206,9 +206,7 @@ game_info::game_info(const config& game, const config& game_config, const std::v
r.addon_id = addon["id"].str();
r.outcome = NEED_DOWNLOAD;
utils::string_map symbols;
symbols["id"] = addon["id"].str();
r.message = vgettext("Missing addon: $id", symbols);
r.message = vgettext("Missing addon: $id", {{"id", addon["id"].str()}});
required_addons.push_back(r);
if(addons_outcome == SATISFIED) {
addons_outcome = NEED_DOWNLOAD;
@ -220,8 +218,6 @@ game_info::game_info(const config& game, const config& game_config, const std::v
std::string turn = game["turn"];
if(!game["mp_era"].empty()) {
const config& era_cfg = game_config.find_child("era", "id", game["mp_era"]);
utils::string_map symbols;
symbols["era_id"] = game["mp_era"];
if(era_cfg) {
era = era_cfg["name"].str();
era_short = era_cfg["short_name"].str();
@ -233,7 +229,7 @@ game_info::game_info(const config& game, const config& game_config, const std::v
addons_outcome = std::max(addons_outcome, result); // Elevate to most severe error level encountered so far
} else {
have_era = !game["require_era"].to_bool(true);
era = vgettext("Unknown era: $era_id", symbols);
era = vgettext("Unknown era: $era_id", {{"era_id", game["mp_era"].str()}});
era_short = "?" + make_short_name(era);
verified = false;
}
@ -334,9 +330,7 @@ game_info::game_info(const config& game, const config& game_config, const std::v
addons_outcome = std::max(addons_outcome, result); // Elevate to most severe error level encountered so far
}
} else {
utils::string_map symbols;
symbols["scenario_id"] = game["mp_scenario"];
scenario = vgettext("Unknown scenario: $scenario_id", symbols);
scenario = vgettext("Unknown scenario: $scenario_id", {{"scenario_id", game["mp_scenario"].str()}});
info_stream << scenario;
verified = false;
}
@ -367,9 +361,7 @@ game_info::game_info(const config& game, const config& game_config, const std::v
addons_outcome = std::max(addons_outcome, result); // Elevate to most severe error level encountered so far
//}
} else {
utils::string_map symbols;
symbols["campaign_id"] = game["mp_campaign"];
scenario = vgettext("Unknown campaign: $campaign_id", symbols);
scenario = vgettext("Unknown campaign: $campaign_id", {{"campaign_id", game["mp_campaign"].str()}});
info_stream << scenario;
verified = false;
}
@ -449,11 +441,12 @@ game_info::ADDON_REQ game_info::check_addon_version_compatibility(const config&
if(local_min_ver > remote_ver) {
r.outcome = CANNOT_SATISFY;
utils::string_map symbols;
symbols["addon"] = r.addon_id; // TODO: Figure out how to ask the add-on manager for the user-friendly name of this add-on.
symbols["host_ver"] = remote_ver.str();
symbols["local_ver"] = local_ver.str();
r.message = vgettext("The host's version of <i>$addon</i> is incompatible. They have version <b>$host_ver</b> while you have version <b>$local_ver</b>.", symbols);
// TODO: Figure out how to ask the add-on manager for the user-friendly name of this add-on.
r.message = vgettext("The host's version of <i>$addon</i> is incompatible. They have version <b>$host_ver</b> while you have version <b>$local_ver</b>.", {
{"addon", r.addon_id},
{"host_ver", remote_ver.str()},
{"local_ver", local_ver.str()}
});
required_addons.push_back(r);
return r.outcome;
@ -463,11 +456,12 @@ game_info::ADDON_REQ game_info::check_addon_version_compatibility(const config&
if(remote_min_ver > local_ver) {
r.outcome = NEED_DOWNLOAD;
utils::string_map symbols;
symbols["addon"] = r.addon_id; // TODO: Figure out how to ask the add-on manager for the user-friendly name of this add-on.
symbols["host_ver"] = remote_ver.str();
symbols["local_ver"] = local_ver.str();
r.message = vgettext("Your version of <i>$addon</i> is incompatible. You have version <b>$local_ver</b> while the host has version <b>$host_ver</b>.", symbols);
// TODO: Figure out how to ask the add-on manager for the user-friendly name of this add-on.
r.message = vgettext("Your version of <i>$addon</i> is incompatible. You have version <b>$local_ver</b> while the host has version <b>$host_ver</b>.", {
{"addon", r.addon_id},
{"host_ver", remote_ver.str()},
{"local_ver", local_ver.str()}
});
required_addons.push_back(r);
return r.outcome;

View file

@ -424,13 +424,11 @@ void tlobby_main::update_gamelist_diff()
void tlobby_main::update_gamelist_header()
{
#ifndef GUI2_EXPERIMENTAL_LISTBOX
utils::string_map symbols;
symbols["num_shown"]
= std::to_string(lobby_info_.games_filtered().size());
symbols["num_total"]
= std::to_string(lobby_info_.games().size());
std::string games_string
= VGETTEXT("Games: showing $num_shown out of $num_total", symbols);
const std::string games_string = vgettext("Games: showing $num_shown out of $num_total", {
{"num_shown", std::to_string(lobby_info_.games_filtered().size())},
{"num_total", std::to_string(lobby_info_.games().size())}
});
find_widget<tlabel>(gamelistbox_, "map", false).set_label(games_string);
#endif
}

View file

@ -838,12 +838,11 @@ void tpreferences::add_hotkey_callback(tlistbox& hotkeys)
}
if(oldhk) {
utils::string_map symbols;
symbols["hotkey_sequence"] = oldhk->get_name();
symbols["old_hotkey_action"] = hotkey::get_description(oldhk->get_command());
symbols["new_hotkey_action"] = hotkey::get_description(newhk->get_command());
std::string text = vgettext("“<b>$hotkey_sequence|</b>” is in use by “<b>$old_hotkey_action|</b>”.\nDo you wish to reassign it to “<b>$new_hotkey_action|</b>”?", symbols);
const std::string text = vgettext("“<b>$hotkey_sequence|</b>” is in use by “<b>$old_hotkey_action|</b>”.\nDo you wish to reassign it to “<b>$new_hotkey_action|</b>”?", {
{"hotkey_sequence", oldhk->get_name()},
{"old_hotkey_action", hotkey::get_description(oldhk->get_command())},
{"new_hotkey_action", hotkey::get_description(newhk->get_command())}
});
const int res = gui2::show_message(video, _("Reassign Hotkey"), text, gui2::tmessage::yes_no_buttons, true);
if(res != gui2::twindow::OK) {

View file

@ -122,11 +122,7 @@ std::string encode_text_alignment(const PangoAlignment alignment)
t_string missing_widget(const std::string& id)
{
utils::string_map symbols;
symbols["id"] = id;
return t_string(
vgettext("Mandatory widget '$id' hasn't been defined.", symbols));
return t_string(vgettext("Mandatory widget '$id' hasn't been defined.", {{"id", id}}));
}
void get_screen_size_variables(game_logic::map_formula_callable& variable)

View file

@ -451,12 +451,10 @@ void tgui_definition::load_widget_definitions(
return;
}
utils::string_map symbols;
symbols["definition"] = definition_type;
symbols["id"] = "default";
t_string msg(vgettext("Widget definition '$definition' "
"doesn't contain the definition for '$id'.",
symbols));
t_string msg(vgettext("Widget definition '$definition' doesn't contain the definition for '$id'.", {
{"definition", definition_type},
{"id", "default"}
}));
VALIDATE(control_definition[definition_type].find("default")
!= control_definition[definition_type].end(),

View file

@ -165,10 +165,7 @@ void tunit_preview_pane::set_displayed_type(const unit_type& type)
}
if(label_level_) {
utils::string_map symbols;
symbols["lvl"] = std::to_string(type.level());
std::string l_str = vgettext("Lvl $lvl", symbols);
std::string l_str = vgettext("Lvl $lvl", {{"lvl", std::to_string(type.level())}});
label_level_->set_label("<b>" + l_str + "</b>");
label_level_->set_use_markup(true);
@ -292,10 +289,7 @@ void tunit_preview_pane::set_displayed_unit(const unit& u)
}
if(label_level_) {
utils::string_map symbols;
symbols["lvl"] = std::to_string(u.level());
std::string l_str = vgettext("Lvl $lvl", symbols);
std::string l_str = vgettext("Lvl $lvl", {{"lvl", std::to_string(u.level())}});
label_level_->set_label("<b>" + l_str + "</b>");
label_level_->set_use_markup(true);