static QByteArray getWinLocaleName(LCID id) { QByteArray result; if (id == LOCALE_USER_DEFAULT) { static QByteArray langEnvVar = qgetenv("LANG"); result = langEnvVar; QString lang, script, cntry; if ( result == "C" || (!result.isEmpty() && qt_splitLocaleName(QString::fromLocal8Bit(result), lang, script, cntry)) ) { 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 defined(Q_OS_WINCE) result = winLangCodeToIsoName(id != LOCALE_USER_DEFAULT ? id : GetUserDefaultLCID()); #else if (id == LOCALE_USER_DEFAULT) id = GetUserDefaultLCID(); QString resultuage = winIso639LangName(id); QString country = winIso3116CtryName(id); result = resultuage.toLatin1(); if (!country.isEmpty()) { result += '_'; result += country.toLatin1(); } #endif return result; }
QVariant QSystemLocale::query(QueryType type, QVariant in) const { QSystemLocaleData *d = qSystemLocaleData(); if (type == LocaleChanged) { d->readEnvironment(); return QVariant(); } QReadLocker locker(&d->lock); const QLocale &lc_numeric = d->lc_numeric; const QLocale &lc_time = d->lc_time; const QLocale &lc_monetary = d->lc_monetary; const QLocale &lc_messages = d->lc_messages; switch (type) { case DecimalPoint: return lc_numeric.decimalPoint(); case GroupSeparator: return lc_numeric.groupSeparator(); case ZeroDigit: return lc_numeric.zeroDigit(); case NegativeSign: return lc_numeric.negativeSign(); case DateFormatLong: return lc_time.dateFormat(QLocale::LongFormat); case DateFormatShort: return lc_time.dateFormat(QLocale::ShortFormat); case TimeFormatLong: return lc_time.timeFormat(QLocale::LongFormat); case TimeFormatShort: return lc_time.timeFormat(QLocale::ShortFormat); case DayNameLong: return lc_time.dayName(in.toInt(), QLocale::LongFormat); case DayNameShort: return lc_time.dayName(in.toInt(), QLocale::ShortFormat); case MonthNameLong: return lc_time.monthName(in.toInt(), QLocale::LongFormat); case MonthNameShort: return lc_time.monthName(in.toInt(), QLocale::ShortFormat); case StandaloneMonthNameLong: return lc_time.standaloneMonthName(in.toInt(), QLocale::LongFormat); case StandaloneMonthNameShort: return lc_time.standaloneMonthName(in.toInt(), QLocale::ShortFormat); case DateToStringLong: return lc_time.toString(in.toDate(), QLocale::LongFormat); case DateToStringShort: return lc_time.toString(in.toDate(), QLocale::ShortFormat); case TimeToStringLong: return lc_time.toString(in.toTime(), QLocale::LongFormat); case TimeToStringShort: return lc_time.toString(in.toTime(), QLocale::ShortFormat); case DateTimeFormatLong: return lc_time.dateTimeFormat(QLocale::LongFormat); case DateTimeFormatShort: return lc_time.dateTimeFormat(QLocale::ShortFormat); case DateTimeToStringLong: return lc_time.toString(in.toDateTime(), QLocale::LongFormat); case DateTimeToStringShort: return lc_time.toString(in.toDateTime(), QLocale::ShortFormat); case PositiveSign: return lc_numeric.positiveSign(); case AMText: return lc_time.amText(); case PMText: return lc_time.pmText(); case FirstDayOfWeek: return lc_time.firstDayOfWeek(); case CurrencySymbol: return lc_monetary.currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt())); case CurrencyToString: { switch (in.type()) { case QVariant::Int: return lc_monetary.toCurrencyString(in.toInt()); case QVariant::UInt: return lc_monetary.toCurrencyString(in.toUInt()); case QVariant::Double: return lc_monetary.toCurrencyString(in.toDouble()); case QVariant::LongLong: return lc_monetary.toCurrencyString(in.toLongLong()); case QVariant::ULongLong: return lc_monetary.toCurrencyString(in.toULongLong()); default: break; } return QString(); } case MeasurementSystem: { const QString meas_locale = QString::fromLatin1(d->lc_measurement_var.constData(), d->lc_measurement_var.size()); if (meas_locale.compare(QLatin1String("Metric"), Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; if (meas_locale.compare(QLatin1String("Other"), Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; return QVariant((int)QLocale(meas_locale).measurementSystem()); } case UILanguages: { if (!d->uiLanguages.isEmpty()) return d->uiLanguages; QString languages = QString::fromLatin1(qgetenv("LANGUAGE")); QStringList lst; if (languages.isEmpty()) lst.append(QString::fromLatin1(d->lc_messages_var)); else lst = languages.split(QLatin1Char(':')); for (int i = 0; i < lst.size(); ++i) { const QString &name = lst.at(i); QString lang, script, cntry; if (qt_splitLocaleName(name, lang, script, cntry)) { if (!cntry.length()) d->uiLanguages.append(lang); else d->uiLanguages.append(lang % QLatin1Char('-') % cntry); } } return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages); } case StringToStandardQuotation: return lc_messages.quoteString(in.value<QStringRef>()); case StringToAlternateQuotation: return lc_messages.quoteString(in.value<QStringRef>(), QLocale::AlternateQuotation); case ListToSeparatedString: return lc_messages.createSeparatedList(in.toStringList()); case LocaleChanged: Q_ASSERT(false); default: break; } return QVariant(); }