+// ----------------------------------------------------------------------------
+// wxLanguageInfo
+// ----------------------------------------------------------------------------
+
+#ifdef __WXMSW__
+
+// helper used by wxLanguageInfo::GetLocaleName() and elsewhere to determine
+// whether the locale is Unicode-only (it is if this function returns empty
+// string)
+static wxString wxGetANSICodePageForLocale(LCID lcid)
+{
+ wxString cp;
+
+ wxChar buffer[16];
+ if ( ::GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE,
+ buffer, WXSIZEOF(buffer)) > 0 )
+ {
+ if ( buffer[0] != _T('0') || buffer[1] != _T('\0') )
+ cp = buffer;
+ //else: this locale doesn't use ANSI code page
+ }
+
+ return cp;
+}
+
+wxUint32 wxLanguageInfo::GetLCID() const
+{
+ return MAKELCID(MAKELANGID(WinLang, WinSublang), SORT_DEFAULT);
+}
+
+wxString wxLanguageInfo::GetLocaleName() const
+{
+ wxString locale;
+
+ const LCID lcid = GetLCID();
+
+ wxChar buffer[256];
+ buffer[0] = _T('\0');
+ if ( !::GetLocaleInfo(lcid, LOCALE_SENGLANGUAGE, buffer, WXSIZEOF(buffer)) )
+ {
+ wxLogLastError(_T("GetLocaleInfo(LOCALE_SENGLANGUAGE)"));
+ return locale;
+ }
+
+ locale << buffer;
+ if ( ::GetLocaleInfo(lcid, LOCALE_SENGCOUNTRY,
+ buffer, WXSIZEOF(buffer)) > 0 )
+ {
+ locale << _T('_') << buffer;
+ }
+
+ const wxString cp = wxGetANSICodePageForLocale(lcid);
+ if ( !cp.empty() )
+ {
+ locale << _T('.') << cp;
+ }
+
+ return locale;
+}
+
+#endif // __WXMSW__
+