Skip to content

Commit

Permalink
Use tr for translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Inokinoki committed Jun 25, 2024
1 parent 80261d8 commit 3f72b20
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 76 deletions.
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ int main(int argc, char *argv[])
a.setWindowIcon(QIcon("../cc.inoki.qefientrymanager.png"));

if (!qefi_is_available() || !qefi_has_privilege()) {
QMessageBox::critical(nullptr, QStringLiteral("Error"),
QStringLiteral("Permission insufficient or no EFI environment"));
QMessageBox::critical(nullptr, QObject::tr("Error"),
QObject::tr("Permission insufficient or no EFI environment"));
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Set window attributes
this->setWindowTitle(QStringLiteral("EFI Entry Manager"));
this->setWindowTitle(tr("EFI Entry Manager"));
this->resize(800, 600);

// Create a class for each page amd keep a ref to update
Expand Down
28 changes: 14 additions & 14 deletions qefidpeditorview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ QEFIDPEditorView::QEFIDPEditorView(QEFIDevicePath *dp, QWidget *parent)
m_topLevelLayout = new QFormLayout(this);

m_dpTypeSelector = new QComboBox(this);
// m_dpTypeSelector->setPlaceholderText(QStringLiteral("Device Path type"));
// m_dpTypeSelector->setPlaceholderText(tr("Device Path type"));
// m_dpTypeSelector->addItem(
// convert_device_path_type_to_name(QEFIDevicePathType::DP_Hardware),
// QVariant(QEFIDevicePathType::DP_Hardware));
Expand All @@ -36,7 +36,7 @@ QEFIDPEditorView::QEFIDPEditorView(QEFIDevicePath *dp, QWidget *parent)
this, &QEFIDPEditorView::dpTypeComboBoxCurrentIndexChanged);

m_dpSubtypeSelector = new QComboBox(this);
// m_dpSubtypeSelector->setPlaceholderText(QStringLiteral("Device Path subtype"));
// m_dpSubtypeSelector->setPlaceholderText(tr("Device Path subtype"));
if (dp != nullptr) {
QList<quint8> subtypes = enum_device_path_subtype(dp->type());
for (int i = 0; i < subtypes.size(); i++) {
Expand Down Expand Up @@ -163,32 +163,32 @@ QEFIDevicePath *QEFIDPEditorView::getDevicePath()
for (int i = 0; i < m_currentWidgets.size(); i++) {
qDebug() << m_currentWidgets[i].first;
// TODO: Int range
if (m_currentWidgets[i].first == QStringLiteral("Partition Num")) {
if (m_currentWidgets[i].first == tr("Partition Num")) {
QVariant data = retrieveDPEditComponent(
QEFIDPEditType::EditType_Number, m_currentWidgets[i].second);
if (data.isNull()) return dp;
partitionNumber = data.toInt();
} else if (m_currentWidgets[i].first == QStringLiteral("Start")) {
} else if (m_currentWidgets[i].first == tr("Start")) {
QVariant data = retrieveDPEditComponent(
QEFIDPEditType::EditType_Number, m_currentWidgets[i].second);
if (data.isNull()) return dp;
start = data.toInt();
} else if (m_currentWidgets[i].first == QStringLiteral("Size")) {
} else if (m_currentWidgets[i].first == tr("Size")) {
QVariant data = retrieveDPEditComponent(
QEFIDPEditType::EditType_Number, m_currentWidgets[i].second);
if (data.isNull()) return dp;
size = data.toInt();
} else if (m_currentWidgets[i].first == QStringLiteral("Format")) {
} else if (m_currentWidgets[i].first == tr("Format")) {
QVariant data = retrieveDPEditComponent(
QEFIDPEditType::EditType_Enum, m_currentWidgets[i].second);
if (data.isNull()) return dp;
format = data.toInt();
} else if (m_currentWidgets[i].first == QStringLiteral("Signature Type")) {
} else if (m_currentWidgets[i].first == tr("Signature Type")) {
QVariant data = retrieveDPEditComponent(
QEFIDPEditType::EditType_Enum, m_currentWidgets[i].second);
if (data.isNull()) return dp;
signatureType = data.toInt();
} else if (m_currentWidgets[i].first == QStringLiteral("Signature")) {
} else if (m_currentWidgets[i].first == tr("Signature")) {
QVariant data = retrieveDPEditComponent(
QEFIDPEditType::EditType_HexData, m_currentWidgets[i].second);
if (data.isNull() || data.type() != QVariant::Type::ByteArray) return dp;
Expand All @@ -210,7 +210,7 @@ QEFIDevicePath *QEFIDPEditorView::getDevicePath()
{
QString filepath;
for (int i = 0; i < m_currentWidgets.size(); i++) {
if (m_currentWidgets[i].first == QStringLiteral("File")) {
if (m_currentWidgets[i].first == tr("File")) {
QVariant data = retrieveDPEditComponent(
QEFIDPEditType::EditType_Path, m_currentWidgets[i].second);
if (data.isNull() || data.type() != QVariant::Type::String) return dp;
Expand Down Expand Up @@ -353,24 +353,24 @@ QList<QPair<QString, QWidget *> > QEFIDPEditorView::constructDPEditView(
if (types[i].first == "Format") {
QComboBox *comboBox = dynamic_cast<QComboBox *>(w);
if (comboBox != nullptr) {
comboBox->addItem(QStringLiteral("GPT"),
comboBox->addItem(tr("GPT"),
QVariant(QEFIDevicePathMediaHD::
QEFIDevicePathMediaHDFormat::GPT));
comboBox->addItem(QStringLiteral("PCAT"),
comboBox->addItem(tr("PCAT"),
QVariant(QEFIDevicePathMediaHD::
QEFIDevicePathMediaHDFormat::PCAT));
}
}
if (types[i].first == "Signature Type") {
QComboBox *comboBox = dynamic_cast<QComboBox *>(w);
if (comboBox != nullptr) {
comboBox->addItem(QStringLiteral("None"),
comboBox->addItem(tr("None"),
QVariant(QEFIDevicePathMediaHD::
QEFIDevicePathMediaHDSignatureType::NONE));
comboBox->addItem(QStringLiteral("MBR"),
comboBox->addItem(tr("MBR"),
QVariant(QEFIDevicePathMediaHD::
QEFIDevicePathMediaHDSignatureType::MBR));
comboBox->addItem(QStringLiteral("GUID"),
comboBox->addItem(tr("GUID"),
QVariant(QEFIDevicePathMediaHD::
QEFIDevicePathMediaHDSignatureType::GUID));
}
Expand Down
6 changes: 3 additions & 3 deletions qefientrydetailview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ QEFIEntryDetailBriefView::QEFIEntryDetailBriefView(
QEFILoadOption *loadOption = entry.loadOption();
if (loadOption) {
auto dpList = loadOption->devicePathList();
m_briefLayout->addRow("Device Path instance:",
m_briefLayout->addRow(tr("Device Path instance:"),
new QLabel(QString::number(dpList.size())));
// Add a tab to display each DP
for (int i = 0; i < dpList.size(); i++) {
// Display type name
m_briefLayout->addRow(QString::asprintf("Device Path %d type:", i + 1),
m_briefLayout->addRow(tr("Device Path %d type:").arg(i + 1),
new QLabel(
convert_device_path_type_to_name(dpList[i]->type()) + " " +
convert_device_path_subtype_to_name(dpList[i]->type(),
Expand Down Expand Up @@ -54,7 +54,7 @@ QEFIEntryDetailView::QEFIEntryDetailView(QEFIEntry &entry, QWidget *parent)
m_topLevelLayout = new QBoxLayout(QBoxLayout::LeftToRight, this);
m_tab = new QTabWidget(this);
m_tab->addTab(new QEFIEntryDetailBriefView(entry, m_tab),
QStringLiteral("Brief"));
tr("Brief"));

QEFILoadOption *loadOption = entry.loadOption();
if (loadOption) {
Expand Down
90 changes: 45 additions & 45 deletions qefientryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ QEFIEntryView::QEFIEntryView(QWidget *parent)
m_buttonLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
m_topLevelLayout->addLayout(m_buttonLayout, 1);

m_moveUpEntryButton = new QPushButton(QStringLiteral("Move up"), this);
m_moveDownEntryButton = new QPushButton(QStringLiteral("Move down"), this);
m_setCurrentButton = new QPushButton(QStringLiteral("Make default"), this);
m_rebootTargetButton = new QPushButton(QStringLiteral("Set reboot"), this);
m_moveUpEntryButton = new QPushButton(tr("Move up"), this);
m_moveDownEntryButton = new QPushButton(tr("Move down"), this);
m_setCurrentButton = new QPushButton(tr("Make default"), this);
m_rebootTargetButton = new QPushButton(tr("Set reboot"), this);
m_rebootTargetButton->setDisabled(true);
m_buttonLayout->addWidget(m_moveUpEntryButton);
m_buttonLayout->addWidget(m_moveDownEntryButton);
Expand All @@ -76,12 +76,12 @@ QEFIEntryView::QEFIEntryView(QWidget *parent)

m_buttonLayout->addStretch(1);

m_bootTimeoutLabel = new QLabel(QString::asprintf("Timeout: %d second(s)",
m_bootTimeoutLabel = new QLabel(tr("Timeout: %d second(s)").arg(
QEFIEntryStaticList::instance()->timeout()), this);
m_addButton = new QPushButton(QStringLiteral("Add"), this);
m_importButton = new QPushButton(QStringLiteral("Import"), this);
m_saveButton = new QPushButton(QStringLiteral("Save"), this);
m_resetButton = new QPushButton(QStringLiteral("Reset"), this);
m_addButton = new QPushButton(tr("Add"), this);
m_importButton = new QPushButton(tr("Import"), this);
m_saveButton = new QPushButton(tr("Save"), this);
m_resetButton = new QPushButton(tr("Reset"), this);
m_buttonLayout->addWidget(m_bootTimeoutLabel);
m_buttonLayout->addWidget(m_addButton);
m_buttonLayout->addWidget(m_importButton);
Expand Down Expand Up @@ -237,9 +237,9 @@ void QEFIEntryView::rebootClicked(bool checked)
<< m_entryItems[m_order[m_selectedItemIndex]].name() << " as reboot target";
// Set BootNext
QEFIEntryStaticList::instance()->setBootNext(m_order[m_selectedItemIndex]);
int ret = QMessageBox::warning(this, QStringLiteral("Reboot to ") +
int ret = QMessageBox::warning(this, tr("Reboot to ") +
m_entryItems[m_order[m_selectedItemIndex]].name(),
QStringLiteral("Do you want to reboot now?"),
tr("Do you want to reboot now?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (ret == QMessageBox::Yes) {
Expand Down Expand Up @@ -323,13 +323,13 @@ void QEFIEntryView::exportClicked(bool checked)
getRawData(m_order[m_selectedItemIndex]);
if (data.size() == 0) {
// Show a warning and stop
QMessageBox::warning(this, QStringLiteral("Export failed"),
QStringLiteral("Data to export is empty."));
QMessageBox::warning(this, tr("Export failed"),
tr("Data to export is empty."));
return;
}
#if QT_VERSION < QT_VERSION_CHECK(5,14,0)
QString exportFilename = QFileDialog::getSaveFileName(this,
QString::asprintf("Export Boot%04X", m_order[m_selectedItemIndex]));
tr("Export Boot%04X").arg(m_order[m_selectedItemIndex]));
QSaveFile exportFile(exportFilename);
exportFile.open(QIODevice::WriteOnly);
exportFile.write(data);
Expand All @@ -351,25 +351,25 @@ void QEFIEntryView::contextMenuEvent(QContextMenuEvent *event)

QEFIEntry &entry = m_entryItems[m_order[m_selectedItemIndex]];
connect(menu.addAction(entry.isActive() ?
QStringLiteral("Disable") : QStringLiteral("Enable")),
tr("Disable") : tr("Enable")),
&QAction::triggered, this, &QEFIEntryView::visibilityClicked);

connect(menu.addAction(QStringLiteral("Delete")), &QAction::triggered,
connect(menu.addAction(tr("Delete")), &QAction::triggered,
this, &QEFIEntryView::deleteClicked);

connect(menu.addAction(QStringLiteral("Export")), &QAction::triggered,
connect(menu.addAction(tr("Export")), &QAction::triggered,
this, &QEFIEntryView::exportClicked);

connect(menu.addAction(QStringLiteral("Property")), &QAction::triggered,
connect(menu.addAction(tr("Property")), &QAction::triggered,
this, &QEFIEntryView::detailClicked);

menu.addSeparator();
}
}
connect(menu.addAction(QStringLiteral("Add")), &QAction::triggered,
connect(menu.addAction(tr("Add")), &QAction::triggered,
this, &QEFIEntryView::addClicked);

connect(menu.addAction(QStringLiteral("Import")), &QAction::triggered,
connect(menu.addAction(tr("Import")), &QAction::triggered,
this, &QEFIEntryView::importClicked);

menu.exec(event->globalPos());
Expand Down Expand Up @@ -400,51 +400,51 @@ void QEFIEntryView::importClicked(bool checked)
QEFILoadOption loadOption(data);
if (!loadOption.isValidated()) {
// Show a warning and stop
QMessageBox::warning(this, QStringLiteral("Import failed"),
QStringLiteral("Data are invalidated."));
QMessageBox::warning(this, tr("Import failed"),
tr("Data are invalidated."));
return;
}

// Choose an ID
QInputDialog dialog(this);
dialog.setWindowTitle(QStringLiteral("Choose an ID"));
dialog.setLabelText(QStringLiteral("Hex value from 0 to FFFF"));
dialog.setWindowTitle(tr("Choose an ID"));
dialog.setLabelText(tr("Hex value from 0 to FFFF"));
dialog.setIntRange(0, 0xFFFF);
dialog.setIntValue(0x1000);
dialog.setIntStep(1);
QSpinBox *spinbox = dialog.findChild<QSpinBox*>();
if (spinbox) spinbox->setDisplayIntegerBase(16);
if (dialog.exec() != QDialog::Accepted) {
// Show a warning and stop
QMessageBox::warning(this, QStringLiteral("Import failed"),
QStringLiteral("The action is cancelled."));
QMessageBox::warning(this, tr("Import failed"),
tr("The action is cancelled."));
return;
}
bool validatedBootID = false;
quint16 bootID = spinbox->text().toInt(&validatedBootID, 16);
if (!validatedBootID) {
// Show a warning and stop
QMessageBox::warning(this, QStringLiteral("Import failed"),
QStringLiteral("The chosen ID is invalidated."));
QMessageBox::warning(this, tr("Import failed"),
tr("The chosen ID is invalidated."));
return;
}
bool orderFound = m_order.contains(bootID);
if (orderFound) {
// Override: Show a confirmation
if (QMessageBox::question(this, QStringLiteral("Import"),
QString::asprintf("Do you want to override Boot%04X?", bootID)) ==
if (QMessageBox::question(this, tr("Import"),
tr("Do you want to override Boot%04X?").arg(bootID)) ==
QMessageBox::No) {
// Show a warning and stop
QMessageBox::warning(this, QStringLiteral("Import failed"),
QStringLiteral("The action is cancelled."));
QMessageBox::warning(this, tr("Import failed"),
tr("The action is cancelled."));
return;
}
}

if (!QEFIEntryStaticList::instance()->updateBootEntry(bootID, data)) {
// Show a warning and stop
QMessageBox::warning(this, QStringLiteral("Import failed"),
QStringLiteral("Data might be invalidated."));
QMessageBox::warning(this, tr("Import failed"),
tr("Data might be invalidated."));
return;
}

Expand All @@ -468,7 +468,7 @@ class BootEntryEditorDialog : public QDialog
: QDialog(parent)
{
m_view = new QEFILoadOptionEditorView(nullptr, this);
setWindowTitle(QStringLiteral("Add EFI Boot Entry"));
setWindowTitle(tr("Add EFI Boot Entry"));
m_topLevelLayout = new QBoxLayout(QBoxLayout::Down, this);
m_topLevelLayout->addWidget(m_view);

Expand Down Expand Up @@ -515,36 +515,36 @@ void QEFIEntryView::addClicked(bool checked)
QByteArray data = dialog.loadOptionData();
if (data.size() == 0) {
// Error
QMessageBox::warning(this, QStringLiteral("Add failed"),
QStringLiteral("Data might be invalidated."));
QMessageBox::warning(this, tr("Add failed"),
tr("Data might be invalidated."));
}

// Parse using a QEFILoadOption
QEFILoadOption loadOption(data);
if (!loadOption.isValidated()) {
// Show a warning and stop
QMessageBox::warning(this, QStringLiteral("Add failed"),
QStringLiteral("Data are invalidated."));
QMessageBox::warning(this, tr("Add failed"),
tr("Data are invalidated."));
return;
}

bool orderFound = m_order.contains(bootID);
if (orderFound) {
// Override: Show a confirmation
if (QMessageBox::question(this, QStringLiteral("Add"),
QString::asprintf("Do you want to override Boot%04X?", bootID)) ==
if (QMessageBox::question(this, tr("Add"),
tr("Do you want to override Boot%04X?").arg(bootID)) ==
QMessageBox::No) {
// Show a warning and stop
QMessageBox::warning(this, QStringLiteral("Add failed"),
QStringLiteral("The action is cancelled."));
QMessageBox::warning(this, tr("Add failed"),
tr("The action is cancelled."));
return;
}
}

if (!QEFIEntryStaticList::instance()->updateBootEntry(bootID, data)) {
// Show a warning and stop
QMessageBox::warning(this, QStringLiteral("Add failed"),
QStringLiteral("Data might be invalidated."));
QMessageBox::warning(this, tr("Add failed"),
tr("Data might be invalidated."));
return;
}

Expand Down
Loading

0 comments on commit 3f72b20

Please sign in to comment.