Skip to content

Commit

Permalink
feat: WeaselSetup.exe command parameter to set language of user inter…
Browse files Browse the repository at this point in the history
…face, /lt for traditional, /ls for simplified, /le for english.
  • Loading branch information
fxliang committed Jun 12, 2024
1 parent c6a3fa2 commit f16d356
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
20 changes: 20 additions & 0 deletions WeaselSetup/WeaselSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ static int Run(LPTSTR lpCmdLine) {
if (uninstalling)
return uninstall(silent);

auto setLanguage = [](const wchar_t* language) {
const WCHAR KEY[] = L"Software\\Rime\\Weasel";
HKEY hKey;
LSTATUS ret = RegOpenKey(HKEY_CURRENT_USER, KEY, &hKey);
if (ret == ERROR_SUCCESS) {
ret = RegSetValueEx(hKey, L"Language", 0, REG_SZ, (const BYTE*)language,
(wcslen(language) + 1) * sizeof(wchar_t));
RegCloseKey(hKey);
}
return ret;
};

if (!wcscmp(L"/ls", lpCmdLine)) {
return setLanguage(L"chs");
} else if (!wcscmp(L"/lt", lpCmdLine)) {
return setLanguage(L"cht");
} else if (!wcscmp(L"/le", lpCmdLine)) {
return setLanguage(L"eng");
}

bool hans = !wcscmp(L"/s", lpCmdLine);
if (hans)
return install(false, silent, old_ime_support);
Expand Down
15 changes: 0 additions & 15 deletions WeaselTSF/LanguageBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,6 @@ static void HMENU2ITfMenu(HMENU hMenu, ITfMenu* pTfMenu) {
}
}

static LONG RegGetStringValue(HKEY key,
LPCWSTR lpSubKey,
LPCWSTR lpValue,
std::wstring& value) {
TCHAR szValue[MAX_PATH];
DWORD dwBufLen = MAX_PATH;

LONG lRes = RegGetValue(key, lpSubKey, lpValue, RRF_RT_REG_SZ, NULL, szValue,
&dwBufLen);
if (lRes == ERROR_SUCCESS) {
value = std::wstring(szValue);
}
return lRes;
}

static LPCWSTR GetWeaselRegName() {
LPCWSTR WEASEL_REG_NAME_;
if (is_wow64())
Expand Down
27 changes: 26 additions & 1 deletion include/WeaselUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,32 @@ inline std::wstring get_weasel_ime_name() {
}
}

inline LONG RegGetStringValue(HKEY key,
LPCWSTR lpSubKey,
LPCWSTR lpValue,
std::wstring& value) {
TCHAR szValue[MAX_PATH];
DWORD dwBufLen = MAX_PATH;

LONG lRes = RegGetValue(key, lpSubKey, lpValue, RRF_RT_REG_SZ, NULL, szValue,
&dwBufLen);
if (lRes == ERROR_SUCCESS) {
value = std::wstring(szValue);
}
return lRes;
}

inline LANGID get_language_id() {
std::wstring lang{};
if (RegGetStringValue(HKEY_CURRENT_USER, L"Software\\Rime\\Weasel",
L"Language", lang) == ERROR_SUCCESS) {
if (lang == L"chs")
return MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);
else if (lang == L"cht")
return MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL);
else if (lang == L"eng")
return MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
}
LANGID langId = GetUserDefaultUILanguage();
if (langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) ||
langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE)) {
Expand All @@ -210,4 +235,4 @@ inline LANGID get_language_id() {
langId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
}
return langId;
}
}

0 comments on commit f16d356

Please sign in to comment.