| OLD | NEW |
| 1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
| 2 |
| 2 #include "PluginSystem.h" | 3 #include "PluginSystem.h" |
| 3 #include "PluginClient.h" | 4 #include "PluginClient.h" |
| 4 #include <array> | |
| 5 | 5 |
| 6 std::wstring GetBrowserLanguage() | 6 std::wstring GetBrowserLanguage() |
| 7 { | 7 { |
| 8 LANGID lcid = GetUserDefaultLangID(); | 8 LANGID lcid = GetUserDefaultLangID(); |
| 9 wchar_t language[128]; |
| 10 memset(language, 0, sizeof(language)); |
| 11 wchar_t country[128]; |
| 12 memset(language, 0, sizeof(country)); |
| 13 |
| 9 std::wstring lang; | 14 std::wstring lang; |
| 10 // we use `size() - 1` here to avoid additional calls to get the required size
or to get the | 15 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, language, 127); |
| 11 // number of retrieved characters. | 16 if (res == 0) |
| 12 { | 17 { |
| 13 std::array<wchar_t, 9> localeLanguage; | 18 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO
_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed"); |
| 14 localeLanguage.fill(L'\0'); | 19 } |
| 15 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, localeLanguage.data()
, localeLanguage.size() - 1); | 20 else |
| 16 if (res == 0) | 21 { |
| 17 { | 22 lang += language; |
| 18 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN
FO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed"); | |
| 19 } | |
| 20 else | |
| 21 { | |
| 22 lang += localeLanguage.data(); | |
| 23 } | |
| 24 } | 23 } |
| 25 lang += L"-"; | 24 lang += L"-"; |
| 25 res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, country, 127); |
| 26 if (res == 0) |
| 26 { | 27 { |
| 27 std::array<wchar_t, 9> localeCountry; | 28 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO
_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country"); |
| 28 localeCountry.fill(L'\0'); | 29 } |
| 29 int res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, localeCountry.data()
, localeCountry.size() - 1); | 30 else |
| 30 if (res == 0) | 31 { |
| 31 { | 32 lang += country; |
| 32 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN
FO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country"); | |
| 33 } | |
| 34 else | |
| 35 { | |
| 36 lang += localeCountry.data(); | |
| 37 } | |
| 38 } | 33 } |
| 39 return lang; | 34 return lang; |
| 40 } | 35 } |
| OLD | NEW |