/* static */ wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory WXUNUSED(cat)) { wxUint32 lcid = LOCALE_USER_DEFAULT; if ( wxGetLocale() ) { const wxLanguageInfo * const info = GetLanguageInfo(wxGetLocale()->GetLanguage()); if ( info ) lcid = info->GetLCID(); } wxString str; wxChar buf[256]; buf[0] = wxT('\0'); switch ( index ) { case wxLOCALE_DECIMAL_POINT: if ( ::GetLocaleInfo(lcid, LOCALE_SDECIMAL, buf, WXSIZEOF(buf)) ) str = buf; break; case wxLOCALE_SHORT_DATE_FMT: case wxLOCALE_LONG_DATE_FMT: case wxLOCALE_TIME_FMT: if ( ::GetLocaleInfo(lcid, GetLCTYPEFormatFromLocalInfo(index), buf, WXSIZEOF(buf)) ) { return TranslateFromUnicodeFormat(buf); } break; case wxLOCALE_DATE_TIME_FMT: // there doesn't seem to be any specific setting for this, so just // combine date and time ones // // we use the short date because this is what "%c" uses by default // ("%#c" uses long date but we have no way to specify the // alternate representation here) { const wxString datefmt = GetInfo(wxLOCALE_SHORT_DATE_FMT); if ( datefmt.empty() ) break; const wxString timefmt = GetInfo(wxLOCALE_TIME_FMT); if ( timefmt.empty() ) break; str << datefmt << ' ' << timefmt; } break; default: wxFAIL_MSG( "unknown wxLocaleInfo" ); } return str; }
/* static */ wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory WXUNUSED(cat)) { CFLocaleRef userLocaleRefRaw; if ( wxGetLocale() ) { userLocaleRefRaw = CFLocaleCreate ( kCFAllocatorDefault, wxCFStringRef(wxGetLocale()->GetCanonicalName()) ); } else // no current locale, use the default one { userLocaleRefRaw = CFLocaleCopyCurrent(); } wxCFRef<CFLocaleRef> userLocaleRef(userLocaleRefRaw); CFStringRef cfstr = 0; switch ( index ) { case wxLOCALE_THOUSANDS_SEP: cfstr = (CFStringRef) CFLocaleGetValue(userLocaleRef, kCFLocaleGroupingSeparator); break; case wxLOCALE_DECIMAL_POINT: cfstr = (CFStringRef) CFLocaleGetValue(userLocaleRef, kCFLocaleDecimalSeparator); break; case wxLOCALE_SHORT_DATE_FMT: case wxLOCALE_LONG_DATE_FMT: case wxLOCALE_DATE_TIME_FMT: case wxLOCALE_TIME_FMT: { CFDateFormatterStyle dateStyle = kCFDateFormatterNoStyle; CFDateFormatterStyle timeStyle = kCFDateFormatterNoStyle; switch (index ) { case wxLOCALE_SHORT_DATE_FMT: dateStyle = kCFDateFormatterShortStyle; break; case wxLOCALE_LONG_DATE_FMT: dateStyle = kCFDateFormatterFullStyle; break; case wxLOCALE_DATE_TIME_FMT: dateStyle = kCFDateFormatterFullStyle; timeStyle = kCFDateFormatterMediumStyle; break; case wxLOCALE_TIME_FMT: timeStyle = kCFDateFormatterMediumStyle; break; default: wxFAIL_MSG( "unexpected time locale" ); return wxString(); } wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate (NULL, userLocaleRef, dateStyle, timeStyle)); wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter )); wxString format = TranslateFromUnicodeFormat(cfs.AsString()); // we always want full years format.Replace("%y","%Y"); return format; } break; default: wxFAIL_MSG( "Unknown locale info" ); return wxString(); } wxCFStringRef str(wxCFRetain(cfstr)); return str.AsString(); }