* Returns the localized text with the specified ID, in the proper form for @a n. * The substitution of @a n has already happened in the returned LocalizedText. * If it's not found, just returns the ID. * @param id ID of the string. * @param n Number to use to decide the proper form. * @return String with the requested ID. */
| 488 | * @return String with the requested ID. |
| 489 | */ |
| 490 | LocalizedText Language::getString(const std::string &id, unsigned n) const |
| 491 | { |
| 492 | assert(!id.empty()); |
| 493 | std::map<std::string, LocalizedText>::const_iterator s = _strings.end(); |
| 494 | if (0 == n) |
| 495 | { |
| 496 | // Try specialized form. |
| 497 | s = _strings.find(id + "_zero"); |
| 498 | } |
| 499 | if (s == _strings.end()) |
| 500 | { |
| 501 | // Try proper form by language |
| 502 | s = _strings.find(id + _handler->getSuffix(n)); |
| 503 | } |
| 504 | if (s == _strings.end()) |
| 505 | { |
| 506 | Log(LOG_WARNING) << id << " not found in " << Options::language; |
| 507 | return LocalizedText(utf8ToWstr(id)); |
| 508 | } |
| 509 | std::wostringstream ss; |
| 510 | ss << n; |
| 511 | std::wstring marker(L"{N}"), val(ss.str()), txt(s->second); |
| 512 | replace(txt, marker, val); |
| 513 | return txt; |
| 514 | } |
| 515 | |
| 516 | /** |
| 517 | * Returns the localized text with the specified ID, in the proper form for the gender. |
no test coverage detected