Skip to content

Commit

Permalink
fix: the UI language was incorrectly determined by "Region Format"
Browse files Browse the repository at this point in the history
  • Loading branch information
ccyybn authored and fxliang committed Jun 11, 2024
1 parent 07894fb commit 8dd0898
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 51 deletions.
13 changes: 2 additions & 11 deletions WeaselDeployer/WeaselDeployer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 2 additions & 11 deletions WeaselServer/WeaselServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
14 changes: 3 additions & 11 deletions WeaselSetup/WeaselSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "stdafx.h"

#include "resource.h"
#include "WeaselUtility.h"
#include <thread>

#include "InstallOptionsDlg.h"
Expand All @@ -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);
Expand Down
17 changes: 2 additions & 15 deletions WeaselTSF/LanguageBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
Expand Down
25 changes: 22 additions & 3 deletions include/WeaselUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,30 @@ inline std::basic_string<CharT> 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;
}

0 comments on commit 8dd0898

Please sign in to comment.