mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Merge pull request #1329 from IvanSavenko/translate_game
Translations support - base functionality for main game texts
This commit is contained in:
@@ -106,27 +106,9 @@ std::string InterfaceObjectConfigurable::readText(const JsonNode & config) const
|
||||
if(config.isNull())
|
||||
return "";
|
||||
|
||||
if(config.isNumber())
|
||||
{
|
||||
logGlobal->debug("Reading text from generaltext handler id:%d", config.Integer());
|
||||
return CGI->generaltexth->allTexts[config.Integer()];
|
||||
}
|
||||
|
||||
const std::string delimiter = "/";
|
||||
std::string s = config.String();
|
||||
logGlobal->debug("Reading text from translations by key: %s", s);
|
||||
JsonNode translated = CGI->generaltexth->localizedTexts;
|
||||
for(size_t p = s.find(delimiter); p != std::string::npos; p = s.find(delimiter))
|
||||
{
|
||||
translated = translated[s.substr(0, p)];
|
||||
s.erase(0, p + delimiter.length());
|
||||
}
|
||||
if(s == config.String())
|
||||
{
|
||||
logGlobal->warn("Reading non-translated text: %s", s);
|
||||
return s;
|
||||
}
|
||||
return translated[s].String();
|
||||
return CGI->generaltexth->translate(s);
|
||||
}
|
||||
|
||||
Point InterfaceObjectConfigurable::readPosition(const JsonNode & config) const
|
||||
@@ -211,12 +193,6 @@ std::pair<std::string, std::string> InterfaceObjectConfigurable::readHintText(co
|
||||
std::pair<std::string, std::string> result;
|
||||
if(!config.isNull())
|
||||
{
|
||||
if(config.isNumber())
|
||||
{
|
||||
logGlobal->debug("Reading hint text (zelp) from generaltext handler id:%d", config.Integer());
|
||||
return CGI->generaltexth->zelp[config.Integer()];
|
||||
}
|
||||
|
||||
if(config.getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
{
|
||||
result.first = readText(config["hover"]);
|
||||
@@ -225,8 +201,9 @@ std::pair<std::string, std::string> InterfaceObjectConfigurable::readHintText(co
|
||||
}
|
||||
if(config.getType() == JsonNode::JsonType::DATA_STRING)
|
||||
{
|
||||
logGlobal->debug("Reading non-translated hint: %s", config.String());
|
||||
result.first = result.second = config.String();
|
||||
logGlobal->debug("Reading hint text (help) from generaltext handler:%sd", config.String());
|
||||
result.first = CGI->generaltexth->translate( config.String(), "hover");
|
||||
result.second = CGI->generaltexth->translate( config.String(), "help");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -299,8 +276,8 @@ std::shared_ptr<CToggleButton> InterfaceObjectConfigurable::buildToggleButton(co
|
||||
logGlobal->debug("Building widget CToggleButton");
|
||||
auto position = readPosition(config["position"]);
|
||||
auto image = config["image"].String();
|
||||
auto zelp = readHintText(config["zelp"]);
|
||||
auto button = std::make_shared<CToggleButton>(position, image, zelp);
|
||||
auto help = readHintText(config["help"]);
|
||||
auto button = std::make_shared<CToggleButton>(position, image, help);
|
||||
if(!config["selected"].isNull())
|
||||
button->setSelected(config["selected"].Bool());
|
||||
if(!config["imageOrder"].isNull())
|
||||
@@ -319,8 +296,8 @@ std::shared_ptr<CButton> InterfaceObjectConfigurable::buildButton(const JsonNode
|
||||
logGlobal->debug("Building widget CButton");
|
||||
auto position = readPosition(config["position"]);
|
||||
auto image = config["image"].String();
|
||||
auto zelp = readHintText(config["zelp"]);
|
||||
auto button = std::make_shared<CButton>(position, image, zelp);
|
||||
auto help = readHintText(config["help"]);
|
||||
auto button = std::make_shared<CButton>(position, image, help);
|
||||
if(!config["items"].isNull())
|
||||
{
|
||||
for(const auto & item : config["items"].Vector())
|
||||
|
||||
Reference in New Issue
Block a user