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

View File

@ -146,11 +146,11 @@ DeviceOptions::DeviceOptions(QWidget *parent) :
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()));
_mode_check.setInterval(100);
_mode_check.start();
_mode_check_timer.setInterval(100);
_mode_check_timer.start();
}
DeviceOptions::~DeviceOptions(){
@ -441,7 +441,7 @@ void DeviceOptions::on_calibration()
_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)
return;

View File

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

View File

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

View File

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

View File

@ -36,6 +36,7 @@
#include "../log.h"
#include "../deviceagent.h"
#include "../ui/msgbox.h"
#include "../ui/langresource.h"
using std::map;
using std::max;
@ -170,31 +171,35 @@ namespace pv
}
}
_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();
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 (bDev && mode == DSO)
_instant_button.setText(is_working ? tr("Stop") : tr("Single"));
_instant_button.setText(is_working ? str_stop : str_single);
else
_instant_button.setText(is_working ? tr("Stop") : tr("Instant"));
_run_stop_button.setText(tr("Start"));
_instant_button.setText(is_working ? str_stop : str_instant);
_run_stop_button.setText(str_start);
}
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)
_instant_button.setText(tr("Single"));
_instant_button.setText(str_single);
else
_instant_button.setText(tr("Instant"));
_instant_button.setText(str_instant);
}
_action_single->setText(tr("&Single"));
_action_repeat->setText(tr("&Repetitive"));
_action_single->setText(L_S(STR_PAGE_TOOLBAR, S_ID(IDS_TOOLBAR_SINGLE_ACTION), "&Single"));
_action_repeat->setText(L_S(STR_PAGE_TOOLBAR, S_ID(IDS_TOOLBAR_REPEAT_ACTION), "&Repetitive"));
}
void SamplingBar::reStyle()