LEFT | RIGHT |
1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
2 #include "PluginSystem.h" | 2 #include "PluginSystem.h" |
3 #include "PluginClient.h" | 3 #include "PluginClient.h" |
4 #include <array> | 4 #include <array> |
5 | 5 |
6 std::wstring GetBrowserLanguage() | 6 std::wstring GetBrowserLanguage() |
7 { | 7 { |
8 LANGID lcid = GetUserDefaultLangID(); | 8 LANGID lcid = GetUserDefaultLangID(); |
9 std::wstring lang; | 9 std::wstring lang; |
10 // we use `size() - 1` here to avoid additional calls to get the required size
or to get the | 10 // According to http://msdn.microsoft.com/en-us/library/windows/desktop/dd3738
48(v=vs.85).aspx |
11 // number of retrieved characters. | 11 // The maximum number of characters allowed for this string is nine, including
a terminating null character. |
12 { | 12 { |
13 std::array<wchar_t, 9> localeLanguage; | 13 std::array<wchar_t, 9> localeLanguage; |
14 localeLanguage.fill(L'\0'); | 14 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, localeLanguage.data()
, localeLanguage.size()); |
15 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, localeLanguage.data()
, localeLanguage.size() - 1); | |
16 if (res == 0) | 15 if (res == 0) |
17 { | 16 { |
18 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN
FO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed"); | 17 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN
FO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed"); |
19 } | 18 } |
20 else | 19 else |
21 { | 20 { |
22 lang += localeLanguage.data(); | 21 lang += localeLanguage.data(); |
23 } | 22 } |
24 } | 23 } |
25 lang += L"-"; | 24 lang += L"-"; |
26 { | 25 { |
27 std::array<wchar_t, 9> localeCountry; | 26 std::array<wchar_t, 9> localeCountry; |
28 localeCountry.fill(L'\0'); | 27 int res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, localeCountry.data()
, localeCountry.size()); |
29 int res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, localeCountry.data()
, localeCountry.size() - 1); | |
30 if (res == 0) | 28 if (res == 0) |
31 { | 29 { |
32 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN
FO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country"); | 30 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN
FO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country"); |
33 } | 31 } |
34 else | 32 else |
35 { | 33 { |
36 lang += localeCountry.data(); | 34 lang += localeCountry.data(); |
37 } | 35 } |
38 } | 36 } |
39 return lang; | 37 return lang; |
40 } | 38 } |
LEFT | RIGHT |