widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #13229
[Merge] lp:~widelands-dev/widelands/bug-1767919-trainingsite-messages into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1767919-trainingsite-messages into lp:widelands.
Commit message:
Fixed translation of trainingsite program names
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1767919 in widelands: "training site messages not translated"
https://bugs.launchpad.net/widelands/+bug/1767919
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1767919-trainingsite-messages/+merge/344813
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1767919-trainingsite-messages into lp:widelands.
=== modified file 'src/logic/map_objects/tribes/productionsite.cc'
--- src/logic/map_objects/tribes/productionsite.cc 2018-04-07 16:59:00 +0000
+++ src/logic/map_objects/tribes/productionsite.cc 2018-04-30 08:00:23 +0000
@@ -35,6 +35,7 @@
#include "graphic/text_constants.h"
#include "logic/editor_game_base.h"
#include "logic/game.h"
+#include "logic/game_data_error.h"
#include "logic/map.h"
#include "logic/map_objects/tribes/carrier.h"
#include "logic/map_objects/tribes/soldier.h"
@@ -93,6 +94,12 @@
const EditorGameBase& egbase)
: BuildingDescr(init_descname, init_type, table, egbase),
out_of_resource_productivity_threshold_(100) {
+ if (msgctxt.empty()) {
+ throw Widelands::GameDataError("Productionsite '%s' has empty Gettext msgctxt", name().c_str());
+ }
+ // Let's convert this only once, it's cheaper
+ const char* msgctxt_char = msgctxt.c_str();
+
i18n::Textdomain td("tribes");
std::unique_ptr<LuaTable> items_table;
@@ -101,7 +108,7 @@
out_of_resource_title_ = _(items_table->get_string("title"));
out_of_resource_heading_ = _(items_table->get_string("heading"));
out_of_resource_message_ =
- pgettext_expr(msgctxt.c_str(), items_table->get_string("message").c_str());
+ pgettext_expr(msgctxt_char, items_table->get_string("message").c_str());
if (items_table->has_key("productivity_threshold")) {
out_of_resource_productivity_threshold_ = items_table->get_int("productivity_threshold");
}
@@ -190,7 +197,7 @@
const std::string program_descname_unlocalized = program_table->get_string("descname");
std::string program_descname = _(program_descname_unlocalized);
if (program_descname == program_descname_unlocalized) {
- program_descname = pgettext_expr(msgctxt.c_str(), program_descname_unlocalized.c_str());
+ program_descname = pgettext_expr(msgctxt_char, program_descname_unlocalized.c_str());
}
programs_[program_name] = std::unique_ptr<ProductionProgram>(new ProductionProgram(
program_name, program_descname, program_table->get_table("actions"), egbase, this));
=== modified file 'src/logic/map_objects/tribes/trainingsite.cc'
--- src/logic/map_objects/tribes/trainingsite.cc 2018-04-07 16:59:00 +0000
+++ src/logic/map_objects/tribes/trainingsite.cc 2018-04-30 08:00:23 +0000
@@ -46,9 +46,10 @@
* /data/tribes/buildings/trainingsites/atlanteans/dungeon/init.lua
*/
TrainingSiteDescr::TrainingSiteDescr(const std::string& init_descname,
+ const std::string& msgctxt,
const LuaTable& table,
const EditorGameBase& egbase)
- : ProductionSiteDescr(init_descname, "", MapObjectType::TRAININGSITE, table, egbase),
+ : ProductionSiteDescr(init_descname, msgctxt, MapObjectType::TRAININGSITE, table, egbase),
num_soldiers_(table.get_int("soldier_capacity")),
max_stall_(table.get_int("trainer_patience")),
=== modified file 'src/logic/map_objects/tribes/trainingsite.h'
--- src/logic/map_objects/tribes/trainingsite.h 2018-04-07 16:59:00 +0000
+++ src/logic/map_objects/tribes/trainingsite.h 2018-04-30 08:00:23 +0000
@@ -34,6 +34,7 @@
class TrainingSiteDescr : public ProductionSiteDescr {
public:
TrainingSiteDescr(const std::string& init_descname,
+ const std::string& msgctxt,
const LuaTable& table,
const EditorGameBase& egbase);
~TrainingSiteDescr() override {
=== modified file 'src/logic/map_objects/tribes/tribes.cc'
--- src/logic/map_objects/tribes/tribes.cc 2018-04-07 16:59:00 +0000
+++ src/logic/map_objects/tribes/tribes.cc 2018-04-30 08:00:23 +0000
@@ -68,8 +68,9 @@
void Tribes::add_trainingsite_type(const LuaTable& table, const EditorGameBase& egbase) {
i18n::Textdomain td("tribes");
+ const std::string msgctxt = table.get_string("msgctxt");
buildings_->add(new TrainingSiteDescr(
- pgettext_expr(table.get_string("msgctxt").c_str(), table.get_string("descname").c_str()),
+ pgettext_expr(msgctxt.c_str(), table.get_string("descname").c_str()), msgctxt,
table, egbase));
}
Follow ups