diff --git a/WeaselDeployer/WeaselDeployer.cpp b/WeaselDeployer/WeaselDeployer.cpp index 4e73af76a..037b674a0 100644 --- a/WeaselDeployer/WeaselDeployer.cpp +++ b/WeaselDeployer/WeaselDeployer.cpp @@ -16,17 +16,8 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); - LCID lcid = GetUserDefaultLCID(); - LANGID langId; - if (lcid == 2052 || lcid == 3072 || lcid == 4100) { - langId = SetThreadUILanguage( - MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED)); - } else if (lcid == 1028 || lcid == 3076 || lcid == 5124) { - langId = SetThreadUILanguage( - MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL)); - } else { - langId = SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); - } + LANGID langId = get_language_id(); + SetThreadUILanguage(langId); SetThreadLocale(langId); HRESULT hRes = ::CoInitialize(NULL); diff --git a/WeaselServer/WeaselServer.cpp b/WeaselServer/WeaselServer.cpp index a99b49316..b4cf8b2f1 100644 --- a/WeaselServer/WeaselServer.cpp +++ b/WeaselServer/WeaselServer.cpp @@ -22,17 +22,8 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) { - LCID lcid = GetUserDefaultLCID(); - LANGID langId; - if (lcid == 2052 || lcid == 3072 || lcid == 4100) { - langId = SetThreadUILanguage( - MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED)); - } else if (lcid == 1028 || lcid == 3076 || lcid == 5124) { - langId = SetThreadUILanguage( - MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL)); - } else { - langId = SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); - } + LANGID langId = get_language_id(); + SetThreadUILanguage(langId); SetThreadLocale(langId); if (!IsWindowsBlueOrLaterEx()) { diff --git a/WeaselSetup/WeaselSetup.cpp b/WeaselSetup/WeaselSetup.cpp index 2a48b04e1..865e4855c 100644 --- a/WeaselSetup/WeaselSetup.cpp +++ b/WeaselSetup/WeaselSetup.cpp @@ -4,6 +4,7 @@ #include "stdafx.h" #include "resource.h" +#include "WeaselUtility.h" #include #include "InstallOptionsDlg.h" @@ -27,17 +28,8 @@ int WINAPI _tWinMain(HINSTANCE hInstance, hRes = _Module.Init(NULL, hInstance); ATLASSERT(SUCCEEDED(hRes)); - LCID lcid = GetUserDefaultLCID(); - LANGID langId; - if (lcid == 2052 || lcid == 3072 || lcid == 4100) { - langId = SetThreadUILanguage( - MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED)); - } else if (lcid == 1028 || lcid == 3076 || lcid == 5124) { - langId = SetThreadUILanguage( - MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL)); - } else { - langId = SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); - } + LANGID langId = get_language_id(); + SetThreadUILanguage(langId); SetThreadLocale(langId); int nRet = Run(lpstrCmdLine); diff --git a/WeaselTSF/LanguageBar.cpp b/WeaselTSF/LanguageBar.cpp index 0ff122dfe..7e535e343 100644 --- a/WeaselTSF/LanguageBar.cpp +++ b/WeaselTSF/LanguageBar.cpp @@ -155,21 +155,8 @@ static LANGID GetActiveProfileLangId() { return profile.langid; } -static LANGID GetUserDefaultLangId() { - LANGID langId; - LCID lcid = GetUserDefaultLCID(); - if (lcid == 2052 || lcid == 3072 || lcid == 4100) { - langId = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED); - } else if (lcid == 1028 || lcid == 3076 || lcid == 5124) { - langId = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL); - } else { - langId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); - } - return langId; -} - STDAPI CLangBarItemButton::GetTooltipString(BSTR* pbstrToolTip) { - LANGID langid = GetUserDefaultLangId(); + LANGID langid = get_language_id(); if (langid == TEXTSERVICE_LANGID_HANS) { *pbstrToolTip = SysAllocString(L"左键切换模式,右键打开菜单"); } else if (langid == TEXTSERVICE_LANGID_HANT) { @@ -196,7 +183,7 @@ STDAPI CLangBarItemButton::OnClick(TfLBIClick click, /* Open menu */ HWND hwnd = _pTextService->_GetFocusedContextWindow(); if (hwnd != NULL) { - LANGID langid = GetUserDefaultLangId(); + LANGID langid = get_language_id(); HMENU menu; if (langid == TEXTSERVICE_LANGID_HANS) { menu = LoadMenuW(g_hInst, MAKEINTRESOURCE(IDR_MENU_POPUP_HANS)); diff --git a/include/WeaselUtility.h b/include/WeaselUtility.h index 6fa048a4d..942cd8ab9 100644 --- a/include/WeaselUtility.h +++ b/include/WeaselUtility.h @@ -184,11 +184,30 @@ inline std::basic_string unescape_string( std::string GetCustomResource(const char* name, const char* type); inline std::wstring get_weasel_ime_name() { - LCID lcid = GetUserDefaultLCID(); - if (lcid == 2052 || lcid == 3072 || lcid == 4100 || lcid == 1028 || - lcid == 3076 || lcid == 5124) { + LANGID langId = GetUserDefaultUILanguage(); + + if (langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL) || + langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) || + langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_HONGKONG) || + langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE) || + langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_MACAU)) { return L"小狼毫"; } else { return L"Weasel"; } +} + +inline LANGID get_language_id() { + LANGID langId = GetUserDefaultUILanguage(); + if (langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) || + langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE)) { + langId = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED); + } else if (langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL) || + langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_HONGKONG) || + langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_MACAU)) { + langId = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL); + } else { + langId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); + } + return langId; } \ No newline at end of file