Further improvements to the translation system

This commit is contained in:
Alexander Babikov
2024-11-13 19:42:27 +05:00
parent 6110a60f14
commit 83064c6e21
4 changed files with 24 additions and 33 deletions

View File

@@ -124,11 +124,7 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
return; return;
while (config->type != -1) { while (config->type != -1) {
const int config_type = config->type & CONFIG_TYPE_MASK; const int config_type = config->type & CONFIG_TYPE_MASK;
const char *temp = tr(config->description).toUtf8().data();
char tdesc[512] = { 0 };
strcpy(tdesc, temp);
/* Ignore options of the wrong class. */ /* Ignore options of the wrong class. */
if (!!(config->type & CONFIG_DEP) != is_dep) if (!!(config->type & CONFIG_DEP) != is_dep)
@@ -172,7 +168,7 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
auto *cbox = new QCheckBox(); auto *cbox = new QCheckBox();
cbox->setObjectName(config->name); cbox->setObjectName(config->name);
cbox->setChecked(value > 0); cbox->setChecked(value > 0);
this->ui->formLayout->addRow(tdesc, cbox); this->ui->formLayout->addRow(tr(config->description), cbox);
break; break;
} }
#ifdef USE_RTMIDI #ifdef USE_RTMIDI
@@ -187,11 +183,11 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
char midiName[512] = { 0 }; char midiName[512] = { 0 };
rtmidi_out_get_dev_name(i, midiName); rtmidi_out_get_dev_name(i, midiName);
Models::AddEntry(model, tr(midiName), i); Models::AddEntry(model, midiName, i);
if (i == value) if (i == value)
currentIndex = i; currentIndex = i;
} }
this->ui->formLayout->addRow(tdesc, cbox); this->ui->formLayout->addRow(tr(config->description), cbox);
cbox->setCurrentIndex(currentIndex); cbox->setCurrentIndex(currentIndex);
break; break;
} }
@@ -206,11 +202,11 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
char midiName[512] = { 0 }; char midiName[512] = { 0 };
rtmidi_in_get_dev_name(i, midiName); rtmidi_in_get_dev_name(i, midiName);
Models::AddEntry(model, tr(midiName), i); Models::AddEntry(model, midiName, i);
if (i == value) if (i == value)
currentIndex = i; currentIndex = i;
} }
this->ui->formLayout->addRow(tdesc, cbox); this->ui->formLayout->addRow(tr(config->description), cbox);
cbox->setCurrentIndex(currentIndex); cbox->setCurrentIndex(currentIndex);
break; break;
} }
@@ -225,17 +221,15 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
cbox->setMaxVisibleItems(30); cbox->setMaxVisibleItems(30);
auto *model = cbox->model(); auto *model = cbox->model();
int currentIndex = -1; int currentIndex = -1;
for (auto *sel = config->selection; (sel != nullptr) && (sel->description != nullptr) && for (auto *sel = config->selection; (sel != nullptr) && (sel->description != nullptr) &&
(strlen(sel->description) > 0); ++sel) { (strlen(sel->description) > 0); ++sel) {
const char *temp2 = tr(sel->description).toUtf8().data(); int row = Models::AddEntry(model, tr(sel->description), sel->value);
char sdesc[512] = { 0 };
strcpy(sdesc, temp2);
int row = Models::AddEntry(model, sdesc, sel->value);
if (sel->value == value) if (sel->value == value)
currentIndex = row; currentIndex = row;
} }
this->ui->formLayout->addRow(tdesc, cbox); this->ui->formLayout->addRow(tr(config->description), cbox);
cbox->setCurrentIndex(currentIndex); cbox->setCurrentIndex(currentIndex);
break; break;
} }
@@ -254,16 +248,13 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
for (int d = 0; d < bios->files_no; d++) for (int d = 0; d < bios->files_no; d++)
p += !!rom_present(const_cast<char *>(bios->files[d])); p += !!rom_present(const_cast<char *>(bios->files[d]));
if (p == bios->files_no) { if (p == bios->files_no) {
const char *temp2 = tr(bios->name).toUtf8().data(); const int row = Models::AddEntry(model, tr(bios->name), q);
char bname[512] = { 0 };
strcpy(bname, temp2);
const int row = Models::AddEntry(model, bname, q);
if (!strcmp(selected.toUtf8().constData(), bios->internal_name)) if (!strcmp(selected.toUtf8().constData(), bios->internal_name))
currentIndex = row; currentIndex = row;
} }
q++; q++;
} }
this->ui->formLayout->addRow(tdesc, cbox); this->ui->formLayout->addRow(tr(config->description), cbox);
cbox->setCurrentIndex(currentIndex); cbox->setCurrentIndex(currentIndex);
break; break;
} }
@@ -276,7 +267,7 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
if (config->spinner.step > 0) if (config->spinner.step > 0)
spinBox->setSingleStep(config->spinner.step); spinBox->setSingleStep(config->spinner.step);
spinBox->setValue(value); spinBox->setValue(value);
this->ui->formLayout->addRow(tdesc, spinBox); this->ui->formLayout->addRow(tr(config->description), spinBox);
break; break;
} }
case CONFIG_FNAME: case CONFIG_FNAME:
@@ -286,7 +277,7 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
fileField->setFileName(selected); fileField->setFileName(selected);
fileField->setFilter(QString(config->file_filter).left(static_cast<int>(strcspn(config->file_filter, fileField->setFilter(QString(config->file_filter).left(static_cast<int>(strcspn(config->file_filter,
"|")))); "|"))));
this->ui->formLayout->addRow(tdesc, fileField); this->ui->formLayout->addRow(tr(config->description), fileField);
break; break;
} }
case CONFIG_STRING: case CONFIG_STRING:
@@ -295,7 +286,7 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
lineEdit->setObjectName(config->name); lineEdit->setObjectName(config->name);
lineEdit->setCursor(Qt::IBeamCursor); lineEdit->setCursor(Qt::IBeamCursor);
lineEdit->setText(selected); lineEdit->setText(selected);
this->ui->formLayout->addRow(tdesc, lineEdit); this->ui->formLayout->addRow(tr(config->description), lineEdit);
break; break;
} }
case CONFIG_SERPORT: case CONFIG_SERPORT:
@@ -314,7 +305,7 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
currentIndex = row; currentIndex = row;
} }
this->ui->formLayout->addRow(tdesc, cbox); this->ui->formLayout->addRow(tr(config->description), cbox);
cbox->setCurrentIndex(currentIndex); cbox->setCurrentIndex(currentIndex);
break; break;
} }
@@ -346,7 +337,7 @@ DeviceConfig::ProcessConfig(void *dc, const void *c, const bool is_dep)
}); });
hboxLayout->addWidget(lineEdit); hboxLayout->addWidget(lineEdit);
hboxLayout->addWidget(generateButton); hboxLayout->addWidget(generateButton);
this->ui->formLayout->addRow(tdesc, hboxLayout); this->ui->formLayout->addRow(tr(config->description), hboxLayout);
break; break;
} }
} }
@@ -358,15 +349,15 @@ void
DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *settings) DeviceConfig::ConfigureDevice(const _device_ *device, int instance, Settings *settings)
{ {
DeviceConfig dc(settings); DeviceConfig dc(settings);
dc.setWindowTitle(QString(tr("%1 Device Configuration")).arg(device->name)); dc.setWindowTitle(tr("%1 Device Configuration").arg(tr(device->name)));
device_context_t device_context; device_context_t device_context;
device_set_context(&device_context, device, instance); device_set_context(&device_context, device, instance);
const auto device_label = new QLabel(device->name); const auto device_label = new QLabel(tr(device->name));
device_label->setAlignment(Qt::AlignCenter); device_label->setAlignment(Qt::AlignCenter);
dc.ui->formLayout->addRow(device_label); dc.ui->formLayout->addRow(device_label);
const auto line = new QFrame; const auto line = new QFrame;
line->setFrameShape(QFrame::HLine); line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken); line->setFrameShadow(QFrame::Sunken);
dc.ui->formLayout->addRow(line); dc.ui->formLayout->addRow(line);
@@ -472,6 +463,6 @@ DeviceConfig::DeviceName(const _device_ *device, const char *internalName, const
else { else {
char temp[512]; char temp[512];
device_get_name(device, bus, temp); device_get_name(device, bus, temp);
return tr(temp, nullptr, 512); return tr((const char *) temp);
} }
} }

View File

@@ -77,7 +77,7 @@ SettingsInput::onCurrentMachineChanged(int machineId)
mouseModel->insertRow(row); mouseModel->insertRow(row);
auto idx = mouseModel->index(row, 0); auto idx = mouseModel->index(row, 0);
mouseModel->setData(idx, tr(name.toUtf8().data()), Qt::DisplayRole); mouseModel->setData(idx, name, Qt::DisplayRole);
mouseModel->setData(idx, i, Qt::UserRole); mouseModel->setData(idx, i, Qt::UserRole);
if (i == mouse_type) { if (i == mouse_type) {

View File

@@ -127,7 +127,7 @@ SettingsNetwork::onCurrentMachineChanged(int machineId)
} }
if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machineId)) { if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machineId)) {
int row = Models::AddEntry(model, tr(name.toUtf8().data()), c); int row = Models::AddEntry(model, name, c);
if (c == net_cards_conf[i].device_num) { if (c == net_cards_conf[i].device_num) {
selectedRow = row - removeRows; selectedRow = row - removeRows;
} }

View File

@@ -119,7 +119,7 @@ SettingsSound::onCurrentMachineChanged(const int machineId)
} }
if (midi_out_device_available(c)) { if (midi_out_device_available(c)) {
int row = Models::AddEntry(model, tr(name.toUtf8().data()), c); int row = Models::AddEntry(model, name, c);
if (c == midi_output_device_current) { if (c == midi_output_device_current) {
selectedRow = row - removeRows; selectedRow = row - removeRows;
} }
@@ -142,7 +142,7 @@ SettingsSound::onCurrentMachineChanged(const int machineId)
} }
if (midi_in_device_available(c)) { if (midi_in_device_available(c)) {
int row = Models::AddEntry(model, tr(name.toUtf8().data()), c); int row = Models::AddEntry(model, name, c);
if (c == midi_input_device_current) { if (c == midi_input_device_current) {
selectedRow = row - removeRows; selectedRow = row - removeRows;
} }