mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-08 06:00:59 -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
|
@ -52,8 +52,8 @@
|
|||
#include "base/rss/rss_session.h"
|
||||
#include "base/torrentfileguard.h"
|
||||
#include "base/torrentfileswatcher.h"
|
||||
#include "base/unicodestrings.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/utils/net.h"
|
||||
#include "base/utils/password.h"
|
||||
#include "base/utils/random.h"
|
||||
|
@ -89,81 +89,6 @@ namespace
|
|||
return ret;
|
||||
}
|
||||
|
||||
QString languageToLocalizedString(const QLocale &locale)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
class WheelEventEater final : public QObject
|
||||
{
|
||||
public:
|
||||
|
@ -1326,25 +1251,8 @@ void OptionsDialog::initializeLanguageCombo()
|
|||
const QStringList langFiles = langDir.entryList(QStringList(u"qbittorrent_*.qm"_qs), QDir::Files);
|
||||
for (const QString &langFile : langFiles)
|
||||
{
|
||||
QString localeStr = langFile.mid(12); // remove "qbittorrent_"
|
||||
localeStr.chop(3); // Remove ".qm"
|
||||
QString languageName;
|
||||
if (localeStr.startsWith(u"eo", Qt::CaseInsensitive))
|
||||
{
|
||||
// QLocale doesn't work with that locale. Esperanto isn't a "real" language.
|
||||
languageName = C_LOCALE_ESPERANTO;
|
||||
}
|
||||
else if (localeStr.startsWith(u"ltg", Qt::CaseInsensitive))
|
||||
{
|
||||
// QLocale doesn't work with that locale.
|
||||
languageName = C_LOCALE_LATGALIAN;
|
||||
}
|
||||
else
|
||||
{
|
||||
QLocale locale(localeStr);
|
||||
languageName = languageToLocalizedString(locale);
|
||||
}
|
||||
m_ui->comboI18n->addItem(/*QIcon(":/icons/flags/"+country+".svg"), */ languageName, localeStr);
|
||||
const QString localeStr = langFile.section(u"_"_qs, 1, -1).section(u"."_qs, 0, 0); // remove "qbittorrent_" and ".qm"
|
||||
m_ui->comboI18n->addItem(/*QIcon(":/icons/flags/"+country+".svg"), */ Utils::Misc::languageToLocalizedString(localeStr), localeStr);
|
||||
qDebug() << "Supported locale:" << localeStr;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue