Skip to content

Commit

Permalink
Further improves localization (#191). Allows switching and setting th…
Browse files Browse the repository at this point in the history
…e chosen localization properly.
  • Loading branch information
ikskuh committed Mar 17, 2021
1 parent da83396 commit eb2775d
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 78 deletions.
6 changes: 6 additions & 0 deletions src/browsertab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ BrowserTab::BrowserTab(MainWindow *mainWindow) : QWidget(nullptr),
{
ui->setupUi(this);

connect( // connect with "this" as context, so the connection will die when the window is destroyed
kristall::globals().localization.get(), &Localization::translationChanged,
this, [this]() { this->ui->retranslateUi(this); },
Qt::DirectConnection
);

this->setUiDensity(kristall::globals().options.ui_density);

addProtocolHandler<GeminiClient>();
Expand Down
34 changes: 22 additions & 12 deletions src/browsertab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
<string>Back</string>
</property>
<property name="icon">
<iconset theme="go-previous"/>
<iconset theme="go-previous">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -59,7 +60,8 @@
<string>Forward</string>
</property>
<property name="icon">
<iconset theme="go-next"/>
<iconset theme="go-next">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -75,7 +77,8 @@
<string>Stop</string>
</property>
<property name="icon">
<iconset theme="process-stop"/>
<iconset theme="process-stop">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -91,7 +94,8 @@
<string>Reload</string>
</property>
<property name="icon">
<iconset theme="view-refresh"/>
<iconset theme="view-refresh">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -107,7 +111,8 @@
<string>Home</string>
</property>
<property name="icon">
<iconset theme="go-home"/>
<iconset theme="go-home">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -123,7 +128,8 @@
<string>/</string>
</property>
<property name="icon">
<iconset theme="go-top"/>
<iconset theme="go-top">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -139,7 +145,8 @@
<string>P</string>
</property>
<property name="icon">
<iconset theme="go-up"/>
<iconset theme="go-up">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand Down Expand Up @@ -211,11 +218,11 @@
<bool>true</bool>
</property>
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
<string notr="true" extracomment="Must not be translated, otherwise the content will be replaced when switching languages">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Start surfin!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openLinks">
<bool>false</bool>
Expand Down Expand Up @@ -267,7 +274,8 @@ p, li { white-space: pre-wrap; }
<string>Previous</string>
</property>
<property name="icon">
<iconset theme="go-up-search"/>
<iconset theme="go-up-search">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -280,7 +288,8 @@ p, li { white-space: pre-wrap; }
<string>Next</string>
</property>
<property name="icon">
<iconset theme="go-down-search"/>
<iconset theme="go-down-search">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -293,7 +302,8 @@ p, li { white-space: pre-wrap; }
<string>Hide</string>
</property>
<property name="icon">
<iconset theme="window-close"/>
<iconset theme="window-close">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand Down
7 changes: 7 additions & 0 deletions src/dialogs/certificateiodialog.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "certificateiodialog.hpp"
#include "ui_certificateiodialog.h"
#include "kristall.hpp"

#include <QFileDialog>
#include <QPushButton>
Expand All @@ -11,6 +12,12 @@ CertificateIoDialog::CertificateIoDialog(QWidget *parent) :
{
ui->setupUi(this);

connect( // connect with "this" as context, so the connection will die when the window is destroyed
kristall::globals().localization.get(), &Localization::translationChanged,
this, [this]() { this->ui->retranslateUi(this); },
Qt::DirectConnection
);

this->ui->key_type->clear();
this->ui->key_type->addItem("RSA", QVariant::fromValue<int>(QSsl::Rsa));
this->ui->key_type->addItem("ECDSA", QVariant::fromValue<int>(QSsl::Ec));
Expand Down
6 changes: 6 additions & 0 deletions src/dialogs/certificatemanagementdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ CertificateManagementDialog::CertificateManagementDialog(QWidget *parent) :
{
ui->setupUi(this);

connect( // connect with "this" as context, so the connection will die when the window is destroyed
kristall::globals().localization.get(), &Localization::translationChanged,
this, [this]() { this->ui->retranslateUi(this); },
Qt::DirectConnection
);

this->ui->certificates->setModel(&identity_set);
this->ui->certificates->expandAll();

Expand Down
7 changes: 7 additions & 0 deletions src/dialogs/certificateselectiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ CertificateSelectionDialog::CertificateSelectionDialog(QWidget *parent) :
ui(new Ui::CertificateSelectionDialog)
{
ui->setupUi(this);

connect( // connect with "this" as context, so the connection will die when the window is destroyed
kristall::globals().localization.get(), &Localization::translationChanged,
this, [this]() { this->ui->retranslateUi(this); },
Qt::DirectConnection
);

this->ui->server_request->setVisible(false);

this->ui->certificates->setModel(&kristall::globals().identities);
Expand Down
6 changes: 6 additions & 0 deletions src/dialogs/newidentitiydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ NewIdentitiyDialog::NewIdentitiyDialog(QWidget *parent) :
{
ui->setupUi(this);

connect( // connect with "this" as context, so the connection will die when the window is destroyed
kristall::globals().localization.get(), &Localization::translationChanged,
this, [this]() { this->ui->retranslateUi(this); },
Qt::DirectConnection
);

ui->display_name->setText("Unnamed");
ui->common_name->setText("Unnamed");
ui->expiration_date->setDate(QDate::currentDate().addYears(1));
Expand Down
44 changes: 44 additions & 0 deletions src/dialogs/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
{
ui->setupUi(this);

connect( // connect with "this" as context, so the connection will die when the window is destroyed
kristall::globals().localization.get(), &Localization::translationChanged,
this, [this]() { this->ui->retranslateUi(this); },
Qt::DirectConnection
);

static_assert(DocumentStyle::Fixed == 0);
static_assert(DocumentStyle::AutoDarkTheme == 1);
static_assert(DocumentStyle::AutoLightTheme == 2);
Expand Down Expand Up @@ -103,6 +109,11 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
this->ui->style_scroll_layout->minimumSize().width()
+ this->ui->style_scroll_area->verticalScrollBar()->sizeHint().width());
});

this->ui->selected_language->clear();
this->ui->selected_language->addItem(QIcon(), tr("System language"), QString(""));
this->ui->selected_language->addItem(QIcon(":/icons/languages/en.svg"), QLocale("en").nativeLanguageName(), QString("en"));
this->ui->selected_language->addItem(QIcon(":/icons/languages/ru.svg"), QLocale("ru").nativeLanguageName(), QString("ru"));
}

SettingsDialog::~SettingsDialog()
Expand Down Expand Up @@ -387,6 +398,32 @@ void SettingsDialog::setOptions(const GenericSettings &options)
}
}

std::optional<QLocale> SettingsDialog::locale() const
{
QString locale_str = this->ui->selected_language->currentData().toString();
if(locale_str.isEmpty())
return std::nullopt;
else
return QLocale(locale_str);
}

void SettingsDialog::setLocale(std::optional<QLocale> locale)
{
if(locale == std::nullopt)
{
this->ui->selected_language->setCurrentIndex(0);
}
else
{
switch(locale->language())
{
default: this->ui->selected_language->setCurrentIndex(0); break;
case QLocale::English: this->ui->selected_language->setCurrentIndex(1); break;
case QLocale::Russian: this->ui->selected_language->setCurrentIndex(2); break;
}
}
}

GenericSettings SettingsDialog::options() const
{
return this->current_options;
Expand Down Expand Up @@ -988,3 +1025,10 @@ void SettingsDialog::on_session_restore_behaviour_currentIndexChanged(int index)
{
this->current_options.session_restore_behaviour = GenericSettings::SessionRestoreBehaviour(this->ui->session_restore_behaviour->itemData(index).toInt());
}

void SettingsDialog::on_selected_language_currentIndexChanged(int index)
{
auto const language_id = this->ui->selected_language->itemData(index, Qt::UserRole).toString();

kristall::globals().localization->translate(QLocale(language_id));
}
6 changes: 6 additions & 0 deletions src/dialogs/settingsdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define SETTINGSDIALOG_HPP

#include <QDialog>
#include <optional>

#include "renderers/geminirenderer.hpp"
#include "protocolsetup.hpp"
Expand Down Expand Up @@ -39,6 +40,9 @@ class SettingsDialog : public QDialog
GenericSettings options() const;
void setOptions(GenericSettings const & options);

std::optional<QLocale> locale() const;
void setLocale(std::optional<QLocale> locale);

private slots:
void on_std_change_font_clicked();

Expand Down Expand Up @@ -178,6 +182,8 @@ private slots:

void on_session_restore_behaviour_currentIndexChanged(int index);

void on_selected_language_currentIndexChanged(int index);

private:
void reloadStylePreview();

Expand Down
Loading

0 comments on commit eb2775d

Please sign in to comment.