summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2011-03-29 10:50:24 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2011-03-29 15:18:07 (GMT)
commit7590288fd6419159116f4392389cb8ca9691fb06 (patch)
treed38121cbb3bb2ea41cbdc7b1b2ae97f3875f7aec /src
parent335fdd66947adadcdaaeb2896c42fba28d67843a (diff)
downloadQt-7590288fd6419159116f4392389cb8ca9691fb06.zip
Qt-7590288fd6419159116f4392389cb8ca9691fb06.tar.gz
Qt-7590288fd6419159116f4392389cb8ca9691fb06.tar.bz2
Added native language and country names (endonyms) to QLocale.
Task-number: QTBUG-17092 Reviewed-by: Zeno Albisser Reviewed-by: Liang Qi
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlocale.cpp40
-rw-r--r--src/corelib/tools/qlocale.h6
-rw-r--r--src/corelib/tools/qlocale_p.h3
-rw-r--r--src/corelib/tools/qlocale_win.cpp27
4 files changed, 75 insertions, 1 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index af95a75..197c742 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -3224,4 +3224,44 @@ QStringList QLocale::uiLanguages() const
return QStringList(bcp47Name());
}
+/*!
+ \since 4.8
+
+ Returns a native name of the language for the locale. For example
+ "Schwiizertüütsch" for Swiss-German locale.
+
+ \sa nativeCountryName(), languageToString()
+*/
+QString QLocale::nativeLanguageName() const
+{
+#ifndef QT_NO_SYSTEMLOCALE
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(QSystemLocale::NativeLanguageName, QVariant());
+ if (!res.isNull())
+ return res.toString();
+ }
+#endif
+ return getLocaleData(endonyms_data + d()->m_language_endonym_idx, d()->m_language_endonym_size);
+}
+
+/*!
+ \since 4.8
+
+ Returns a native name of the country for the locale. For example
+ "España" for Spanish/Spain locale.
+
+ \sa nativeLanguageName(), countryToString()
+*/
+QString QLocale::nativeCountryName() const
+{
+#ifndef QT_NO_SYSTEMLOCALE
+ if (d() == systemPrivate()) {
+ QVariant res = systemLocale()->query(QSystemLocale::NativeCountryName, QVariant());
+ if (!res.isNull())
+ return res.toString();
+ }
+#endif
+ return getLocaleData(endonyms_data + d()->m_country_endonym_idx, d()->m_country_endonym_size);
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
index 4ac7630..9f44e30 100644
--- a/src/corelib/tools/qlocale.h
+++ b/src/corelib/tools/qlocale.h
@@ -114,7 +114,9 @@ public:
StringToAlternateQuotation, // QString in: QStringRef to quote
ScriptId, // uint
ListToSeparatedString, // QString
- LocaleChanged // system locale changed
+ LocaleChanged, // system locale changed
+ NativeLanguageName, // QString
+ NativeCountryName // QString
};
virtual QVariant query(QueryType type, QVariant in) const;
virtual QLocale fallbackLocale() const;
@@ -658,6 +660,8 @@ public:
QString name() const;
QString bcp47Name() const;
+ QString nativeLanguageName() const;
+ QString nativeCountryName() const;
short toShort(const QString &s, bool *ok = 0, int base = 0) const;
ushort toUShort(const QString &s, bool *ok = 0, int base = 0) const;
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index e600807..1b31929 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -211,11 +211,14 @@ public:
quint16 m_currency_display_name_idx, m_currency_display_name_size;
quint8 m_currency_format_idx, m_currency_format_size;
quint8 m_currency_negative_format_idx, m_currency_negative_format_size;
+ quint16 m_language_endonym_idx, m_language_endonym_size;
+ quint16 m_country_endonym_idx, m_country_endonym_size;
quint16 m_currency_digits : 2;
quint16 m_currency_rounding : 3;
quint16 m_first_day_of_week : 3;
quint16 m_weekend_start : 3;
quint16 m_weekend_end : 3;
+
};
inline char QLocalePrivate::digitToCLocale(const QChar &in) const
diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp
index 0c2d039..3325419 100644
--- a/src/corelib/tools/qlocale_win.cpp
+++ b/src/corelib/tools/qlocale_win.cpp
@@ -76,6 +76,12 @@ static QString winIso3116CtryName(LCID id = LOCALE_USER_DEFAULT);
# define LOCALE_SSHORTESTDAYNAME6 0x0065
# define LOCALE_SSHORTESTDAYNAME7 0x0066
#endif
+#ifndef LOCALE_SNATIVELANGUAGENAME
+# define LOCALE_SNATIVELANGUAGENAME 0x00000004
+#endif
+#ifndef LOCALE_SNATIVECOUNTRYNAME
+# define LOCALE_SNATIVECOUNTRYNAME 0x00000008
+#endif
struct QSystemLocalePrivate
{
@@ -101,6 +107,8 @@ struct QSystemLocalePrivate
QVariant currencySymbol(QLocale::CurrencySymbolFormat);
QVariant toCurrencyString(const QSystemLocale::CurrencyToStringArgument &);
QVariant uiLanguages();
+ QVariant nativeLanguageName();
+ QVariant nativeCountryName();
void update();
@@ -559,6 +567,21 @@ QVariant QSystemLocalePrivate::uiLanguages()
return QStringList(QString::fromLatin1(winLangCodeToIsoName(GetUserDefaultUILanguage())));
}
+QVariant QSystemLocalePrivate::nativeLanguageName()
+{
+ if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS7)
+ return getLocaleInfo(LOCALE_SNATIVELANGNAME);
+ return getLocaleInfo(LOCALE_SNATIVELANGUAGENAME);
+}
+
+QVariant QSystemLocalePrivate::nativeCountryName()
+{
+ if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS7)
+ return getLocaleInfo(LOCALE_SNATIVECTRYNAME);
+ return getLocaleInfo(LOCALE_SNATIVECOUNTRYNAME);
+}
+
+
void QSystemLocalePrivate::update()
{
lcid = GetUserDefaultLCID();
@@ -713,6 +736,10 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const
case LocaleChanged:
d->update();
break;
+ case NativeLanguageName:
+ return d->nativeLanguageName();
+ case NativeCountryName:
+ return d->nativeCountryName();
default:
break;
}