mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-10 23:42:46 -07:00
Unify the way to generate the language list in WebUI and GUI
PR #17994.
This commit is contained in:
parent
c5a4a0db2c
commit
b33dc7d831
5 changed files with 133 additions and 154 deletions
|
@ -53,6 +53,8 @@
|
|||
#include <zlib.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QLocale>
|
||||
#include <QMimeDatabase>
|
||||
#include <QRegularExpression>
|
||||
#include <QSet>
|
||||
|
@ -403,6 +405,94 @@ QString Utils::Misc::getUserIDString()
|
|||
return uid;
|
||||
}
|
||||
|
||||
QString Utils::Misc::languageToLocalizedString(const QString &localeStr)
|
||||
{
|
||||
if (localeStr.startsWith(u"eo", Qt::CaseInsensitive))
|
||||
{
|
||||
// QLocale doesn't work with that locale. Esperanto isn't a "real" language.
|
||||
return C_LOCALE_ESPERANTO;
|
||||
}
|
||||
|
||||
if (localeStr.startsWith(u"ltg", Qt::CaseInsensitive))
|
||||
{
|
||||
// QLocale doesn't work with that locale.
|
||||
return C_LOCALE_LATGALIAN;
|
||||
}
|
||||
|
||||
const QLocale locale {localeStr};
|
||||
switch (locale.language())
|
||||
{
|
||||
case QLocale::Arabic: return C_LOCALE_ARABIC;
|
||||
case QLocale::Armenian: return C_LOCALE_ARMENIAN;
|
||||
case QLocale::Azerbaijani: return C_LOCALE_AZERBAIJANI;
|
||||
case QLocale::Basque: return C_LOCALE_BASQUE;
|
||||
case QLocale::Bulgarian: return C_LOCALE_BULGARIAN;
|
||||
case QLocale::Byelorussian: return C_LOCALE_BYELORUSSIAN;
|
||||
case QLocale::Catalan: return C_LOCALE_CATALAN;
|
||||
case QLocale::Chinese:
|
||||
switch (locale.country())
|
||||
{
|
||||
case QLocale::China: return C_LOCALE_CHINESE_SIMPLIFIED;
|
||||
case QLocale::HongKong: return C_LOCALE_CHINESE_TRADITIONAL_HK;
|
||||
default: return C_LOCALE_CHINESE_TRADITIONAL_TW;
|
||||
}
|
||||
case QLocale::Croatian: return C_LOCALE_CROATIAN;
|
||||
case QLocale::Czech: return C_LOCALE_CZECH;
|
||||
case QLocale::Danish: return C_LOCALE_DANISH;
|
||||
case QLocale::Dutch: return C_LOCALE_DUTCH;
|
||||
case QLocale::English:
|
||||
switch (locale.country())
|
||||
{
|
||||
case QLocale::Australia: return C_LOCALE_ENGLISH_AUSTRALIA;
|
||||
case QLocale::UnitedKingdom: return C_LOCALE_ENGLISH_UNITEDKINGDOM;
|
||||
default: return C_LOCALE_ENGLISH;
|
||||
}
|
||||
case QLocale::Estonian: return C_LOCALE_ESTONIAN;
|
||||
case QLocale::Finnish: return C_LOCALE_FINNISH;
|
||||
case QLocale::French: return C_LOCALE_FRENCH;
|
||||
case QLocale::Galician: return C_LOCALE_GALICIAN;
|
||||
case QLocale::Georgian: return C_LOCALE_GEORGIAN;
|
||||
case QLocale::German: return C_LOCALE_GERMAN;
|
||||
case QLocale::Greek: return C_LOCALE_GREEK;
|
||||
case QLocale::Hebrew: return C_LOCALE_HEBREW;
|
||||
case QLocale::Hindi: return C_LOCALE_HINDI;
|
||||
case QLocale::Hungarian: return C_LOCALE_HUNGARIAN;
|
||||
case QLocale::Icelandic: return C_LOCALE_ICELANDIC;
|
||||
case QLocale::Indonesian: return C_LOCALE_INDONESIAN;
|
||||
case QLocale::Italian: return C_LOCALE_ITALIAN;
|
||||
case QLocale::Japanese: return C_LOCALE_JAPANESE;
|
||||
case QLocale::Korean: return C_LOCALE_KOREAN;
|
||||
case QLocale::Latvian: return C_LOCALE_LATVIAN;
|
||||
case QLocale::Lithuanian: return C_LOCALE_LITHUANIAN;
|
||||
case QLocale::Malay: return C_LOCALE_MALAY;
|
||||
case QLocale::Mongolian: return C_LOCALE_MONGOLIAN;
|
||||
case QLocale::NorwegianBokmal: return C_LOCALE_NORWEGIAN;
|
||||
case QLocale::Occitan: return C_LOCALE_OCCITAN;
|
||||
case QLocale::Persian: return C_LOCALE_PERSIAN;
|
||||
case QLocale::Polish: return C_LOCALE_POLISH;
|
||||
case QLocale::Portuguese:
|
||||
if (locale.country() == QLocale::Brazil)
|
||||
return C_LOCALE_PORTUGUESE_BRAZIL;
|
||||
return C_LOCALE_PORTUGUESE;
|
||||
case QLocale::Romanian: return C_LOCALE_ROMANIAN;
|
||||
case QLocale::Russian: return C_LOCALE_RUSSIAN;
|
||||
case QLocale::Serbian: return C_LOCALE_SERBIAN;
|
||||
case QLocale::Slovak: return C_LOCALE_SLOVAK;
|
||||
case QLocale::Slovenian: return C_LOCALE_SLOVENIAN;
|
||||
case QLocale::Spanish: return C_LOCALE_SPANISH;
|
||||
case QLocale::Swedish: return C_LOCALE_SWEDISH;
|
||||
case QLocale::Thai: return C_LOCALE_THAI;
|
||||
case QLocale::Turkish: return C_LOCALE_TURKISH;
|
||||
case QLocale::Ukrainian: return C_LOCALE_UKRAINIAN;
|
||||
case QLocale::Uzbek: return C_LOCALE_UZBEK;
|
||||
case QLocale::Vietnamese: return C_LOCALE_VIETNAMESE;
|
||||
default:
|
||||
const QString lang = QLocale::languageToString(locale.language());
|
||||
qWarning() << "Unrecognized language name: " << lang;
|
||||
return lang;
|
||||
}
|
||||
}
|
||||
|
||||
QString Utils::Misc::parseHtmlLinks(const QString &rawText)
|
||||
{
|
||||
QString result = rawText;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue