From 2acedb38e58a9f420ad5e32cfe272f796238b0f8 Mon Sep 17 00:00:00 2001
From: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
Date: Tue, 19 Jul 2022 09:19:50 -0300
Subject: [PATCH] plugins: fix locale in windows

Change-Id: I630a53810f39dc4b1df81417242eafb0da77766a
---
 src/plugin/pluginpreferencesutils.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/plugin/pluginpreferencesutils.cpp b/src/plugin/pluginpreferencesutils.cpp
index f1c6f31df7..03ae4498c7 100644
--- a/src/plugin/pluginpreferencesutils.cpp
+++ b/src/plugin/pluginpreferencesutils.cpp
@@ -159,7 +159,26 @@ PluginPreferencesUtils::getPreferences(const std::string& rootPath, const std::s
     std::vector<std::map<std::string, std::string>> preferences;
     if (file) {
         // Get preferences locale
+#ifdef WIN32
+        std::string lang;
+        WCHAR localeBuffer[LOCALE_NAME_MAX_LENGTH];
+        if (GetUserDefaultLocaleName(localeBuffer, LOCALE_NAME_MAX_LENGTH) != 0) {
+            char utf8Buffer[LOCALE_NAME_MAX_LENGTH] {};
+            WideCharToMultiByte(CP_UTF8,
+                                0,
+                                localeBuffer,
+                                LOCALE_NAME_MAX_LENGTH,
+                                utf8Buffer,
+                                LOCALE_NAME_MAX_LENGTH,
+                                nullptr,
+                                nullptr);
+
+            lang.append(utf8Buffer);
+            string_replace(lang, "-", "_");
+        }
+#else
         std::string lang = std::locale("").name();
+#endif //
         auto locales = getLocales(rootPath, std::string(string_remove_suffix(lang, '.')));
 
         // Read the file to a json format
-- 
GitLab