📄 qlocale.cpp
字号:
{ 0x280a, "es_PE" }, { 0x2c01, "ar_JO" }, { 0x2c09, "en_TT" }, { 0x2c0a, "es_AR" }, { 0x3001, "ar_LB" }, { 0x300a, "es_EC" }, { 0x3401, "ar_KW" }, { 0x340a, "es_CL" }, { 0x3801, "ar_AE" }, { 0x380a, "es_UY" }, { 0x3c01, "ar_BH" }, { 0x3c0a, "es_PY" }, { 0x4001, "ar_QA" }, { 0x400a, "es_BO" }, { 0x440a, "es_SV" }, { 0x480a, "es_HN" }, { 0x4c0a, "es_NI" }, { 0x500a, "es_PR" }};static const int windows_to_iso_count = sizeof(windows_to_iso_list)/sizeof(WindowsToISOListElt);static const char *winLangCodeToIsoName(int code){ int cmp = code - windows_to_iso_list[0].windows_code; if (cmp < 0) return 0; if (cmp == 0) return windows_to_iso_list[0].iso_name; int begin = 0; int end = windows_to_iso_count; while (end - begin > 1) { uint mid = (begin + end)/2; const WindowsToISOListElt *elt = windows_to_iso_list + mid; int cmp = code - elt->windows_code; if (cmp < 0) end = mid; else if (cmp > 0) begin = mid; else return elt->iso_name; } return 0;}static QString winIso639LangName(){ QString result; // Windows returns the wrong ISO639 for some languages, we need to detect them here using // the language code QString lang_code; QT_WA({ TCHAR out[256]; if (GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, out, 255)) lang_code = QString::fromUtf16((ushort*)out); } , { char out[256]; if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, out, 255)) lang_code = QString::fromLocal8Bit(out); }); if (!lang_code.isEmpty()) { const char *endptr; bool ok; QByteArray latin1_lang_code = lang_code.toLatin1(); int i = qstrtoull(latin1_lang_code, &endptr, 16, &ok); if (ok && *endptr == '\0') { switch (i) { case 0x814: result = QLatin1String("nn"); // Nynorsk break; default: break; } } } if (!result.isEmpty()) return result; // not one of the problematic languages - do the usual lookup QT_WA({ TCHAR out[256]; if (GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME , out, 255)) result = QString::fromUtf16((ushort*)out); } , { char out[256]; if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, out, 255)) result = QString::fromLocal8Bit(out); }); return result;}static QString winIso3116CtryName(){ QString result; QT_WA({ TCHAR out[256]; if (GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, out, 255)) result = QString::fromUtf16((ushort*)out); } , { char out[256]; if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, out, 255)) result = QString::fromLocal8Bit(out); }); return result;}#endif // Q_OS_WINstatic QByteArray envVarLocale(){ static QByteArray lang = 0;#ifdef Q_OS_UNIX lang = qgetenv("LC_ALL"); if (lang.isNull()) lang = qgetenv("LC_NUMERIC"); if (lang.isNull())#endif lang = qgetenv("LANG"); return lang;}QByteArray QLocalePrivate::systemLocaleName(){ QByteArray result = envVarLocale();#if defined(Q_OS_MAC) if (!result.isEmpty()) return result;#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_3) { QCFType<CFLocaleRef> l = CFLocaleCopyCurrent(); CFStringRef locale = CFLocaleGetIdentifier(l); result = QCFString::toQString(locale).toLatin1(); } else#endif { char mac_ret[255]; if(!LocaleRefGetPartString(NULL, kLocaleLanguageMask | kLocaleRegionMask, 255, mac_ret)) { result = mac_ret; } }#endif#if defined(Q_WS_WIN) if ( !result.isEmpty() ) { long id = 0; bool ok = false; id = qstrtoll(result.data(), 0, 0, &ok); if ( !ok || id == 0 || id < INT_MIN || id > INT_MAX ) return result; else return winLangCodeToIsoName( (int)id ); } if (QSysInfo::WindowsVersion == QSysInfo::WV_95) { result = winLangCodeToIsoName(GetUserDefaultLangID()); } else { QString resultuage = winIso639LangName(); QString country = winIso3116CtryName(); result += resultuage.toLatin1(); if (!country.isEmpty()) { result += '_'; result += country.toLatin1(); } }#endif if (result.isEmpty()) result = "C"; return result;}/*! \class QLocale \brief The QLocale class converts between numbers and their string representations in various languages. \reentrant \ingroup i18n \ingroup text \mainclass QLocale is initialized with a language/country pair in its constructor and offers number-to-string and string-to-number conversion functions similar to those in QString. Example: \code QLocale egyptian(QLocale::Arabic, QLocale::Egypt); QString s1 = egyptian.toString(1.571429E+07, 'e'); QString s2 = egyptian.toString(10); double d = egyptian.toDouble(s1); int i = egyptian.toInt(s2); \endcode QLocale supports the concept of a default locale, which is determined from the system's locale settings at application startup. The default locale can be changed by calling the static member setDefault(). Setting the default locale has the following effects: \list \i If a QLocale object is constructed with the default constructor, it will use the default locale's settings. \i QString::toInt(), QString::toDouble(), etc., interpret the string according to the default locale. If this fails, it falls back on the "C" locale. \i QString::arg() uses the default locale to format a number when its position specifier in the format string contains an 'L', e.g. "%L1". \endlist The following example illustrates how to use QLocale directly: \code QLocale::setDefault(QLocale::Hebrew, QLocale::Israel); QLocale hebrew; // Constructs a default QLocale QString s1 = hebrew.toString(15714.3, 'e'); bool ok; double d; QLocale::setDefault(QLocale::C); d = QString("1234,56").toDouble(&ok); // ok == false d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 QLocale::setDefault(QLocale::German); d = QString("1234,56").toDouble(&ok); // ok == true, d == 1234.56 d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 QLocale::setDefault(QLocale::English, QLocale::UnitedStates); str = QString("%1 %L2 %L3") .arg(12345).arg(12345).arg(12345, 0, 16); // str == "12345 12,345 3039" \endcode When a language/country pair is specified in the constructor, one of three things can happen: \list \i If the language/country pair is found in the database, it is used. \i If the language is found but the country is not, or if the country is \c AnyCountry, the language is used with the most appropriate available country (for example, Germany for German), \i If neither the language nor the country are found, QLocale defaults to the default locale (see setDefault()). \endlist The "C" locale is identical to \l{English}/\l{UnitedStates}. Use language() and country() to determine the actual language and country values used. An alternative method for constructing a QLocale object is by specifying the locale name. \code QLocale korean("ko"); QLocale swiss("de_CH"); \endcode This constructor converts the locale name to a language/country pair; it does not use the system locale database. The double-to-string and string-to-double conversion functions are covered by the following licenses: \legalese Copyright (c) 1991 by AT&T. Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software. THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. This product includes software developed by the University of California, Berkeley and its contributors. \sa QString::arg(), QString::toInt(), QString::toDouble()*//*! \enum QLocale::Language This enumerated type is used to specify a language. \value C \value Abkhazian \value Afan \value Afar \value Afrikaans \value Albanian \value Amharic \value Arabic \value Armenian \value Assamese \value Aymara \value Azerbaijani \value Bashkir \value Basque \value Bengali \value Bhutani \value Bihari \value Bislama \value Bosnian \value Breton \value Bulgarian \value Burmese \value Byelorussian \value Cambodian \value Catalan \value Chinese \value Cornish \value Corsican \value Croatian \value Czech \value Danish \value Divehi \value Dutch \value English \value Esperanto \value Estonian \value Faroese \value FijiLanguage \value Finnish \value French \value Frisian \value Gaelic \value Galician \value Georgian \value German \value Greek \value Greenlandic \value Guarani \value Gujarati \value Hausa \value Hebrew \value Hindi \value Hungarian \value Icelandic \value Indonesian \value Interlingua \value Interlingue \value Inuktitut \value Inupiak \value Irish \value Italian \value Japanese \value Javanese \value Kannada \value Kashmiri \value Kazakh \value Kinyarwanda \value Kirghiz \value Korean \value Kurdish \value Kurundi \value Laothian \value Latin \value Latvian \value Lingala \value Lithuanian \value Macedonian \value Malagasy \value Malay \value Malayalam \value Maltese \value Manx \value Maori \value Marathi \value Moldavian \value Mongolian \value NauruLanguage \value Nepali \value Norwegian \value Nynorsk \value Occitan \value Oriya \value Pashto \value Persian \value Polish \value Portuguese \value Punjabi \value Quechua \value RhaetoRomance \value Romanian \value Russian \value Samoan \value Sangho \value Sanskrit \value Serbian \value SerboCroatian \value Sesotho \value Setswana \value Shona \value Sindhi \value Singhalese \value Siswati \value Slovak \value Slovenian \value Somali \value Spanish \value Sundanese \value Swahili \value Swedish \value Tagalog \value Tajik \value Tamil \value Tatar \value Telugu \value Thai \value Tibetan \value Tigrinya \value TongaLanguage \value Tsonga \value Turkish \value Turkmen \value Twi \value Uigur \value Ukrainian \value Urdu \value Uzbek \value Vietnamese \value Volapuk \value Welsh \value Wolof \value Xhosa \value Yiddish \value Yoruba \value Zhuang \value Zulu \omitvalue LastLanguage \sa language()*//*! \enum QLocale::Country This enumerated type is used to specify a country. \value AnyCountry \value Afghanistan \value Albania \value Algeria \value AmericanSamoa
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -