From b4dc014b107f871ee9a7dfbcd3ca5539dd3aa73e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 19 Feb 2019 22:50:40 +0300 Subject: TranslateU - translates a string to Utf8 --- src/mir_core/src/langpack.cpp | 30 +++++++++++++++++++++++------- src/mir_core/src/mir_core.def | 1 + src/mir_core/src/mir_core64.def | 1 + 3 files changed, 25 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/mir_core/src/langpack.cpp b/src/mir_core/src/langpack.cpp index fab4656a63..0532f58e4a 100644 --- a/src/mir_core/src/langpack.cpp +++ b/src/mir_core/src/langpack.cpp @@ -43,6 +43,7 @@ struct LangPackEntry { DWORD englishHash; char *szLocal; + char *utfLocal; wchar_t *wszLocal; MUUID *pMuuid; LangPackEntry* pNext; // for langpack items with the same hash value @@ -480,7 +481,7 @@ char* LangPackTranslateString(const MUUID *pUuid, const char *szEnglish, const i return (char*)szEnglish; LangPackEntry key, *entry; - key.englishHash = W ? hashstrW(szEnglish) : mir_hashstr(szEnglish); + key.englishHash = (W == 1) ? hashstrW(szEnglish) : mir_hashstr(szEnglish); entry = (LangPackEntry*)bsearch(&key, g_pEntries, g_entryCount, sizeof(LangPackEntry), (int(*)(const void*, const void*))SortLangPackHashesProc2); if (entry == nullptr) return (char*)szEnglish; @@ -495,12 +496,22 @@ char* LangPackTranslateString(const MUUID *pUuid, const char *szEnglish, const i } } - if (W) + switch (W) { + case 0: + if (entry->szLocal == nullptr && entry->wszLocal != nullptr) + entry->szLocal = mir_u2a_cp(entry->wszLocal, langPack.codepage); + return entry->szLocal; + + case 1: return (char*)entry->wszLocal; - if (entry->szLocal == nullptr && entry->wszLocal != nullptr) - entry->szLocal = mir_u2a_cp(entry->wszLocal, langPack.codepage); - return entry->szLocal; + case 2: + if (entry->utfLocal == nullptr && entry->wszLocal != nullptr) + entry->utfLocal = mir_utf8encodeW(entry->wszLocal); + return entry->utfLocal; + } + + return nullptr; } MIR_CORE_DLL(int) Langpack_GetDefaultCodePage() @@ -529,12 +540,17 @@ MIR_CORE_DLL(wchar_t*) Langpack_PcharToTchar(const char *pszStr) MIR_CORE_DLL(char*) TranslateA_LP(const char *str, HPLUGIN pPlugin) { - return (char*)LangPackTranslateString(GetMuid(pPlugin), str, FALSE); + return (char*)LangPackTranslateString(GetMuid(pPlugin), str, 0); +} + +MIR_CORE_DLL(char*) TranslateU_LP(const char *str, HPLUGIN pPlugin) +{ + return (char*)LangPackTranslateString(GetMuid(pPlugin), str, 2); } MIR_CORE_DLL(wchar_t*) TranslateW_LP(const wchar_t *str, HPLUGIN pPlugin) { - return (wchar_t*)LangPackTranslateString(GetMuid(pPlugin), (LPCSTR)str, TRUE); + return (wchar_t*)LangPackTranslateString(GetMuid(pPlugin), (LPCSTR)str, 1); } MIR_CORE_DLL(void) TranslateMenu_LP(HMENU hMenu, HPLUGIN pPlugin) diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 1fafa5915d..91ca5b7dbd 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1419,3 +1419,4 @@ db_get_utfa @1631 ?GetTextU@CCtrlBase@@QAEPADPADI@Z @1632 NONAME ?GetTextU@CCtrlBase@@QAEPADXZ @1633 NONAME ?BytesParsed@XMLDocument@tinyxml2@@QBEHXZ @1634 NONAME +TranslateU_LP @1635 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index f395c92786..565fd9bedc 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1419,3 +1419,4 @@ db_get_utfa @1631 ?GetTextU@CCtrlBase@@QEAAPEADPEAD_K@Z @1632 NONAME ?GetTextU@CCtrlBase@@QEAAPEADXZ @1633 NONAME ?BytesParsed@XMLDocument@tinyxml2@@QEBAHXZ @1634 NONAME +TranslateU_LP @1635 -- cgit v1.2.3