* 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. */
| 372 | * @param extras Pointer to extra strings from ruleset. |
| 373 | */ |
| 374 | void 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 |
nothing calls this directly
no test coverage detected