From 2986ee351d41ea34ad16e9066e6fb52639b99d0b Mon Sep 17 00:00:00 2001 From: lx-s Date: Fri, 3 Nov 2023 09:49:59 +0100 Subject: [PATCH] #26 Added more translations. --- .gitattributes | 2 +- Translations/wm_de/resource.h | 3 +++ Translations/wm_de/wm_de.rc | Bin 4404 -> 5036 bytes WinMute/WMi18n.cpp | 28 ++++++++++++++++++++++++++-- WinMute/WMi18n.h | 3 ++- WinMute/WinMain.cpp | 15 +++++++-------- WinMute/WinMute.cpp | 11 ++++++----- WinMute/WinMute.h | 1 + WinMute/WinMute.rc | 6 ++++++ WinMute/resource.h | 3 +++ 10 files changed, 55 insertions(+), 17 deletions(-) diff --git a/.gitattributes b/.gitattributes index 59e9579..c5b0872 100644 --- a/.gitattributes +++ b/.gitattributes @@ -19,7 +19,7 @@ *.vcxproj text eol=crlf *.vcxproj.filters text eol=crlf *.vcxproj.users text eol=crlf -*.rc text eol=crlf +*.rc text eol=auto *.props eol=crlf resource.h text eol=crlf diff --git a/Translations/wm_de/resource.h b/Translations/wm_de/resource.h index 1a2e987..fa888d8 100644 --- a/Translations/wm_de/resource.h +++ b/Translations/wm_de/resource.h @@ -9,6 +9,9 @@ #define IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TEXT 105 #define IDS_MAIN_ERROR_INIT_WINMUTE_TITLE 106 #define IDS_MAIN_ERROR_INIT_WINMUTE_TEXT 107 +#define IDS_WM_ERROR_WINDOWS_SUPPORT_TITLE 201 +#define IDS_WM_ERROR_WINDOWS_SUPPORT_TEXT2 202 +#define IDS_WM_ERROR_WINDOWS_SUPPORT_TEXT 202 // Next default values for new objects // diff --git a/Translations/wm_de/wm_de.rc b/Translations/wm_de/wm_de.rc index 06ce1b19ef255875cea30d2d84ff876542b883ee..07bec0d174513cf190ca178e0648c621fc0fe966 100644 GIT binary patch delta 419 zcmdm@v_^dc2j6534h!pW249AF23Lk4AoK^~c!qEWPX<2*7a%X3AsEOHW(Z{n078&# z2#_BFln-I>VQ`%+&+QoP$56^p#Gn9Fo5_&JkiwA9P|i>cGGx$WFacsCpvru>swYq<7j6E?>&y%Qa+FY? delta 12 TcmZ3ZzC~#R2jAuf0Uc%l9vK7T diff --git a/WinMute/WMi18n.cpp b/WinMute/WMi18n.cpp index ce46411..89a8439 100644 --- a/WinMute/WMi18n.cpp +++ b/WinMute/WMi18n.cpp @@ -110,7 +110,7 @@ std::wstring WMi18n::GetCurrentLanguageModule() const std::wstring WMi18n::GetCurrentLanguageName() const { - return GetString(IDS_LANG_NAME); + return GetTextW(IDS_LANG_NAME); } // https://learn.microsoft.com/en-us/windows/win32/intl/creating-a-multilingual-user-interface-application @@ -155,7 +155,7 @@ void WMi18n::UnloadLanguage() noexcept } } -std::wstring WMi18n::GetString(UINT strId) const +std::wstring WMi18n::GetTextW(UINT strId) const { HMODULE hMod = (langModule_ == nullptr) ? hglobInstance : langModule_; constexpr size_t strBufferSize = 2048 + 1; @@ -178,3 +178,27 @@ std::wstring WMi18n::GetString(UINT strId) const return err; } } + +std::string WMi18n::GetTextA(UINT strId) const +{ + HMODULE hMod = (langModule_ == nullptr) ? hglobInstance : langModule_; + constexpr size_t strBufferSize = 2048 + 1; + char strBuffer[strBufferSize]{ 0 }; + const int strLength = LoadStringA(hMod, strId, strBuffer, 0); + if (strLength == 0) { + return ""; + } else if (strLength < strBufferSize) { + LoadStringA(hMod, strId, strBuffer, ARRAY_SIZE(strBuffer)); + return std::string(strBuffer, strBuffer + strLength); + } else if (strLength > 0) { + char *largeBuffer = new char[strLength + 1]; + LoadStringA(hMod, strId, largeBuffer, strLength + 1); + std::string ret(strBuffer, largeBuffer + strLength); + delete[] largeBuffer; + return ret; + } else { + WMLog::GetInstance().WriteWindowsError(L"LoadStringA", GetLastError()); + std::string err = "String resource " + std::to_string(strId) + " not found"; + return err; + } +} diff --git a/WinMute/WMi18n.h b/WinMute/WMi18n.h index 5c28458..6e22ce2 100644 --- a/WinMute/WMi18n.h +++ b/WinMute/WMi18n.h @@ -51,7 +51,8 @@ public: std::wstring GetCurrentLanguageModule() const; std::wstring GetCurrentLanguageName() const; - std::wstring GetString(UINT id) const; + std::wstring GetTextW(UINT id) const; + std::string GetTextA(UINT id) const; private: WMi18n() noexcept; diff --git a/WinMute/WinMain.cpp b/WinMute/WinMain.cpp index c83d0f2..724f182 100644 --- a/WinMute/WinMain.cpp +++ b/WinMute/WinMain.cpp @@ -86,8 +86,8 @@ int WINAPI wWinMain( nullptr, nullptr, PROGRAM_NAME, - i18n.GetString(IDS_MAIN_ERROR_SETTINGS_INIT_TITLE).c_str(), - i18n.GetString(IDS_MAIN_ERROR_SETTINGS_INIT_TEXT).c_str(), + i18n.GetTextW(IDS_MAIN_ERROR_SETTINGS_INIT_TITLE).c_str(), + i18n.GetTextW(IDS_MAIN_ERROR_SETTINGS_INIT_TEXT).c_str(), TDCBF_OK_BUTTON, TD_ERROR_ICON, nullptr); @@ -96,7 +96,7 @@ int WINAPI wWinMain( LoadLanguage(settings, i18n); - HANDLE hMutex = CreateMutexW(nullptr, TRUE, L"LxSystemsWinMuteMtx"); + HANDLE hMutex = CreateMutexW(nullptr, TRUE, L"LxSystemsWinMuteRunOnce"); if (hMutex == nullptr) { return FALSE; } else if (GetLastError() == ERROR_ALREADY_EXISTS) { @@ -105,8 +105,8 @@ int WINAPI wWinMain( nullptr, nullptr, PROGRAM_NAME, - i18n.GetString(IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TITLE).c_str(), - i18n.GetString(IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TEXT).c_str(), + i18n.GetTextW(IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TITLE).c_str(), + i18n.GetTextW(IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TEXT).c_str(), TDCBF_OK_BUTTON, TD_INFORMATION_ICON, nullptr); @@ -115,7 +115,6 @@ int WINAPI wWinMain( SetWorkingDirectory(); - HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0); if (!InitWindowsComponents()) { @@ -123,8 +122,8 @@ int WINAPI wWinMain( nullptr, nullptr, PROGRAM_NAME, - i18n.GetString(IDS_MAIN_ERROR_INIT_WINMUTE_TITLE).c_str(), - i18n.GetString(IDS_MAIN_ERROR_INIT_WINMUTE_TEXT).c_str(), + i18n.GetTextW(IDS_MAIN_ERROR_INIT_WINMUTE_TITLE).c_str(), + i18n.GetTextW(IDS_MAIN_ERROR_INIT_WINMUTE_TEXT).c_str(), TDCBF_OK_BUTTON, TD_ERROR_ICON, nullptr); diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index cda8af3..c22488a 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -148,7 +148,8 @@ WinMute::WinMute(WMSettings& settings) : hTrayMenu_(nullptr), hAppIcon_(nullptr), hTrayIcon_(nullptr), - settings_(settings) + settings_(settings), + i18n(WMi18n::GetInstance()) { } @@ -191,10 +192,10 @@ bool WinMute::InitAudio() // Nothing to do } else if (IsWindowsXPOrGreater()) { TaskDialog( - nullptr, nullptr, PROGRAM_NAME, - L"Only Windows Vista and newer is supported", - L"For Windows XP support, please download WinMute " - L" version 1.4.2 or older", + nullptr, nullptr, + PROGRAM_NAME, + i18n.GetTextW(IDS_WM_ERROR_WINDOWS_SUPPORT_TITLE).c_str(), + i18n.GetTextW(IDS_WM_ERROR_WINDOWS_SUPPORT_TEXT).c_str(), TDCBF_OK_BUTTON, TD_ERROR_ICON, nullptr); return false; } diff --git a/WinMute/WinMute.h b/WinMute/WinMute.h index 514979f..ee3e376 100644 --- a/WinMute/WinMute.h +++ b/WinMute/WinMute.h @@ -67,6 +67,7 @@ private: TrayIcon trayIcon_; WifiDetector wifiDetector_; WMSettings& settings_; + WMi18n &i18n; MuteControl muteCtrl_; QuietHoursTimer quietHours_; BluetoothDetector btDetector_; diff --git a/WinMute/WinMute.rc b/WinMute/WinMute.rc index 2da7905..7f0630b 100644 --- a/WinMute/WinMute.rc +++ b/WinMute/WinMute.rc @@ -554,6 +554,12 @@ BEGIN "WinMute encountered a critical error while initializing and must shut down." END +STRINGTABLE +BEGIN + IDS_WM_ERROR_WINDOWS_SUPPORT_TITLE + "Only Windows Vista and newer is supported" +END + #endif // English (United Kingdom) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/WinMute/resource.h b/WinMute/resource.h index 5db195a..327331c 100644 --- a/WinMute/resource.h +++ b/WinMute/resource.h @@ -30,6 +30,9 @@ #define IDD_MANAGE_ENDPOINTS 135 #define IDD_DIALOG2 137 #define IDD_MANAGE_ENDPOINTS_ADD 137 +#define IDS_WM_ERROR_WINDOWS_SUPPORT_TITLE 201 +#define IDS_STRING202 202 +#define IDS_WM_ERROR_WINDOWS_SUPPORT_TEXT 202 #define IDC_LINK_HOMEPAGE 1001 #define IDC_LINK_SUPPORT 1002 #define IDC_LINK_PROJECT 1002 -- 2.43.0