]> repos.lx-s.de Git - winmute.git/commitdiff
#26 Added more translations.
authorlx-s <lx-s@users.noreply.github.com>
Fri, 3 Nov 2023 08:49:59 +0000 (09:49 +0100)
committerlx-s <lx-s@users.noreply.github.com>
Fri, 3 Nov 2023 08:49:59 +0000 (09:49 +0100)
.gitattributes
Translations/wm_de/resource.h
Translations/wm_de/wm_de.rc
WinMute/WMi18n.cpp
WinMute/WMi18n.h
WinMute/WinMain.cpp
WinMute/WinMute.cpp
WinMute/WinMute.h
WinMute/WinMute.rc
WinMute/resource.h

index 59e95794d699b28bc85379ea29dc6d1494c128f7..c5b087279453a5eecc364087cc220f775b60a8a1 100644 (file)
@@ -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
 
index 1a2e987da85941280f46464d9776677005a27daa..fa888d8fad4a4bf0316faf604dae0e9a747c3c20 100644 (file)
@@ -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
 // 
index 06ce1b19ef255875cea30d2d84ff876542b883ee..07bec0d174513cf190ca178e0648c621fc0fe966 100644 (file)
Binary files a/Translations/wm_de/wm_de.rc and b/Translations/wm_de/wm_de.rc differ
index ce46411c6a8423aef6af52430ba5017f4a87a484..89a8439ba4c4361bd876f12160a042e6cc0308b0 100644 (file)
@@ -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;
+   }
+}
index 5c284584dc6925483af3980fc67d1e6877da7fb6..6e22ce223aa070815d1c8402fc0af1c28a1178b1 100644 (file)
@@ -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;
index c83d0f2393867ba9968dee2f7056c4880917cdf5..724f18280665d6428f7bbe3882e787238cb3a1e9 100644 (file)
@@ -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);
index cda8af364ed9937aa9f881f9608d31cc59a275fd..c22488a349bdfa43fb269fe790c006e9baf45f35 100644 (file)
@@ -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;
    }
index 514979f8880364fc1fdc83caae1031cb0dfc9e8a..ee3e3764dc6a039be1fcdce0a6805b8d343eee59 100644 (file)
@@ -67,6 +67,7 @@ private:
    TrayIcon trayIcon_;
    WifiDetector wifiDetector_;
    WMSettings& settings_;
+   WMi18n &i18n;
    MuteControl muteCtrl_;
    QuietHoursTimer quietHours_;
    BluetoothDetector btDetector_;
index 2da7905b32863048267681fe29490da0b30d49d6..7f0630b7ac5afd5729b73f3dfa7a54cd5a447093 100644 (file)
@@ -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
 /////////////////////////////////////////////////////////////////////////////
 
index 5db195ab069c3bd66adfe68882835333e7d53eb8..327331cb6f9506ad4c9190dc1d93395bb024d634 100644 (file)
@@ -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