1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Remove option to change language on per-profile basis

System locale is now always used.
This commit is contained in:
David Rosca 2018-02-26 21:52:39 +01:00
parent 27506e3ba1
commit 4d2f02ac45
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
10 changed files with 31 additions and 180 deletions

View File

@ -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()) {

View File

@ -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<PostLaunchAction> m_postLaunchActions;
QString m_languageFile;
void createJumpList();
void initPulseSupport();

View File

@ -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;
}

View File

@ -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()) {

View File

@ -412,46 +412,6 @@
</property>
</widget>
</item>
<item row="18" column="1" colspan="2">
<widget class="QLabel" name="label_17">
<property name="text">
<string>In order to change language, you must restart browser.</string>
</property>
</widget>
</item>
<item row="14" column="0" colspan="3">
<widget class="QLabel" name="label_11">
<property name="text">
<string>&lt;b&gt;Language&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="15" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QLabel" name="label_16">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Available translations: </string>
</property>
</widget>
</item>
</layout>
</item>
<item row="15" column="2">
<widget class="QComboBox" name="languages"/>
</item>
<item row="5" column="1" colspan="2">
<widget class="QCheckBox" name="dontLoadTabsUntilSelected">
<property name="text">
@ -2419,8 +2379,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>80</height>
<width>96</width>
<height>31</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_14">

View File

@ -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();

View File

@ -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"));
}

View File

@ -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);
}

View File

@ -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<QSettings> m_settings;

View File

@ -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);