forked from qt-creator/qt-creator
Multilanguage: Add utility to get language names consistently
There are multiple places that language codes are converted to language names each doing it a different way. To make this consistent, we need to have a single implementation for it. Change-Id: I2aeaf5b7c9203e8a41a61420f4c98e1fce491db5 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <QDir>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
#include <QLocale>
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
#include <QTime>
|
||||
@@ -464,4 +465,16 @@ QString wildcardToRegularExpression(const QString &original)
|
||||
return "\\A" + rx + "\\z";
|
||||
#endif
|
||||
}
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QString languageNameFromLanguageCode(const QString &languageCode)
|
||||
{
|
||||
QLocale locale(languageCode);
|
||||
QString languageName = QLocale::languageToString(locale.language());
|
||||
QString nativeLanguageName = locale.nativeLanguageName().simplified();
|
||||
|
||||
if (!nativeLanguageName.isEmpty() && languageName != nativeLanguageName)
|
||||
languageName += " - " + locale.nativeLanguageName();
|
||||
return languageName;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -121,4 +121,7 @@ QTCREATOR_UTILS_EXPORT QString formatElapsedTime(qint64 elapsed);
|
||||
* into account and handling them to disallow matching a wildcard characters.
|
||||
*/
|
||||
QTCREATOR_UTILS_EXPORT QString wildcardToRegularExpression(const QString &original);
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QString languageNameFromLanguageCode(const QString &languageCode);
|
||||
|
||||
} // namespace Utils
|
||||
|
Reference in New Issue
Block a user