From 4d2f02ac45ae6f1c1a9605c4954eea0a34a1c2b2 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 26 Feb 2018 21:52:39 +0100 Subject: [PATCH] Remove option to change language on per-profile basis System locale is now always used. --- src/lib/app/mainapplication.cpp | 76 ------------------------- src/lib/app/mainapplication.h | 7 --- src/lib/plugins/plugins.cpp | 5 +- src/lib/preferences/preferences.cpp | 37 ------------ src/lib/preferences/preferences.ui | 44 +------------- src/lib/preferences/thememanager.cpp | 4 +- src/lib/tools/certificateinfowidget.cpp | 2 +- src/lib/tools/desktopfile.cpp | 26 ++++++--- src/lib/tools/desktopfile.h | 6 +- src/lib/webengine/webview.cpp | 4 +- 10 files changed, 31 insertions(+), 180 deletions(-) diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index a985e6058..35ec95d61 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -305,7 +305,6 @@ MainApplication::MainApplication(int &argc, char** argv) m_restoreManager = new RestoreManager(sessionManager()->askSessionFromUser()); } - translateApp(); loadSettings(); m_plugins = new PluginProxy(this); @@ -489,22 +488,6 @@ void MainApplication::setProxyStyle(ProxyStyle *style) setStyle(style); } -QString MainApplication::currentLanguageFile() const -{ - return m_languageFile; -} - -QString MainApplication::currentLanguage() const -{ - QString lang = m_languageFile; - - if (lang.isEmpty()) { - return "en_US"; - } - - return lang.left(lang.length() - 3); -} - History* MainApplication::history() { if (!m_history) { @@ -1023,65 +1006,6 @@ void MainApplication::loadTheme(const QString &name) setStyleSheet(qss); } -void MainApplication::translateApp() -{ - QString file = Settings().value(QSL("Language/language"), QLocale::system().name()).toString(); - - // It can only be "C" locale, for which we will use default English language - if (file.size() < 2) - file.clear(); - - if (!file.isEmpty() && !file.endsWith(QL1S(".qm"))) - file.append(QL1S(".qm")); - - // Either we load default language (with empty file), or we attempt to load xx.qm (xx_yy.qm) - Q_ASSERT(file.isEmpty() || file.size() >= 5); - - QString translationPath = DataPaths::path(DataPaths::Translations); - - if (!file.isEmpty()) { - const QStringList translationsPaths = DataPaths::allPaths(DataPaths::Translations); - - foreach (const QString &path, translationsPaths) { - // If "xx_yy" translation doesn't exists, try to use "xx*" translation - // It can only happen when language is chosen from system locale - - if (!QFile(QString("%1/%2").arg(path, file)).exists()) { - QDir dir(path); - QString lang = file.left(2) + QL1S("*.qm"); - - const QStringList translations = dir.entryList(QStringList(lang)); - - // If no translation can be found, default English will be used - file = translations.isEmpty() ? QString() : translations.at(0); - } - - if (!file.isEmpty() && QFile(QString("%1/%2").arg(path, file)).exists()) { - translationPath = path; - break; - } - } - } - - // Load application translation - QTranslator* app = new QTranslator(this); - app->load(file, translationPath); - - // Load Qt translation (first try to load from Qt path) - QTranslator* sys = new QTranslator(this); - sys->load(QL1S("qt_") + file, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); - - // If there is no translation in Qt path for specified language, try to load it from our path - if (sys->isEmpty()) { - sys->load(QL1S("qt_") + file, translationPath); - } - - m_languageFile = file; - - installTranslator(app); - installTranslator(sys); -} - void MainApplication::checkDefaultWebBrowser() { if (isPortable()) { diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index c672ec67f..b6dca475b 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -91,9 +91,6 @@ public: QString styleName() const; void setProxyStyle(ProxyStyle *style); - QString currentLanguageFile() const; - QString currentLanguage() const; - History* history(); Bookmarks* bookmarks(); @@ -157,8 +154,6 @@ private: void loadSettings(); void loadTheme(const QString &name); - void translateApp(); - void setupUserScripts(); void setUserStyleSheet(const QString &filePath); @@ -197,8 +192,6 @@ private: QList m_postLaunchActions; - QString m_languageFile; - void createJumpList(); void initPulseSupport(); diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index c950a4d55..51b278055 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -97,8 +97,8 @@ void Plugins::shutdown() PluginSpec Plugins::createSpec(const DesktopFile &metaData) { PluginSpec spec; - spec.name = metaData.name(mApp->currentLanguage()); - spec.description = metaData.comment(mApp->currentLanguage()); + spec.name = metaData.name(); + spec.description = metaData.comment(); spec.version = metaData.value(QSL("X-Falkon-Version")).toString(); spec.author = QSL("%1 <%2>").arg(metaData.value(QSL("X-Falkon-Author")).toString(), metaData.value(QSL("X-Falkon-Email")).toString()); spec.hasSettings = metaData.value(QSL("X-Falkon-Settings")).toBool(); @@ -352,7 +352,6 @@ bool Plugins::initPlugin(PluginInterface::InitState state, Plugin *plugin) return false; } - qApp->installTranslator(plugin->instance->getTranslator(mApp->currentLanguageFile())); return true; } diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index f21bd41ce..68a09e060 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -100,7 +100,6 @@ Preferences::Preferences(BrowserWindow* window) { setAttribute(Qt::WA_DeleteOnClose); ui->setupUi(this); - ui->languages->setLayoutDirection(Qt::LeftToRight); QzTools::centerWidgetOnScreen(this); m_themesManager = new ThemeManager(ui->themesWidget, this); @@ -458,37 +457,6 @@ Preferences::Preferences(BrowserWindow* window) ui->spellcheckNoLanguages->hide(); } - //OTHER - //Languages - QString activeLanguage = mApp->currentLanguage(); - - if (!activeLanguage.isEmpty() && activeLanguage != QLatin1String("en_US")) { - ui->languages->addItem(createLanguageItem(activeLanguage), activeLanguage); - } - - ui->languages->addItem("English (en_US)"); - - const QStringList translationPaths = DataPaths::allPaths(DataPaths::Translations); - - foreach (const QString &path, translationPaths) { - QDir lanDir(path); - QStringList list = lanDir.entryList(QStringList("*.qm")); - foreach (const QString &name, list) { - if (name.startsWith(QLatin1String("qt_"))) { - continue; - } - - QString loc = name; - loc.remove(QLatin1String(".qm")); - - if (loc == activeLanguage) { - continue; - } - - ui->languages->addItem(createLanguageItem(loc), loc); - } - } - // Proxy Configuration settings.beginGroup("Web-Proxy"); int proxyType = settings.value("ProxyType", 2).toInt(); @@ -1021,11 +989,6 @@ void Preferences::saveSettings() settings.setValue("showSearchSuggestions", ui->showABSearchSuggestions->isChecked()); settings.endGroup(); - //Languages - settings.beginGroup("Language"); - settings.setValue("language", ui->languages->itemData(ui->languages->currentIndex()).toString()); - settings.endGroup(); - //Proxy Configuration int proxyType; if (ui->noProxy->isChecked()) { diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index 867c66427..47a74636c 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -412,46 +412,6 @@ - - - - In order to change language, you must restart browser. - - - - - - - <b>Language</b> - - - - - - - - - - 0 - 0 - - - - - 200 - 0 - - - - Available translations: - - - - - - - - @@ -2419,8 +2379,8 @@ 0 0 - 560 - 80 + 96 + 31 diff --git a/src/lib/preferences/thememanager.cpp b/src/lib/preferences/thememanager.cpp index beedc64cc..f99e45065 100644 --- a/src/lib/preferences/thememanager.cpp +++ b/src/lib/preferences/thememanager.cpp @@ -111,8 +111,8 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &path, const QString } DesktopFile metadata(path + QSL("metadata.desktop")); - info.name = metadata.name(mApp->currentLanguage()); - info.description = metadata.comment(mApp->currentLanguage()); + info.name = metadata.name(); + info.description = metadata.comment(); info.author = metadata.value(QSL("X-Falkon-Author")).toString(); const QString iconName = metadata.icon(); diff --git a/src/lib/tools/certificateinfowidget.cpp b/src/lib/tools/certificateinfowidget.cpp index cb0a92db0..d84efdbf5 100644 --- a/src/lib/tools/certificateinfowidget.cpp +++ b/src/lib/tools/certificateinfowidget.cpp @@ -329,7 +329,7 @@ CertificateInfoWidget::CertificateInfoWidget(const QSslCertificate &cert, QWidge ui->issuedByO->setText(showCertInfo(cert.issuerInfo(QSslCertificate::Organization))); ui->issuedByOU->setText(showCertInfo(cert.issuerInfo(QSslCertificate::OrganizationalUnitName))); //Validity - QLocale locale = QLocale(mApp->currentLanguageFile()); + QLocale locale = QLocale::system(); ui->validityIssuedOn->setText(locale.toString(cert.effectiveDate(), "dddd d. MMMM yyyy")); ui->validityExpiresOn->setText(locale.toString(cert.expiryDate(), "dddd d. MMMM yyyy")); } diff --git a/src/lib/tools/desktopfile.cpp b/src/lib/tools/desktopfile.cpp index 47794c06d..464add83b 100644 --- a/src/lib/tools/desktopfile.cpp +++ b/src/lib/tools/desktopfile.cpp @@ -30,14 +30,14 @@ DesktopFile::DesktopFile(const QString &filePath) m_settings->beginGroup(QSL("Desktop Entry")); } -QString DesktopFile::name(const QString &locale) const +QString DesktopFile::name() const { - return value(QSL("Name"), locale).toString(); + return value(QSL("Name"), true).toString(); } -QString DesktopFile::comment(const QString &locale) const +QString DesktopFile::comment() const { - return value(QSL("Comment"), locale).toString(); + return value(QSL("Comment"), true).toString(); } QString DesktopFile::type() const @@ -50,16 +50,28 @@ QString DesktopFile::icon() const return value(QSL("Icon")).toString(); } -QVariant DesktopFile::value(const QString &key, const QString &locale) const +QVariant DesktopFile::value(const QString &key, bool localized) const { if (!m_settings) { return QVariant(); } - if (!locale.isEmpty()) { - const QString localeKey = QSL("%1[%2]").arg(key, locale); + if (localized) { + const QLocale locale = QLocale::system(); + QString localeKey = QSL("%1[%2]").arg(key, locale.name()); if (m_settings->contains(localeKey)) { return m_settings->value(localeKey); } + localeKey = QSL("%1[%2]").arg(key, locale.bcp47Name()); + if (m_settings->contains(localeKey)) { + return m_settings->value(localeKey); + } + const int i = locale.name().indexOf(QLatin1Char('_')); + if (i > 0) { + localeKey = QSL("%1[%2]").arg(key, locale.name().left(i)); + if (m_settings->contains(localeKey)) { + return m_settings->value(localeKey); + } + } } return m_settings->value(key); } diff --git a/src/lib/tools/desktopfile.h b/src/lib/tools/desktopfile.h index 13e70f2bc..87db58ddf 100644 --- a/src/lib/tools/desktopfile.h +++ b/src/lib/tools/desktopfile.h @@ -29,11 +29,11 @@ public: explicit DesktopFile(); explicit DesktopFile(const QString &filePath); - QString name(const QString &locale = QString()) const; - QString comment(const QString &locale = QString()) const; + QString name() const; + QString comment() const; QString type() const; QString icon() const; - QVariant value(const QString &key, const QString &locale = QString()) const; + QVariant value(const QString &key, bool localized = false) const; private: QSharedPointer m_settings; diff --git a/src/lib/webengine/webview.cpp b/src/lib/webengine/webview.cpp index 6db0c7706..94bed96ec 100644 --- a/src/lib/webengine/webview.cpp +++ b/src/lib/webengine/webview.cpp @@ -795,7 +795,7 @@ void WebView::createPageContextMenu(QMenu* menu) const QUrl w3url = QUrl::fromEncoded("http://validator.w3.org/check?uri=" + QUrl::toPercentEncoding(url().toEncoded())); menu->addAction(QIcon(":icons/sites/w3.png"), tr("Validate page"), this, SLOT(openUrlInSelectedTab()))->setData(w3url); - QByteArray langCode = mApp->currentLanguage().left(2).toUtf8(); + QByteArray langCode = QLocale::system().name().left(2).toUtf8(); const QUrl gturl = QUrl::fromEncoded("http://translate.google.com/translate?sl=auto&tl=" + langCode + "&u=" + QUrl::toPercentEncoding(url().toEncoded())); menu->addAction(QIcon(":icons/sites/translate.png"), tr("Translate page"), this, SLOT(openUrlInSelectedTab()))->setData(gturl); } @@ -868,7 +868,7 @@ void WebView::createSelectedTextContextMenu(QMenu* menu, const WebHitTestResult menu->addAction(QIcon::fromTheme("mail-message-new"), tr("Send text..."), this, SLOT(sendTextByMail()))->setData(selectedText); menu->addSeparator(); - QString langCode = mApp->currentLanguage().left(2).toUtf8(); + QString langCode = QLocale::system().name().left(2).toUtf8(); QUrl googleTranslateUrl = QUrl(QString("https://translate.google.com/#auto/%1/%2").arg(langCode, selectedText)); Action* gtwact = new Action(QIcon(":icons/sites/translate.png"), tr("Google Translate")); gtwact->setData(googleTranslateUrl);