MCPcopy Create free account
hub / github.com/WinMerge/winmerge / LoadLanguageFile

Method LoadLanguageFile

ShellExtension/Common/LanguageSelect.cpp:566–651  ·  view source on GitHub ↗

* @brief Load language.file * @param [in] wLangId * @return `true` on success, `false` otherwise. */

Source from the content-addressed store, hash-verified

564 * @return `true` on success, `false` otherwise.
565 */
566bool 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 }

Callers 1

GetResourceStringMethod · 0.45

Calls 8

unslashFunction · 0.70
EatPrefixFunction · 0.70
sizeClass · 0.50
clearMethod · 0.45
emptyMethod · 0.45
insert_or_assignMethod · 0.45
eraseMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected