From f53f0c3ce8a8c544aaa801224865633a5e4e89e3 Mon Sep 17 00:00:00 2001 From: GunChleoc Date: Wed, 15 Feb 2017 09:38:45 +0000 Subject: [PATCH 1/2] Fixed translation markup in unit::describe_builtin_effect() Replaced hard-coded word order and N_ for all strings in unit::describe_builtin_effect() with vgettext/vngettext using placeholders. --- src/units/unit.cpp | 77 ++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/src/units/unit.cpp b/src/units/unit.cpp index c2ba4d6b4ca7..283b91434ef4 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -1745,54 +1745,45 @@ std::string unit::describe_builtin_effect(std::string apply_to, const config& ef } } else if(apply_to == "hitpoints") { const std::string &increase_total = effect["increase_total"]; - if(!increase_total.empty()) { - return utils::print_modifier(increase_total) + " " + - t_string(N_("HP"), "wesnoth"); - } - } else if(apply_to == "movement") { - const std::string &increase = effect["increase"]; - - if(!increase.empty()) { - int n = std::stoi(increase); - return utils::print_modifier(increase) + " " + - _n("move", "moves", n); - } - } else if(apply_to == "vision") { - const std::string &increase = effect["increase"]; - - if(!increase.empty()) { - return utils::print_modifier(increase) + " " + t_string(N_("vision"), "wesnoth"); + return vgettext( + "wesnoth", + "$number_or_percent HP", + utils::string_map({{"number_or_percent", utils::print_modifier(increase_total)}})); } - } else if(apply_to == "jamming") { - const std::string &increase = effect["increase"]; - - if(!increase.empty()) { - return utils::print_modifier(increase) + " " + t_string(N_("jamming"), "wesnoth"); - } - } else if(apply_to == "max_experience") { + } else { const std::string &increase = effect["increase"]; - if(!increase.empty()) { - return utils::print_modifier(increase) + " " + - t_string(N_("XP to advance"), "wesnoth"); - } - } else if (apply_to == "max_attacks") { - const std::string &increase = effect["increase"]; - - std::string description = utils::print_modifier(increase) + " "; - const char* const singular = N_("attack per turn"); - const char* const plural = N_("attacks per turn"); - if (increase[increase.size()-1] == '%' || std::abs(std::stoi(increase)) != 1) { - description += t_string(plural, "wesnoth"); - } else { - description += t_string(singular, "wesnoth"); + if(apply_to == "movement") { + return vngettext( + "$number_or_percent move", + "$number_or_percent moves", + std::stoi(increase), + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); + } else if(apply_to == "vision") { + return vgettext( + "$number_or_percent vision", + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); + } else if(apply_to == "jamming") { + return vgettext( + "$number_or_percent jamming", + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); + } else if(apply_to == "max_experience") { + return vgettext( + "$number_or_percent XP to advance", + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); + } else if (apply_to == "max_attacks") { + return vngettext( + "$number_or_percent attack per turn", + "$number_or_percent attacks per turn", + std::stoi(increase), + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); + } else if (apply_to == "recall_cost") { + return vgettext( + "$number_or_percent cost to recall", + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); + } } - return description; - } else if (apply_to == "recall_cost") { - const std::string &increase = effect["increase"]; - return utils::print_modifier(increase) + " " + - t_string(N_("cost to recall"), "wesnoth"); } return ""; } From 1af6ed227b3428bdc4a59e07055552b97bd2fa19 Mon Sep 17 00:00:00 2001 From: GunChleoc Date: Thu, 16 Feb 2017 19:30:52 +0000 Subject: [PATCH 2/2] Use early return ... for less indentation. --- src/units/unit.cpp | 57 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/units/unit.cpp b/src/units/unit.cpp index 283b91434ef4..f67471ed9142 100644 --- a/src/units/unit.cpp +++ b/src/units/unit.cpp @@ -1753,36 +1753,37 @@ std::string unit::describe_builtin_effect(std::string apply_to, const config& ef } } else { const std::string &increase = effect["increase"]; - if(!increase.empty()) { - if(apply_to == "movement") { - return vngettext( - "$number_or_percent move", - "$number_or_percent moves", - std::stoi(increase), - utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); - } else if(apply_to == "vision") { - return vgettext( - "$number_or_percent vision", - utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); - } else if(apply_to == "jamming") { - return vgettext( - "$number_or_percent jamming", + if(increase.empty()) { + return ""; + } + if(apply_to == "movement") { + return vngettext( + "$number_or_percent move", + "$number_or_percent moves", + std::stoi(increase), + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); + } else if(apply_to == "vision") { + return vgettext( + "$number_or_percent vision", + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); + } else if(apply_to == "jamming") { + return vgettext( + "$number_or_percent jamming", + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); + } else if(apply_to == "max_experience") { + return vgettext( + "$number_or_percent XP to advance", utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); - } else if(apply_to == "max_experience") { - return vgettext( - "$number_or_percent XP to advance", - utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); - } else if (apply_to == "max_attacks") { - return vngettext( - "$number_or_percent attack per turn", - "$number_or_percent attacks per turn", - std::stoi(increase), - utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); - } else if (apply_to == "recall_cost") { - return vgettext( - "$number_or_percent cost to recall", + } else if (apply_to == "max_attacks") { + return vngettext( + "$number_or_percent attack per turn", + "$number_or_percent attacks per turn", + std::stoi(increase), utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); - } + } else if (apply_to == "recall_cost") { + return vgettext( + "$number_or_percent cost to recall", + utils::string_map({{"number_or_percent", utils::print_modifier(increase)}})); } } return "";