mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-13 00:33:09 -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
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonDocument>
|
||||
|
@ -112,6 +113,22 @@ namespace
|
|||
|
||||
return u"no-store"_qs;
|
||||
}
|
||||
|
||||
QString createLanguagesOptionsHtml()
|
||||
{
|
||||
// List language files
|
||||
const QDir langDir {u":/www/translations"_qs};
|
||||
const QStringList langFiles = langDir.entryList(QStringList(u"webui_*.qm"_qs), QDir::Files);
|
||||
QStringList languages;
|
||||
for (const QString &langFile : langFiles)
|
||||
{
|
||||
const QString localeStr = langFile.section(u"_"_qs, 1, -1).section(u"."_qs, 0, 0); // remove "webui_" and ".qm"
|
||||
languages << u"<option value=\"%1\">%2</option>"_qs.arg(localeStr, Utils::Misc::languageToLocalizedString(localeStr));
|
||||
qDebug() << "Supported locale:" << localeStr;
|
||||
}
|
||||
|
||||
return languages.join(u'\n');
|
||||
}
|
||||
}
|
||||
|
||||
WebApplication::WebApplication(IApplication *app, QObject *parent)
|
||||
|
@ -472,13 +489,17 @@ void WebApplication::sendFile(const Path &path)
|
|||
const QMimeType mimeType = QMimeDatabase().mimeTypeForFileNameAndData(path.data(), data);
|
||||
const bool isTranslatable = !m_isAltUIUsed && mimeType.inherits(u"text/plain"_qs);
|
||||
|
||||
// Translate the file
|
||||
if (isTranslatable)
|
||||
{
|
||||
auto dataStr = QString::fromUtf8(data);
|
||||
// Translate the file
|
||||
translateDocument(dataStr);
|
||||
data = dataStr.toUtf8();
|
||||
|
||||
// Add the language options
|
||||
if (path == (m_rootFolder / Path(PRIVATE_FOLDER) / Path(u"views/preferences.html"_qs)))
|
||||
dataStr.replace(u"${LANGUAGE_OPTIONS}"_qs, createLanguagesOptionsHtml());
|
||||
|
||||
data = dataStr.toUtf8();
|
||||
m_translatedFiles[path] = {data, mimeType.name(), lastModified}; // caching translated file
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue