CGeneralTextHandler.cpp 19 KB

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