A new multilingual solution

This commit is contained in:
dreamsourcelabTAI 2022-10-14 09:57:15 +08:00
parent 83631c9d65
commit 9457e64e7b
6 changed files with 35 additions and 27 deletions

View File

@ -34,6 +34,7 @@
#include "config.h" #include "config.h"
#include "pv/appcontrol.h" #include "pv/appcontrol.h"
#include "pv/log.h" #include "pv/log.h"
#include "pv/ui/langresource.h"
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -196,6 +197,7 @@ bool bHighScale = true;
AppControl *control = AppControl::Instance(); AppControl *control = AppControl::Instance();
AppConfig &app = AppConfig::Instance(); AppConfig &app = AppConfig::Instance();
app.LoadAll(); //load app config app.LoadAll(); //load app config
LangResource::Instance()->Load(app._frameOptions.language);
if (app._appOptions.ableSaveLog){ if (app._appOptions.ableSaveLog){
dsv_log_enalbe_logfile(false); dsv_log_enalbe_logfile(false);

View File

@ -146,11 +146,11 @@ DeviceOptions::DeviceOptions(QWidget *parent) :
try_resize_scroll(); try_resize_scroll();
connect(&_mode_check, SIGNAL(timeout()), this, SLOT(mode_check())); connect(&_mode_check_timer, SIGNAL(timeout()), this, SLOT(mode_check_timeout()));
connect(button_box, SIGNAL(accepted()), this, SLOT(accept())); connect(button_box, SIGNAL(accepted()), this, SLOT(accept()));
_mode_check.setInterval(100); _mode_check_timer.setInterval(100);
_mode_check.start(); _mode_check_timer.start();
} }
DeviceOptions::~DeviceOptions(){ DeviceOptions::~DeviceOptions(){
@ -441,7 +441,7 @@ void DeviceOptions::on_calibration()
_device_agent->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(true)); _device_agent->set_config(NULL, NULL, SR_CONF_CALI, g_variant_new_boolean(true));
} }
void DeviceOptions::mode_check() void DeviceOptions::mode_check_timeout()
{ {
if (_isBuilding) if (_isBuilding)
return; return;

View File

@ -109,7 +109,7 @@ private slots:
void enable_all_probes(); void enable_all_probes();
void disable_all_probes(); void disable_all_probes();
void zero_adj(); void zero_adj();
void mode_check(); void mode_check_timeout();
void channel_check(); void channel_check();
void analog_channel_check(); void analog_channel_check();
void on_calibration(); void on_calibration();
@ -119,7 +119,7 @@ private:
std::vector<QCheckBox *> _probes_checkBox_list; std::vector<QCheckBox *> _probes_checkBox_list;
std::vector<QLayout *> _sub_lays; std::vector<QLayout *> _sub_lays;
QTimer _mode_check; QTimer _mode_check_timer;
QString _mode; QString _mode;
QWidget *_scroll_panel; QWidget *_scroll_panel;
QScrollArea *_scroll; QScrollArea *_scroll;

View File

@ -96,6 +96,7 @@
#include "deviceagent.h" #include "deviceagent.h"
#include <stdlib.h> #include <stdlib.h>
#include "ZipMaker.h" #include "ZipMaker.h"
#include "ui/langresource.h"
#define BASE_SESSION_VERSION 2 #define BASE_SESSION_VERSION 2
@ -206,8 +207,7 @@ namespace pv
// Set the title // Set the title
QString title = QApplication::applicationName() + " v" + QApplication::applicationVersion(); QString title = QApplication::applicationName() + " v" + QApplication::applicationVersion();
std::string std_title = title.toStdString(); setWindowTitle(QApplication::translate("MainWindow", title.toLocal8Bit().data(), 0));
setWindowTitle(QApplication::translate("MainWindow", std_title.c_str(), 0));
// event filter // event filter
_view->installEventFilter(this); _view->installEventFilter(this);
@ -623,7 +623,6 @@ namespace pv
// old version(<= 1.1.2), restore the language // old version(<= 1.1.2), restore the language
if (sessionObj["Version"].toInt() == BASE_SESSION_VERSION) if (sessionObj["Version"].toInt() == BASE_SESSION_VERSION)
{ {
switchLanguage(sessionObj["Language"].toInt());
} }
if (_device_agent->is_hardware()) if (_device_agent->is_hardware())
@ -838,11 +837,14 @@ namespace pv
GVariant *gvar; GVariant *gvar;
gsize num_opts; gsize num_opts;
QString title = QApplication::applicationName() + " v" + QApplication::applicationVersion();
QJsonArray channelVar; QJsonArray channelVar;
sessionVar["Version"] = QJsonValue::fromVariant(BASE_SESSION_VERSION); sessionVar["Version"] = QJsonValue::fromVariant(BASE_SESSION_VERSION);
sessionVar["Device"] = QJsonValue::fromVariant(_device_agent->driver_name()); sessionVar["Device"] = QJsonValue::fromVariant(_device_agent->driver_name());
sessionVar["DeviceMode"] = QJsonValue::fromVariant(_device_agent->get_work_mode()); sessionVar["DeviceMode"] = QJsonValue::fromVariant(_device_agent->get_work_mode());
sessionVar["Language"] = QJsonValue::fromVariant(app._frameOptions.language); sessionVar["Language"] = QJsonValue::fromVariant(app._frameOptions.language);
sessionVar["Title"] = QJsonValue::fromVariant(title);
gvar_opts = _device_agent->get_config_list(NULL, SR_CONF_DEVICE_SESSIONS); gvar_opts = _device_agent->get_config_list(NULL, SR_CONF_DEVICE_SESSIONS);
if (gvar_opts == NULL) if (gvar_opts == NULL)
@ -1155,7 +1157,8 @@ namespace pv
{ {
app._frameOptions.language = language; app._frameOptions.language = language;
app.SaveFrame(); app.SaveFrame();
} LangResource::Instance()->Load(language);
}
if (language == LAN_CN) if (language == LAN_CN)
{ {
@ -1485,7 +1488,7 @@ namespace pv
if (error.error != QJsonParseError::NoError) if (error.error != QJsonParseError::NoError)
{ {
QString estr = error.errorString(); QString estr = error.errorString();
dsv_err("File::get_decoders(), parse json error:\"%s\"!", estr.toUtf8().data()); dsv_err("MainWindow::get_decoder_json_from_file(), parse json error:\"%s\"!", estr.toUtf8().data());
} }
dec_array = sessionDoc.array(); dec_array = sessionDoc.array();

View File

@ -131,14 +131,12 @@ private slots:
signals: signals:
void prgRate(int progress); void prgRate(int progress);
//IMainForm
public: public:
void switchLanguage(int language); //IMainForm
void switchLanguage(int language);
//ISessionCallback
public:
void session_save();
//ISessionCallback
void session_save();
private: private:
void check_usb_device_speed(); void check_usb_device_speed();

View File

@ -36,6 +36,7 @@
#include "../log.h" #include "../log.h"
#include "../deviceagent.h" #include "../deviceagent.h"
#include "../ui/msgbox.h" #include "../ui/msgbox.h"
#include "../ui/langresource.h"
using std::map; using std::map;
using std::max; using std::max;
@ -170,31 +171,35 @@ namespace pv
} }
} }
_configure_button.setText(tr("Options")); _configure_button.setText(tr("Options"));
_mode_button.setText(tr("Mode")); _mode_button.setText(L_S(STR_PAGE_TOOLBAR, S_ID(IDS_TOOLBAR_MODE), "Mode"));
int mode = _device_agent->get_work_mode(); int mode = _device_agent->get_work_mode();
bool is_working = _session->is_working(); bool is_working = _session->is_working();
auto str_start = L_S(STR_PAGE_TOOLBAR, S_ID(IDS_TOOLBAR_START), "Start");
auto str_stop = L_S(STR_PAGE_TOOLBAR, S_ID(IDS_TOOLBAR_STOP), "Stop");
auto str_single = L_S(STR_PAGE_TOOLBAR, S_ID(IDS_TOOLBAR_SINGLE), "Single");
auto str_instant = L_S(STR_PAGE_TOOLBAR, S_ID(IDS_TOOLBAR_INSTANT), "Instant");
if (_is_run_as_instant) if (_is_run_as_instant)
{ {
if (bDev && mode == DSO) if (bDev && mode == DSO)
_instant_button.setText(is_working ? tr("Stop") : tr("Single")); _instant_button.setText(is_working ? str_stop : str_single);
else else
_instant_button.setText(is_working ? tr("Stop") : tr("Instant")); _instant_button.setText(is_working ? str_stop : str_instant);
_run_stop_button.setText(tr("Start")); _run_stop_button.setText(str_start);
} }
else else
{ {
_run_stop_button.setText(is_working ? tr("Stop") : tr("Start")); _run_stop_button.setText(is_working ? str_stop: str_start);
if (bDev && mode == DSO) if (bDev && mode == DSO)
_instant_button.setText(tr("Single")); _instant_button.setText(str_single);
else else
_instant_button.setText(tr("Instant")); _instant_button.setText(str_instant);
} }
_action_single->setText(tr("&Single")); _action_single->setText(L_S(STR_PAGE_TOOLBAR, S_ID(IDS_TOOLBAR_SINGLE_ACTION), "&Single"));
_action_repeat->setText(tr("&Repetitive")); _action_repeat->setText(L_S(STR_PAGE_TOOLBAR, S_ID(IDS_TOOLBAR_REPEAT_ACTION), "&Repetitive"));
} }
void SamplingBar::reStyle() void SamplingBar::reStyle()