Deploy format_conjunct_list

This commit is contained in:
Celtic Minstrel 2017-05-22 00:05:33 -04:00
parent 2cc7ec4bde
commit c6bdcb0f53
3 changed files with 33 additions and 90 deletions

View file

@ -176,38 +176,15 @@ void multimenu_button::update_label()
selected.push_back(values_[i]["label"]);
}
if(selected.size() == 0) {
set_label(_("multimenu^None Selected"));
} else if(selected.size() == 1) {
set_label(selected[0]);
} else if(selected.size() == 2) {
const string_map variables {{"first", selected[0]}, {"second", selected[1]}, {"excess", "1"}};
if(max_shown_ == 1) {
set_label(VNGETTEXT("multimenu^$first and 1 other","multimenu^$first and $excess others", 1, variables));
} else {
set_label(VGETTEXT("multimenu^$first and $second", variables));
}
} else if(selected.size() == values_.size()) {
if(selected.size() == values_.size()) {
set_label(_("multimenu^All Selected"));
} else {
const int excess = selected.size() - max_shown_;
if(max_shown_ > 0 && excess > 0) {
selected.resize(max_shown_);
}
std::string first = selected[0];
for(size_t i = 1; i < selected.size() - 1; i++) {
const string_map variables {{"first", first}, {"second", selected[i]}};
first = VGETTEXT("multimenu^$first, $second", variables);
}
if(max_shown_ > 0 && excess > 0) {
const string_map variables {{"first", first}, {"excess", std::to_string(excess + 1)}};
set_label(VNGETTEXT("multimenu^$first and 1 other","$first and $excess others", excess + 1, variables));
} else {
const string_map variables {{"first", first}, {"second", selected.back()}};
set_label(VGETTEXT("multimenu^$first and $second", variables));
if(selected.size() > static_cast<size_t>(max_shown_)) {
const int excess = selected.size() - max_shown_;
selected.resize(max_shown_ + 1);
selected.back() = VNGETTEXT("multimenu excess^1 other", "$excess others", excess, {{"excess", std::to_string(excess)}});
}
set_label(utils::format_conjunct_list(_("multimenu^None Selected"), selected));
}
}

View file

@ -180,13 +180,6 @@ bool attack_type::matches_filter(const config& filter) const
return matches;
}
namespace {
void add_and(std::stringstream &ss) {
if(ss.tellp() > 0)
ss << t_string(N_(" and "), "wesnoth");
}
}
/**
* Modifies *this using the specifications in @a cfg, but only if *this matches
* @a cfg viewed as a filter.
@ -348,101 +341,91 @@ bool attack_type::describe_modification(const config& cfg,std::string* descripti
const std::string& increase_movement = cfg["increase_movement_used"];
const std::string& set_movement = cfg["set_movement_used"];
std::stringstream desc;
std::vector<t_string> desc;
if(!increase_damage.empty()) {
add_and(desc);
desc << VNGETTEXT(
desc.emplace_back(VNGETTEXT(
// TRANSLATORS: Current value for WML code increase_damage, documented in https://wiki.wesnoth.org/EffectWML
"$number_or_percent damage",
"$number_or_percent damage",
std::stoi(increase_damage),
utils::string_map({{"number_or_percent", utils::print_modifier(increase_damage)}}));
{{"number_or_percent", utils::print_modifier(increase_damage)}}));
}
if(!set_damage.empty()) {
add_and(desc);
// TRANSLATORS: Current value for WML code set_damage, documented in https://wiki.wesnoth.org/EffectWML
desc << VNGETTEXT(
desc.emplace_back(VNGETTEXT(
"$number damage",
"$number damage",
std::stoi(set_damage),
utils::string_map({{"number", set_damage}}));
{{"number", set_damage}}));
}
if(!increase_attacks.empty()) {
add_and(desc);
desc << VNGETTEXT(
desc.emplace_back(VNGETTEXT(
// TRANSLATORS: Current value for WML code increase_attacks, documented in https://wiki.wesnoth.org/EffectWML
"$number_or_percent strike",
"$number_or_percent strikes",
std::stoi(increase_attacks),
utils::string_map({{"number_or_percent", utils::print_modifier(increase_attacks)}}));
{{"number_or_percent", utils::print_modifier(increase_attacks)}}));
}
if(!set_attacks.empty()) {
add_and(desc);
desc << VNGETTEXT(
desc.emplace_back(VNGETTEXT(
// TRANSLATORS: Current value for WML code set_attacks, documented in https://wiki.wesnoth.org/EffectWML
"$number strike",
"$number strikes",
std::stoi(set_attacks),
utils::string_map({{"number", set_attacks}}));
{{"number", set_attacks}}));
}
if(!set_accuracy.empty()) {
add_and(desc);
desc << vgettext(
desc.emplace_back(VGETTEXT(
// TRANSLATORS: Current value for WML code set_accuracy, documented in https://wiki.wesnoth.org/EffectWML
"$percent|% accuracy",
utils::string_map({{"percent", set_accuracy}}));
{{"percent", set_accuracy}}));
}
if(!increase_accuracy.empty()) {
add_and(desc);
desc << vgettext(
desc.emplace_back(VGETTEXT(
// TRANSLATORS: Current value for WML code increase_accuracy, documented in https://wiki.wesnoth.org/EffectWML
"$percent|% accuracy",
utils::string_map({{"percent", utils::print_modifier(increase_accuracy)}}));
{{"percent", utils::print_modifier(increase_accuracy)}}));
}
if(!set_parry.empty()) {
add_and(desc);
desc << vgettext(
desc.emplace_back(VGETTEXT(
// TRANSLATORS: Current value for WML code set_parry, documented in https://wiki.wesnoth.org/EffectWML
"$number parry",
utils::string_map({{"number", set_parry}}));
{{"number", set_parry}}));
}
if(!increase_parry.empty()) {
add_and(desc);
desc << vgettext(
desc.emplace_back(VGETTEXT(
// TRANSLATORS: Current value for WML code increase_parry, documented in https://wiki.wesnoth.org/EffectWML
"$number_or_percent parry",
utils::string_map({{"number_or_percent", utils::print_modifier(increase_parry)}}));
{{"number_or_percent", utils::print_modifier(increase_parry)}}));
}
if(!set_movement.empty()) {
add_and(desc);
desc << VNGETTEXT(
desc.emplace_back(VNGETTEXT(
// TRANSLATORS: Current value for WML code set_movement, documented in https://wiki.wesnoth.org/EffectWML
"$number movement point",
"$number movement points",
std::stoi(set_movement),
utils::string_map({{"number", set_movement}}));
{{"number", set_movement}}));
}
if(!increase_movement.empty()) {
add_and(desc);
desc << VNGETTEXT(
desc.emplace_back(VNGETTEXT(
// TRANSLATORS: Current value for WML code increase_movement, documented in https://wiki.wesnoth.org/EffectWML
"$number_or_percent movement point",
"$number_or_percent movement points",
std::stoi(increase_movement),
utils::string_map({{"number_or_percent", utils::print_modifier(increase_movement)}}));
{{"number_or_percent", utils::print_modifier(increase_movement)}}));
}
*description = desc.str();
*description = utils::format_conjunct_list("", desc);
}
return true;

View file

@ -1752,25 +1752,18 @@ const std::set<std::string> unit::builtin_effects {
std::string unit::describe_builtin_effect(std::string apply_to, const config& effect)
{
if(apply_to == "attack") {
std::string attack_names;
bool first_attack = true;
std::vector<t_string> attack_names;
std::string desc;
for(attack_ptr a : attacks_) {
bool affected = a->describe_modification(effect, &desc);
if(affected && desc != "") {
if(first_attack) {
first_attack = false;
} else {
attack_names += t_string(N_(" and "), "wesnoth");
}
attack_names += t_string(a->name(), "wesnoth-units");
attack_names.emplace_back(a->name(), "wesnoth-units");
}
}
if(!attack_names.empty()) {
utils::string_map symbols;
symbols["attack_list"] = attack_names;
symbols["attack_list"] = utils::format_conjunct_list("", attack_names);
symbols["effect_description"] = desc;
return vgettext("$attack_list|: $effect_description", symbols);
}
@ -2249,22 +2242,12 @@ void unit::add_modification(const std::string& mod_type, const config& mod, bool
// Punctuation should be translatable: not all languages use Latin punctuation.
// (However, there maybe is a better way to do it)
if(effects_description.empty() == false && generate_description == true) {
if(generate_description && !effects_description.empty()) {
if(!mod_description.empty()) {
description += "\n";
}
for(auto i = effects_description.begin(); i != effects_description.end(); ++i) {
if(i->empty()) {
continue;
}
description += *i;
if(std::next(i) != effects_description.end()) {
description += t_string(N_(" and "), "wesnoth");
}
}
description += utils::format_conjunct_list("", effects_description);
}
// store trait info