Skip to content

Commit

Permalink
improved runtime language switching
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolcha committed Feb 26, 2025
1 parent d3669f2 commit 203333e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/core/clock_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ void ClockApplication::loadTranslation()
}

_active_lang = app_translator->language();
_active_lang.replace('-', '_');
_translators.push_back(std::move(app_translator));
}

Expand Down
3 changes: 3 additions & 0 deletions app/core/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ std::unique_ptr<QTranslator> findTranslation(QStringView module)

std::unique_ptr<QTranslator> loadTranslation(QStringView module, QStringView locale)
{
if (locale.startsWith(QLatin1String("en"))) // "English" is built-in
return nullptr; // use built-in

auto translator = std::make_unique<QTranslator>();
if (translator->load(QString(":/i18n/i18n/%1_%2").arg(module, locale)))
return translator;
Expand Down
27 changes: 21 additions & 6 deletions app/gui/settings/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ SettingsDialog::SettingsDialog(ClockApplication* app, size_t idx, QWidget* paren

app->window(_curr_idx)->enableFrame();

QSignalBlocker _(ui->windows_box);
const auto act_insts = app->config()->global()->getActiveInstancesList();
for (auto i : act_insts)
ui->windows_box->addItem(tr("window %1").arg(i+1));
ui->windows_box->setCurrentIndex(_curr_idx);
ui->windows_box->setVisible(act_insts.size() > 1);
fillWindowsList();

fillLanguagesList();
fillUpdatePeriodsList();
Expand Down Expand Up @@ -110,7 +105,13 @@ void SettingsDialog::reject()
bool SettingsDialog::event(QEvent* e)
{
if (e->type() == QEvent::LanguageChange) {
QSignalBlocker _(this);
ui->retranslateUi(this);
fillWindowsList();
fillUpdatePeriodsList();
fillTextureTypes(ui->tx_options_box);
fillTextureTypes(ui->bg_options_box);
initAppearanceTab(_curr_idx);
initPluginsTab();
}
return QDialog::event(e);
Expand Down Expand Up @@ -990,6 +991,17 @@ void SettingsDialog::showPluginInfoDialog(const PluginHandle& ph)
dlg->show();
}

void SettingsDialog::fillWindowsList()
{
QSignalBlocker _(ui->windows_box);
ui->windows_box->clear();
const auto act_insts = app->config()->global()->getActiveInstancesList();
for (auto i : act_insts)
ui->windows_box->addItem(tr("window %1").arg(i+1));
ui->windows_box->setCurrentIndex(_curr_idx);
ui->windows_box->setVisible(act_insts.size() > 1);
}

void SettingsDialog::fillLanguagesList()
{
QSignalBlocker _(ui->lang_list);
Expand All @@ -1004,6 +1016,7 @@ void SettingsDialog::fillLanguagesList()
void SettingsDialog::fillUpdatePeriodsList()
{
QSignalBlocker _(ui->update_period_edit);
ui->update_period_edit->clear();
ui->update_period_edit->addItem(tr("1 day"), 1);
ui->update_period_edit->addItem(tr("3 days"), 3);
ui->update_period_edit->addItem(tr("1 week"), 7);
Expand Down Expand Up @@ -1049,6 +1062,8 @@ void SettingsDialog::fillSkinsList()

void SettingsDialog::fillTextureTypes(QComboBox* box)
{
QSignalBlocker _(box);
box->clear();
box->addItem(tr("solid color"), QVariant::fromValue(tx::Color));
box->addItem(tr("gradient"), QVariant::fromValue(tx::Gradient));
box->addItem(tr("pattern"), QVariant::fromValue(tx::Pattern));
Expand Down
1 change: 1 addition & 0 deletions app/gui/settings/settings_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private slots:
void onPluginStateChanged(PluginHandle ph, bool enabled);
void showPluginInfoDialog(const PluginHandle& ph);

void fillWindowsList();
void fillLanguagesList();
void fillUpdatePeriodsList();
void fillTimeZonesList();
Expand Down

0 comments on commit 203333e

Please sign in to comment.