2
0

CGeneralTextHandler.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*
  2. * CGeneralTextHandler.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CGeneralTextHandler.h"
  12. #include "filesystem/Filesystem.h"
  13. #include "CConfigHandler.h"
  14. #include "CModHandler.h"
  15. #include "mapObjects/CQuest.h"
  16. #include "VCMI_Lib.h"
  17. #include "Languages.h"
  18. #include "TextOperations.h"
  19. VCMI_LIB_NAMESPACE_BEGIN
  20. /// Detects language and encoding of H3 text files based on matching against pregenerated footprints of H3 file
  21. void CGeneralTextHandler::detectInstallParameters()
  22. {
  23. using LanguageFootprint = std::array<double, 16>;
  24. static const std::array<LanguageFootprint, 7> knownFootprints =
  25. { {
  26. { { 0.1602, 0.0000, 0.0357, 0.0054, 0.0038, 0.0017, 0.0077, 0.0214, 0.0000, 0.0000, 0.1264, 0.1947, 0.2012, 0.1406, 0.0480, 0.0532 } },
  27. { { 0.0559, 0.0000, 0.1983, 0.0051, 0.0222, 0.0183, 0.4596, 0.2405, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000 } },
  28. { { 0.0493, 0.0000, 0.1926, 0.0047, 0.0230, 0.0121, 0.4133, 0.2780, 0.0002, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0259, 0.0008 } },
  29. { { 0.0534, 0.0000, 0.1705, 0.0047, 0.0418, 0.0208, 0.4775, 0.2191, 0.0001, 0.0000, 0.0000, 0.0000, 0.0000, 0.0005, 0.0036, 0.0080 } },
  30. { { 0.0534, 0.0000, 0.1701, 0.0067, 0.0157, 0.0133, 0.4328, 0.2540, 0.0001, 0.0043, 0.0000, 0.0244, 0.0000, 0.0000, 0.0181, 0.0071 } },
  31. { { 0.0548, 0.0000, 0.1744, 0.0061, 0.0031, 0.0009, 0.0046, 0.0136, 0.0000, 0.0004, 0.0000, 0.0000, 0.0227, 0.0061, 0.4882, 0.2252 } },
  32. { { 0.0559, 0.0000, 0.1807, 0.0059, 0.0036, 0.0013, 0.0046, 0.0134, 0.0000, 0.0004, 0.0000, 0.0487, 0.0209, 0.0060, 0.4615, 0.1972 } },
  33. } };
  34. static const std::array<std::string, 7> knownLanguages =
  35. { {
  36. "chinese",
  37. "english",
  38. "french",
  39. "german",
  40. "polish",
  41. "russian",
  42. "ukrainian"
  43. } };
  44. // load file that will be used for footprint generation
  45. // this is one of the most text-heavy files in game and consists solely from translated texts
  46. auto resource = CResourceHandler::get("core")->load(ResourceID("DATA/GENRLTXT.TXT", EResType::TEXT));
  47. std::array<size_t, 256> charCount{};
  48. std::array<double, 16> footprint{};
  49. std::array<double, 6> deviations{};
  50. auto data = resource->readAll();
  51. // compute how often each character occurs in input file
  52. for (si64 i = 0; i < data.second; ++i)
  53. charCount[data.first[i]] += 1;
  54. // and convert computed data into weights
  55. // to reduce amount of data, group footprint data into 16-char blocks.
  56. // While this will reduce precision, it should not affect output
  57. // since we expect only tiny differences compared to reference footprints
  58. for (size_t i = 0; i < 256; ++i)
  59. footprint[i/16] += static_cast<double>(charCount[i]) / data.second;
  60. logGlobal->debug("Language footprint: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
  61. footprint[0], footprint[1], footprint[2], footprint[3], footprint[4], footprint[5], footprint[6], footprint[7],
  62. footprint[8], footprint[9], footprint[10], footprint[11], footprint[12], footprint[13], footprint[14], footprint[15]
  63. );
  64. for (size_t i = 0; i < deviations.size(); ++i)
  65. {
  66. for (size_t j = 0; j < footprint.size(); ++j)
  67. deviations[i] += std::abs((footprint[j] - knownFootprints[i][j]));
  68. }
  69. size_t bestIndex = boost::range::min_element(deviations) - deviations.begin();
  70. for (size_t i = 0; i < deviations.size(); ++i)
  71. logGlobal->debug("Comparing to %s: %f", knownLanguages[i], deviations[i]);
  72. Settings language = settings.write["session"]["language"];
  73. language->String() = knownLanguages[bestIndex];
  74. Settings confidence = settings.write["session"]["languageDeviation"];
  75. confidence->Float() = deviations[bestIndex];
  76. Settings encoding = settings.write["session"]["encoding"];
  77. encoding->String() = Languages::getLanguageOptions(knownLanguages[bestIndex]).encoding;
  78. }
  79. //Helper for string -> float conversion
  80. class LocaleWithComma: public std::numpunct<char>
  81. {
  82. protected:
  83. char do_decimal_point() const override
  84. {
  85. return ',';
  86. }
  87. };
  88. CLegacyConfigParser::CLegacyConfigParser(std::string URI)
  89. {
  90. ResourceID resource(URI, EResType::TEXT);
  91. auto input = CResourceHandler::get()->load(resource);
  92. std::string modName = VLC->modh->findResourceOrigin(resource);
  93. std::string language = VLC->modh->getModLanguage(modName);
  94. fileEncoding = Languages::getLanguageOptions(language).encoding;
  95. data.reset(new char[input->getSize()]);
  96. input->read(reinterpret_cast<uint8_t*>(data.get()), input->getSize());
  97. curr = data.get();
  98. end = curr + input->getSize();
  99. }
  100. std::string CLegacyConfigParser::extractQuotedPart()
  101. {
  102. assert(*curr == '\"');
  103. curr++; // skip quote
  104. char * begin = curr;
  105. while (curr != end && *curr != '\"' && *curr != '\t')
  106. curr++;
  107. return std::string(begin, curr++); //increment curr to close quote
  108. }
  109. std::string CLegacyConfigParser::extractQuotedString()
  110. {
  111. assert(*curr == '\"');
  112. std::string ret;
  113. while (true)
  114. {
  115. ret += extractQuotedPart();
  116. // double quote - add it to string and continue quoted part
  117. if (curr < end && *curr == '\"')
  118. {
  119. ret += '\"';
  120. }
  121. //extract normal part
  122. else if(curr < end && *curr != '\t' && *curr != '\r')
  123. {
  124. char * begin = curr;
  125. while (curr < end && *curr != '\t' && *curr != '\r' && *curr != '\"')//find end of string or next quoted part start
  126. curr++;
  127. ret += std::string(begin, curr);
  128. if(curr>=end || *curr != '\"')
  129. return ret;
  130. }
  131. else // end of string
  132. return ret;
  133. }
  134. }
  135. std::string CLegacyConfigParser::extractNormalString()
  136. {
  137. char * begin = curr;
  138. while (curr < end && *curr != '\t' && *curr != '\r')//find end of string
  139. curr++;
  140. return std::string(begin, curr);
  141. }
  142. std::string CLegacyConfigParser::readRawString()
  143. {
  144. if (curr >= end || *curr == '\n')
  145. return "";
  146. std::string ret;
  147. if (*curr == '\"')
  148. ret = extractQuotedString();// quoted text - find closing quote
  149. else
  150. ret = extractNormalString();//string without quotes - copy till \t or \r
  151. curr++;
  152. return ret;
  153. }
  154. std::string CLegacyConfigParser::readString()
  155. {
  156. // do not convert strings that are already in ASCII - this will only slow down loading process
  157. std::string str = readRawString();
  158. if (TextOperations::isValidASCII(str))
  159. return str;
  160. return TextOperations::toUnicode(str, fileEncoding);
  161. }
  162. float CLegacyConfigParser::readNumber()
  163. {
  164. std::string input = readRawString();
  165. std::istringstream stream(input);
  166. if(input.find(',') != std::string::npos) // code to handle conversion with comma as decimal separator
  167. stream.imbue(std::locale(std::locale(), new LocaleWithComma()));
  168. float result;
  169. if ( !(stream >> result) )
  170. return 0;
  171. return result;
  172. }
  173. bool CLegacyConfigParser::isNextEntryEmpty() const
  174. {
  175. char * nextSymbol = curr;
  176. while (nextSymbol < end && *nextSymbol == ' ')
  177. nextSymbol++; //find next meaningfull symbol
  178. return nextSymbol >= end || *nextSymbol == '\n' || *nextSymbol == '\r' || *nextSymbol == '\t';
  179. }
  180. bool CLegacyConfigParser::endLine()
  181. {
  182. while (curr < end && *curr != '\n')
  183. readString();
  184. curr++;
  185. return curr < end;
  186. }
  187. void CGeneralTextHandler::readToVector(std::string const & sourceID, std::string const & sourceName)
  188. {
  189. CLegacyConfigParser parser(sourceName);
  190. size_t index = 0;
  191. do
  192. {
  193. registerString( "core", {sourceID, index}, parser.readString());
  194. index += 1;
  195. }
  196. while (parser.endLine());
  197. }
  198. const std::string & CGeneralTextHandler::deserialize(const TextIdentifier & identifier) const
  199. {
  200. if(stringsLocalizations.count(identifier.get()) == 0)
  201. {
  202. logGlobal->error("Unable to find localization for string '%s'", identifier.get());
  203. return identifier.get();
  204. }
  205. auto const & entry = stringsLocalizations.at(identifier.get());
  206. if (!entry.overrideValue.empty())
  207. return entry.overrideValue;
  208. return entry.baseValue;
  209. }
  210. void CGeneralTextHandler::registerString(const std::string & modContext, const TextIdentifier & UID, const std::string & localized)
  211. {
  212. assert(!modContext.empty());
  213. assert(!getModLanguage(modContext).empty());
  214. assert(UID.get().find("..") == std::string::npos); // invalid identifier - there is section that was evaluated to empty string
  215. //assert(stringsLocalizations.count(UID.get()) == 0); // registering already registered string?
  216. if(stringsLocalizations.count(UID.get()) > 0)
  217. {
  218. auto & value = stringsLocalizations[UID.get()];
  219. if(value.baseLanguage.empty())
  220. {
  221. value.baseLanguage = getModLanguage(modContext);
  222. value.baseValue = localized;
  223. }
  224. else
  225. {
  226. if(value.baseValue != localized)
  227. logMod->warn("Duplicate registered string '%s' found! Old value: '%s', new value: '%s'", UID.get(), value.baseValue, localized);
  228. }
  229. }
  230. else
  231. {
  232. StringState result;
  233. result.baseLanguage = getModLanguage(modContext);
  234. result.baseValue = localized;
  235. result.modContext = modContext;
  236. stringsLocalizations[UID.get()] = result;
  237. }
  238. }
  239. void CGeneralTextHandler::registerStringOverride(const std::string & modContext, const std::string & language, const TextIdentifier & UID, const std::string & localized)
  240. {
  241. assert(!modContext.empty());
  242. assert(!language.empty());
  243. // NOTE: implicitly creates entry, intended - strings added by vcmi (and potential UI mods) are not registered anywhere at the moment
  244. auto & entry = stringsLocalizations[UID.get()];
  245. entry.overrideLanguage = language;
  246. entry.overrideValue = localized;
  247. if (entry.modContext.empty())
  248. entry.modContext = modContext;
  249. }
  250. bool CGeneralTextHandler::validateTranslation(const std::string & language, const std::string & modContext, const JsonNode & config) const
  251. {
  252. bool allPresent = true;
  253. for (auto const & string : stringsLocalizations)
  254. {
  255. if (string.second.modContext != modContext)
  256. continue;
  257. if (string.second.baseLanguage == language && !string.second.baseValue.empty())
  258. continue;
  259. if (config.Struct().count(string.first) > 0)
  260. continue;
  261. if (allPresent)
  262. logMod->warn("Translation into language '%s' in mod '%s' is incomplete! Missing lines:", language, modContext);
  263. std::string currentText;
  264. if (string.second.overrideValue.empty())
  265. currentText = string.second.baseValue;
  266. else
  267. currentText = string.second.overrideValue;
  268. logMod->warn(R"( "%s" : "%s",)", string.first, TextOperations::escapeString(currentText));
  269. allPresent = false;
  270. }
  271. bool allFound = true;
  272. for (auto const & string : config.Struct())
  273. {
  274. if (stringsLocalizations.count(string.first) > 0)
  275. continue;
  276. if (allFound)
  277. logMod->warn("Translation into language '%s' in mod '%s' has unused lines:", language, modContext);
  278. logMod->warn(R"( "%s" : "%s",)", string.first, TextOperations::escapeString(string.second.String()));
  279. allFound = false;
  280. }
  281. return allPresent && allFound;
  282. }
  283. void CGeneralTextHandler::loadTranslationOverrides(const std::string & language, const std::string & modContext, const JsonNode & config)
  284. {
  285. for ( auto const & node : config.Struct())
  286. registerStringOverride(modContext, language, node.first, node.second.String());
  287. }
  288. CGeneralTextHandler::CGeneralTextHandler():
  289. victoryConditions(*this, "core.vcdesc" ),
  290. lossCondtions (*this, "core.lcdesc" ),
  291. colors (*this, "core.plcolors" ),
  292. tcommands (*this, "core.tcommand" ),
  293. hcommands (*this, "core.hallinfo" ),
  294. fcommands (*this, "core.castinfo" ),
  295. advobtxt (*this, "core.advevent" ),
  296. restypes (*this, "core.restypes" ),
  297. randsign (*this, "core.randsign" ),
  298. overview (*this, "core.overview" ),
  299. arraytxt (*this, "core.arraytxt" ),
  300. primarySkillNames(*this, "core.priskill" ),
  301. jktexts (*this, "core.jktext" ),
  302. tavernInfo (*this, "core.tvrninfo" ),
  303. tavernRumors (*this, "core.randtvrn" ),
  304. turnDurations (*this, "core.turndur" ),
  305. heroscrn (*this, "core.heroscrn" ),
  306. tentColors (*this, "core.tentcolr" ),
  307. levels (*this, "core.skilllev" ),
  308. zelp (*this, "core.help" ),
  309. allTexts (*this, "core.genrltxt" ),
  310. // pseudo-array, that don't have H3 file with same name
  311. seerEmpty (*this, "core.seerhut.empty" ),
  312. seerNames (*this, "core.seerhut.names" ),
  313. capColors (*this, "vcmi.capitalColors" ),
  314. znpc00 (*this, "vcmi.znpc00" ), // technically - wog
  315. qeModCommands (*this, "vcmi.quickExchange" )
  316. {
  317. detectInstallParameters();
  318. readToVector("core.vcdesc", "DATA/VCDESC.TXT" );
  319. readToVector("core.lcdesc", "DATA/LCDESC.TXT" );
  320. readToVector("core.tcommand", "DATA/TCOMMAND.TXT" );
  321. readToVector("core.hallinfo", "DATA/HALLINFO.TXT" );
  322. readToVector("core.castinfo", "DATA/CASTINFO.TXT" );
  323. readToVector("core.advevent", "DATA/ADVEVENT.TXT" );
  324. readToVector("core.restypes", "DATA/RESTYPES.TXT" );
  325. readToVector("core.randsign", "DATA/RANDSIGN.TXT" );
  326. readToVector("core.overview", "DATA/OVERVIEW.TXT" );
  327. readToVector("core.arraytxt", "DATA/ARRAYTXT.TXT" );
  328. readToVector("core.priskill", "DATA/PRISKILL.TXT" );
  329. readToVector("core.jktext", "DATA/JKTEXT.TXT" );
  330. readToVector("core.tvrninfo", "DATA/TVRNINFO.TXT" );
  331. readToVector("core.turndur", "DATA/TURNDUR.TXT" );
  332. readToVector("core.heroscrn", "DATA/HEROSCRN.TXT" );
  333. readToVector("core.tentcolr", "DATA/TENTCOLR.TXT" );
  334. readToVector("core.skilllev", "DATA/SKILLLEV.TXT" );
  335. readToVector("core.cmpmusic", "DATA/CMPMUSIC.TXT" );
  336. readToVector("core.minename", "DATA/MINENAME.TXT" );
  337. readToVector("core.mineevnt", "DATA/MINEEVNT.TXT" );
  338. static const char * QE_MOD_COMMANDS = "DATA/QECOMMANDS.TXT";
  339. if (CResourceHandler::get()->existsResource(ResourceID(QE_MOD_COMMANDS, EResType::TEXT)))
  340. readToVector("vcmi.quickExchange", QE_MOD_COMMANDS);
  341. {
  342. CLegacyConfigParser parser("DATA/RANDTVRN.TXT");
  343. parser.endLine();
  344. size_t index = 0;
  345. do
  346. {
  347. std::string line = parser.readString();
  348. if(!line.empty())
  349. {
  350. registerString("core", {"core.randtvrn", index}, line);
  351. index += 1;
  352. }
  353. }
  354. while (parser.endLine());
  355. }
  356. {
  357. CLegacyConfigParser parser("DATA/GENRLTXT.TXT");
  358. parser.endLine();
  359. size_t index = 0;
  360. do
  361. {
  362. registerString("core", {"core.genrltxt", index}, parser.readString());
  363. index += 1;
  364. }
  365. while (parser.endLine());
  366. }
  367. {
  368. CLegacyConfigParser parser("DATA/HELP.TXT");
  369. size_t index = 0;
  370. do
  371. {
  372. std::string first = parser.readString();
  373. std::string second = parser.readString();
  374. registerString("core", "core.help." + std::to_string(index) + ".hover", first);
  375. registerString("core", "core.help." + std::to_string(index) + ".help", second);
  376. index += 1;
  377. }
  378. while (parser.endLine());
  379. }
  380. {
  381. CLegacyConfigParser parser("DATA/PLCOLORS.TXT");
  382. size_t index = 0;
  383. do
  384. {
  385. std::string color = parser.readString();
  386. registerString("core", {"core.plcolors", index}, color);
  387. color[0] = toupper(color[0]);
  388. registerString("core", {"vcmi.capitalColors", index}, color);
  389. index += 1;
  390. }
  391. while (parser.endLine());
  392. }
  393. {
  394. CLegacyConfigParser parser("DATA/SEERHUT.TXT");
  395. //skip header
  396. parser.endLine();
  397. for (size_t i = 0; i < 6; ++i)
  398. {
  399. registerString("core", {"core.seerhut.empty", i}, parser.readString());
  400. }
  401. parser.endLine();
  402. for (size_t i = 0; i < 9; ++i) //9 types of quests
  403. {
  404. std::string questName = CQuest::missionName(static_cast<CQuest::Emission>(1+i));
  405. for (size_t j = 0; j < 5; ++j)
  406. {
  407. std::string questState = CQuest::missionState(j);
  408. parser.readString(); //front description
  409. for (size_t k = 0; k < 6; ++k)
  410. {
  411. registerString("core", {"core.seerhut.quest", questName, questState, k}, parser.readString());
  412. }
  413. parser.endLine();
  414. }
  415. }
  416. for (size_t k = 0; k < 6; ++k) //Time limit
  417. {
  418. registerString("core", {"core.seerhut.time", k}, parser.readString());
  419. }
  420. parser.endLine();
  421. parser.endLine(); // empty line
  422. parser.endLine(); // header
  423. for (size_t i = 0; i < 48; ++i)
  424. {
  425. registerString("core", {"core.seerhut.names", i}, parser.readString());
  426. parser.endLine();
  427. }
  428. }
  429. {
  430. CLegacyConfigParser parser("DATA/CAMPTEXT.TXT");
  431. //skip header
  432. parser.endLine();
  433. std::string text;
  434. size_t campaignsCount = 0;
  435. do
  436. {
  437. text = parser.readString();
  438. if (!text.empty())
  439. {
  440. registerString("core", {"core.camptext.names", campaignsCount}, text);
  441. campaignsCount += 1;
  442. }
  443. }
  444. while (parser.endLine() && !text.empty());
  445. for (size_t campaign=0; campaign<campaignsCount; campaign++)
  446. {
  447. size_t region = 0;
  448. do // skip empty space and header
  449. {
  450. text = parser.readString();
  451. }
  452. while (parser.endLine() && text.empty());
  453. do
  454. {
  455. text = parser.readString();
  456. if (!text.empty())
  457. {
  458. registerString("core", {"core.camptext.regions", std::to_string(campaign), region}, text);
  459. region += 1;
  460. }
  461. }
  462. while (parser.endLine() && !text.empty());
  463. scenariosCountPerCampaign.push_back(region);
  464. }
  465. }
  466. if (VLC->modh->modules.COMMANDERS)
  467. {
  468. if(CResourceHandler::get()->existsResource(ResourceID("DATA/ZNPC00.TXT", EResType::TEXT)))
  469. readToVector("vcmi.znpc00", "DATA/ZNPC00.TXT" );
  470. }
  471. }
  472. int32_t CGeneralTextHandler::pluralText(int32_t textIndex, int32_t count) const
  473. {
  474. if(textIndex == 0)
  475. return 0;
  476. if(textIndex < 0)
  477. return -textIndex;
  478. if(count == 1)
  479. return textIndex;
  480. return textIndex + 1;
  481. }
  482. void CGeneralTextHandler::dumpAllTexts()
  483. {
  484. logGlobal->info("BEGIN TEXT EXPORT");
  485. for ( auto const & entry : stringsLocalizations)
  486. {
  487. if (!entry.second.overrideValue.empty())
  488. logGlobal->info(R"("%s" : "%s",)", entry.first, TextOperations::escapeString(entry.second.overrideValue));
  489. else
  490. logGlobal->info(R"("%s" : "%s",)", entry.first, TextOperations::escapeString(entry.second.baseValue));
  491. }
  492. logGlobal->info("END TEXT EXPORT");
  493. }
  494. size_t CGeneralTextHandler::getCampaignLength(size_t campaignID) const
  495. {
  496. assert(campaignID < scenariosCountPerCampaign.size());
  497. if(campaignID < scenariosCountPerCampaign.size())
  498. return scenariosCountPerCampaign[campaignID];
  499. return 0;
  500. }
  501. std::string CGeneralTextHandler::getModLanguage(const std::string & modContext)
  502. {
  503. if (modContext == "core")
  504. return getInstalledLanguage();
  505. return VLC->modh->getModLanguage(modContext);
  506. }
  507. std::string CGeneralTextHandler::getPreferredLanguage()
  508. {
  509. return settings["general"]["language"].String();
  510. }
  511. std::string CGeneralTextHandler::getInstalledLanguage()
  512. {
  513. return settings["session"]["language"].String();
  514. }
  515. std::string CGeneralTextHandler::getInstalledEncoding()
  516. {
  517. return settings["session"]["encoding"].String();
  518. }
  519. std::vector<std::string> CGeneralTextHandler::findStringsWithPrefix(std::string const & prefix)
  520. {
  521. std::vector<std::string> result;
  522. for (auto const & entry : stringsLocalizations)
  523. {
  524. if(boost::algorithm::starts_with(entry.first, prefix))
  525. result.push_back(entry.first);
  526. }
  527. return result;
  528. }
  529. LegacyTextContainer::LegacyTextContainer(CGeneralTextHandler & owner, std::string const & basePath):
  530. owner(owner),
  531. basePath(basePath)
  532. {}
  533. std::string LegacyTextContainer::operator[](size_t index) const
  534. {
  535. return owner.translate(basePath, index);
  536. }
  537. LegacyHelpContainer::LegacyHelpContainer(CGeneralTextHandler & owner, std::string const & basePath):
  538. owner(owner),
  539. basePath(basePath)
  540. {}
  541. std::pair<std::string, std::string> LegacyHelpContainer::operator[](size_t index) const
  542. {
  543. return {
  544. owner.translate(basePath + "." + std::to_string(index) + ".hover"),
  545. owner.translate(basePath + "." + std::to_string(index) + ".help")
  546. };
  547. }
  548. VCMI_LIB_NAMESPACE_END