Update commands strings when language change

This commit is contained in:
Joshua Ogunyinka 2022-01-03 13:28:49 +04:00 committed by David Capello
parent bbfae36d8f
commit ab56186d79
4 changed files with 30 additions and 12 deletions

View File

@ -20,12 +20,7 @@ Command::Command(const char* id, CommandFlags flags)
: m_id(id) : m_id(id)
, m_flags(flags) , m_flags(flags)
{ {
std::string strId = "commands."; generateFriendlyName();
strId += this->id();
if (auto s = Strings::instance())
m_friendlyName = s->translate(strId.c_str());
else
m_friendlyName = strId;
} }
Command::~Command() Command::~Command()
@ -69,6 +64,15 @@ bool Command::isChecked(Context* context)
} }
} }
void Command::generateFriendlyName()
{
std::string strId = "commands." + this->id();
if (auto s = Strings::instance())
m_friendlyName = s->translate(strId.c_str());
else
m_friendlyName = strId;
}
void Command::execute(Context* context) void Command::execute(Context* context)
{ {
onExecute(context); onExecute(context);

View File

@ -35,6 +35,7 @@ namespace app {
void loadParams(const Params& params); void loadParams(const Params& params);
bool isEnabled(Context* context); bool isEnabled(Context* context);
bool isChecked(Context* context); bool isChecked(Context* context);
void generateFriendlyName();
protected: protected:
virtual bool onNeedsParams() const; virtual bool onNeedsParams() const;

View File

@ -13,6 +13,7 @@
#include "app/app.h" #include "app/app.h"
#include "app/app_menus.h" #include "app/app_menus.h"
#include "app/commands/command.h"
#include "app/commands/commands.h" #include "app/commands/commands.h"
#include "app/crash/data_recovery.h" #include "app/crash/data_recovery.h"
#include "app/i18n/strings.h" #include "app/i18n/strings.h"
@ -159,12 +160,7 @@ MainWindow::MainWindow()
// When the language is change, we reload the menu bar strings and // When the language is change, we reload the menu bar strings and
// relayout the whole main window. // relayout the whole main window.
Strings::instance()->LanguageChange.connect( Strings::instance()->LanguageChange.connect([this] { onLanguageChange(); });
[this]{
m_menuBar->reload();
layout();
invalidate();
});
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -203,6 +199,22 @@ MainWindow::~MainWindow()
m_menuBar->setMenu(NULL); m_menuBar->setMenu(NULL);
} }
void MainWindow::onLanguageChange()
{
auto commands = Commands::instance();
std::vector<std::string> commandIDs;
commands->getAllIds(commandIDs);
for (const auto& commandID : commandIDs) {
Command* command = commands->byId(commandID.c_str());
command->generateFriendlyName();
}
m_menuBar->reload();
layout();
invalidate();
}
DocView* MainWindow::getDocView() DocView* MainWindow::getDocView()
{ {
return dynamic_cast<DocView*>(m_workspace->activeView()); return dynamic_cast<DocView*>(m_workspace->activeView());

View File

@ -116,6 +116,7 @@ namespace app {
void onSaveLayout(ui::SaveLayoutEvent& ev) override; void onSaveLayout(ui::SaveLayoutEvent& ev) override;
void onResize(ui::ResizeEvent& ev) override; void onResize(ui::ResizeEvent& ev) override;
void onActiveViewChange(); void onActiveViewChange();
void onLanguageChange();
private: private:
DocView* getDocView(); DocView* getDocView();