MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / load

Method load

src/Engine/Language.cpp:374–423  ·  view source on GitHub ↗

* Loads a language file in Ruby-on-Rails YAML format. * Not that this has anything to do with Ruby, but since it's a * widely-supported format and we already have YAML, it was convenient. * @param filename Filename of the YAML file. * @param extras Pointer to extra strings from ruleset. */

Source from the content-addressed store, hash-verified

372 * @param extras Pointer to extra strings from ruleset.
373 */
374void Language::load(const std::string &filename, ExtraStrings *extras)
375{
376 _strings.clear();
377
378 YAML::Node doc = YAML::LoadFile(filename);
379 _id = doc.begin()->first.as<std::string>();
380 YAML::Node lang = doc.begin()->second;
381 for (YAML::const_iterator i = lang.begin(); i != lang.end(); ++i)
382 {
383 // Regular strings
384 if (i->second.IsScalar())
385 {
386 _strings[i->first.as<std::string>()] = loadString(i->second.as<std::string>());
387 }
388 // Strings with plurality
389 else if (i->second.IsMap())
390 {
391 for (YAML::const_iterator j = i->second.begin(); j != i->second.end(); ++j)
392 {
393 std::string s = i->first.as<std::string>() + "_" + j->first.as<std::string>();
394 _strings[s] = loadString(j->second.as<std::string>());
395 }
396 }
397 }
398 if (extras)
399 {
400 for (std::map<std::string, std::string>::const_iterator i = extras->getStrings()->begin(); i != extras->getStrings()->end(); ++i)
401 {
402 _strings[i->first] = loadString(i->second);
403 }
404 }
405 delete _handler;
406 _handler = LanguagePlurality::create(_id);
407 if (std::find(_rtl.begin(), _rtl.end(), _id) == _rtl.end())
408 {
409 _direction = DIRECTION_LTR;
410 }
411 else
412 {
413 _direction = DIRECTION_RTL;
414 }
415 if (std::find(_cjk.begin(), _cjk.end(), _id) == _cjk.end())
416 {
417 _wrap = WRAP_WORDS;
418 }
419 else
420 {
421 _wrap = WRAP_LETTERS;
422 }
423}
424
425/**
426* Replaces all special string markers with the approriate characters

Callers

nothing calls this directly

Calls 3

createFunction · 0.85
getStringsMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected