Skip to content

Commit

Permalink
dynamic translation switching
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolcha committed Sep 12, 2024
1 parent ee116e2 commit 702d863
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/core/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ void Application::configureWindows()
for (size_t i = 0; i < _windows.size(); i++) configureWindow(i);
}

void Application::retranslateUI()
{
std::ranges::for_each(_translators, [](auto& t) { QApplication::removeTranslator(t.get()); });
_translators.clear();
_active_lang = "en_US";

const auto& plugins = _cfg->global().getPlugins();
std::ranges::for_each(plugins, [this](auto& p) { _pm.unloadPlugin(p); });
loadTranslation();
_pm.enumeratePlugins();
std::ranges::for_each(plugins, [this](auto& p) { _pm.loadPlugin(p); });
}

size_t Application::findWindow(ClockWindow* w) const
{
for (size_t i = 0; i < _windows.size(); i++)
Expand Down
3 changes: 3 additions & 0 deletions app/core/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class Application : public QApplication

QString activeLang() const { return _active_lang; }

public slots:
void retranslateUI();

private:
void initConfig();
void loadTranslation();
Expand Down
6 changes: 6 additions & 0 deletions app/core/plugin_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ PluginInfo PluginManager::pluginInfo(const QString& id) const
return info;
}

void PluginManager::enumeratePlugins()
{
_impl->available.clear();
_impl->enumerate();
}

void PluginManager::loadPlugin(const QString& id)
{
_impl->load(id);
Expand Down
2 changes: 2 additions & 0 deletions app/core/plugin_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class PluginManager : public QObject
PluginInfo pluginInfo(const QString& id) const;

public slots:
void enumeratePlugins();

void loadPlugin(const QString& id);
void unloadPlugin(const QString& id);

Expand Down
4 changes: 4 additions & 0 deletions app/gui/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void SettingsDialog::reject()
app->configureWindows();
const auto curr_plugins = app->config().global().getPlugins();
for (const auto& p : curr_plugins) app->pluginManager().loadPlugin(p);
app->retranslateUI();
QDialog::reject();
}

Expand All @@ -129,6 +130,9 @@ void SettingsDialog::on_lang_tr_btn_clicked()
void SettingsDialog::on_lang_list_activated(int index)
{
app->config().global().setLocale(ui->lang_list->itemData(index).toString());
app->retranslateUI();
ui->retranslateUi(this);
initPluginsTab();
}

void SettingsDialog::on_enable_autostart_clicked(bool checked)
Expand Down

0 comments on commit 702d863

Please sign in to comment.