mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 05:48:47 +03:00
Apply locale changes immediately in WebUI
This commit is contained in:
parent
2230d96705
commit
92a4e73a22
2 changed files with 12 additions and 5 deletions
|
@ -95,15 +95,15 @@ namespace
|
|||
return ret;
|
||||
}
|
||||
|
||||
void translateDocument(QString &data)
|
||||
void translateDocument(const QString &locale, QString &data)
|
||||
{
|
||||
const QRegExp regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR(\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\])");
|
||||
const QRegExp mnemonic("\\(?&([a-zA-Z]?\\))?");
|
||||
int i = 0;
|
||||
bool found = true;
|
||||
|
||||
const QString locale = Preferences::instance()->getLocale();
|
||||
bool isTranslationNeeded = !locale.startsWith("en") || locale.startsWith("en_AU") || locale.startsWith("en_GB");
|
||||
bool isTranslationNeeded = !locale.startsWith("en")
|
||||
|| locale.startsWith("en_AU") || locale.startsWith("en_GB");
|
||||
|
||||
while (i < data.size() && found) {
|
||||
i = regex.indexIn(data, i);
|
||||
|
@ -420,7 +420,7 @@ void WebApplication::configure()
|
|||
{
|
||||
const auto pref = Preferences::instance();
|
||||
|
||||
m_domainList = Preferences::instance()->getServerDomains().split(';', QString::SkipEmptyParts);
|
||||
m_domainList = pref->getServerDomains().split(';', QString::SkipEmptyParts);
|
||||
std::for_each(m_domainList.begin(), m_domainList.end(), [](QString &entry) { entry = entry.trimmed(); });
|
||||
|
||||
const QString rootFolder = Utils::Fs::expandPathAbs(
|
||||
|
@ -429,6 +429,12 @@ void WebApplication::configure()
|
|||
m_translatedFiles.clear();
|
||||
m_rootFolder = rootFolder;
|
||||
}
|
||||
|
||||
const QString newLocale = pref->getLocale();
|
||||
if (m_currentLocale != newLocale) {
|
||||
m_currentLocale = newLocale;
|
||||
m_translatedFiles.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void WebApplication::registerAPIController(const QString &scope, APIController *controller)
|
||||
|
@ -476,7 +482,7 @@ void WebApplication::sendFile(const QString &path)
|
|||
// Translate the file
|
||||
if (isTranslatable) {
|
||||
QString dataStr {data};
|
||||
translateDocument(dataStr);
|
||||
translateDocument(m_currentLocale, dataStr);
|
||||
data = dataStr.toUtf8();
|
||||
|
||||
m_translatedFiles[path] = {data, lastModified}; // caching translated file
|
||||
|
|
|
@ -141,4 +141,5 @@ private:
|
|||
QDateTime lastModified;
|
||||
};
|
||||
QMap<QString, TranslatedFile> m_translatedFiles;
|
||||
QString m_currentLocale;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue