* @brief Load language.file * @param [in] wLangId * @return `true` on success, `false` otherwise. */
| 564 | * @return `true` on success, `false` otherwise. |
| 565 | */ |
| 566 | bool CLanguageSelect::LoadLanguageFile(LANGID wLangId, const std::wstring& sLanguagesFolder) |
| 567 | { |
| 568 | m_langId = wLangId; |
| 569 | m_map_msgid_to_msgstr.clear(); |
| 570 | |
| 571 | std::wstring strPath = GetFileName(wLangId, sLanguagesFolder); |
| 572 | if (strPath.empty()) |
| 573 | return false; |
| 574 | |
| 575 | wchar_t buf[1024]; |
| 576 | std::wstring *ps = nullptr; |
| 577 | std::wstring msgctxt; |
| 578 | std::wstring msgid; |
| 579 | FILE *f; |
| 580 | if (_tfopen_s(&f, strPath.c_str(), _T("r,ccs=UTF-8")) != 0) |
| 581 | return false; |
| 582 | ps = nullptr; |
| 583 | std::wstring format; |
| 584 | std::wstring msgstr; |
| 585 | std::wstring directive; |
| 586 | auto addToMap = [&]() { |
| 587 | ps = nullptr; |
| 588 | if (!msgctxt.empty()) |
| 589 | unslash(msgctxt); |
| 590 | if (!msgid.empty()) |
| 591 | unslash(msgid); |
| 592 | if (msgstr.empty()) |
| 593 | msgstr = msgid; |
| 594 | unslash(msgstr); |
| 595 | if (!msgid.empty()) |
| 596 | { |
| 597 | if (msgctxt.empty()) |
| 598 | m_map_msgid_to_msgstr.insert_or_assign(msgid, msgstr); |
| 599 | else |
| 600 | m_map_msgid_to_msgstr.insert_or_assign(L"\x01\"" + msgctxt + L"\"" + msgid, msgstr); |
| 601 | } |
| 602 | msgctxt.erase(); |
| 603 | msgid.erase(); |
| 604 | msgstr.erase(); |
| 605 | }; |
| 606 | while (fgetws(buf, static_cast<int>(std::size(buf)), f) != nullptr) |
| 607 | { |
| 608 | if (wchar_t *p1 = EatPrefix(buf, L"#,")) |
| 609 | { |
| 610 | format = p1; |
| 611 | format.erase(0, format.find_first_not_of(L" \t\r\n")); |
| 612 | format.erase(format.find_last_not_of(L" \t\r\n") + 1); |
| 613 | } |
| 614 | else if (wchar_t *p2 = EatPrefix(buf, L"#.")) |
| 615 | { |
| 616 | directive = p2; |
| 617 | directive.erase(0, directive.find_first_not_of(L" \t\r\n")); |
| 618 | directive.erase(directive.find_last_not_of(L" \t\r\n") + 1); |
| 619 | } |
| 620 | else if (EatPrefix(buf, L"msgctxt ")) |
| 621 | { |
| 622 | ps = &msgctxt; |
| 623 | } |
no test coverage detected