1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Fixed localization validation

This commit is contained in:
Ivan Savenko 2023-02-12 19:50:55 +02:00
parent ad87735d8d
commit 6643408cdd
3 changed files with 15 additions and 4 deletions

View File

@ -8,7 +8,7 @@
"localizable" : {
"type":"object",
"additionalProperties" : false,
"required" : [ "name", "description", "modType" ],
"required" : [ "name", "description" ],
"properties":{
"name": {
"type":"string",

View File

@ -418,6 +418,17 @@ void CGeneralTextHandler::registerStringOverride(const std::string & modContext,
bool CGeneralTextHandler::validateTranslation(const std::string & language, const std::string & modContext, const JsonNode & config) const
{
auto escapeString = [](std::string input)
{
boost::replace_all(input, "\\", "\\\\");
boost::replace_all(input, "\n", "\\n");
boost::replace_all(input, "\r", "\\r");
boost::replace_all(input, "\t", "\\t");
boost::replace_all(input, "\"", "\\\"");
return input;
};
bool allPresent = true;
for (auto const & string : stringsLocalizations)
@ -440,7 +451,7 @@ bool CGeneralTextHandler::validateTranslation(const std::string & language, cons
else
currentText = string.second.overrideValue;
logMod->warn(R"( "%s" : "%s",)", string.first, currentText);
logMod->warn(R"( "%s" : "%s",)", string.first, escapeString(currentText));
allPresent = false;
}
@ -454,7 +465,7 @@ bool CGeneralTextHandler::validateTranslation(const std::string & language, cons
if (allFound)
logMod->warn("Translation into language '%s' in mod '%s' has unused lines:", language, modContext);
logMod->warn(R"( "%s" : "%s",)", string.first, string.second.String());
logMod->warn(R"( "%s" : "%s",)", string.first, escapeString(string.second.String()));
allFound = false;
}

View File

@ -1148,7 +1148,7 @@ bool CModHandler::validateTranslations(TModID modName) const
void CModHandler::loadTranslation(TModID modName)
{
auto & mod = allMods[modName];
auto const & mod = allMods[modName];
std::string preferredLanguage = VLC->generaltexth->getPreferredLanguage();
std::string modBaseLanguage = allMods[modName].baseLanguage;