DolphinQt/Assembler: improve translatability

Also, don't show error line numbers in the instruction patch dialog. The
input text field only accepts one line anyway.
This commit is contained in:
Tillmann Karras 2023-12-15 00:16:13 +00:00
parent feb831a781
commit c8c9928eb1
2 changed files with 21 additions and 16 deletions

View File

@ -17,9 +17,10 @@ namespace
{
QString HtmlFormatErrorLoc(const Common::GekkoAssembler::AssemblerError& err)
{
return QObject::tr("<span style=\"color: red; font-weight: bold\">Error</span> on line %1 col %2")
.arg(err.line + 1)
.arg(err.col + 1);
const QString error = QStringLiteral("<span style=\"color: red; font-weight: bold\">%1</span>")
.arg(QObject::tr("Error"));
// i18n: '%1' is the translation of 'Error'
return QObject::tr("%1 in column %2").arg(error).arg(err.col + 1);
}
QString HtmlFormatErrorLine(const Common::GekkoAssembler::AssemblerError& err)
@ -31,7 +32,7 @@ QString HtmlFormatErrorLine(const Common::GekkoAssembler::AssemblerError& err)
const QString line_post_error =
QString::fromStdString(std::string(err.error_line.substr(err.col + err.len))).toHtmlEscaped();
return QObject::tr("%1<u><span style=\"color:red; font-weight:bold\">%2</span></u>%3")
return QStringLiteral("%1<u><span style=\"color:red; font-weight:bold\">%2</span></u>%3")
.arg(line_pre_error)
.arg(line_error)
.arg(line_post_error);
@ -61,7 +62,6 @@ void AssembleInstructionDialog::CreateWidgets()
m_error_line_label->setFont(QFont(QFontDatabase::systemFont(QFontDatabase::FixedFont).family()));
m_input_edit->setFont(QFont(QFontDatabase::systemFont(QFontDatabase::FixedFont).family()));
layout->addWidget(new QLabel(tr("Inline Assembler")));
layout->addWidget(m_error_loc_label);
layout->addWidget(m_input_edit);
layout->addWidget(m_error_line_label);
@ -102,7 +102,8 @@ void AssembleInstructionDialog::OnEditChanged()
{
m_button_box->button(QDialogButtonBox::Ok)->setEnabled(false);
m_error_loc_label->setText(tr("<span style=\"color: red; font-weight: bold\">Error</span>"));
m_error_loc_label->setText(
QStringLiteral("<span style=\"color: red; font-weight: bold\">%1</span>").arg(tr("Error")));
m_error_line_label->clear();
m_msg_label->setText(tr("No input"));
}
@ -117,7 +118,8 @@ void AssembleInstructionDialog::OnEditChanged()
m_code = (m_code << 8) | block_bytes[i];
}
m_error_loc_label->setText(tr("<span style=\"color: green; font-weight: bold\">Ok</span>"));
m_error_loc_label->setText(
QStringLiteral("<span style=\"color: green; font-weight: bold\">%1</span>").arg(tr("OK")));
m_error_line_label->clear();
m_msg_label->setText(tr("Instruction: %1").arg(m_code, 8, 16, QLatin1Char('0')));
}

View File

@ -48,9 +48,10 @@ using namespace Common::GekkoAssembler;
QString HtmlFormatErrorLoc(const AssemblerError& err)
{
return QObject::tr("<span style=\"color: red; font-weight: bold\">Error</span> on line %1 col %2")
.arg(err.line + 1)
.arg(err.col + 1);
const QString error = QStringLiteral("<span style=\"color: red; font-weight: bold\">%1</span>")
.arg(QObject::tr("Error"));
// i18n: '%1' is the translation of 'Error'
return QObject::tr("%1 on line %1 column %2").arg(error).arg(err.line + 1).arg(err.col + 1);
}
QString HtmlFormatErrorLine(const AssemblerError& err)
@ -62,7 +63,7 @@ QString HtmlFormatErrorLine(const AssemblerError& err)
const QString line_post_error =
QString::fromStdString(std::string(err.error_line.substr(err.col + err.len))).toHtmlEscaped();
return QObject::tr("<span style=\"font-family:'monospace';font-size:16px\">"
return QStringLiteral("<span style=\"font-family:'monospace';font-size:16px\">"
"<pre>%1<u><span style=\"color:red;font-weight:bold\">%2</span></u>%3</pre>"
"</span>")
.arg(line_pre_error)
@ -72,7 +73,7 @@ QString HtmlFormatErrorLine(const AssemblerError& err)
QString HtmlFormatMessage(const AssemblerError& err)
{
return QObject::tr("<span>%1</span>").arg(QString::fromStdString(err.message).toHtmlEscaped());
return QStringLiteral("<span>%1</span>").arg(QString::fromStdString(err.message).toHtmlEscaped());
}
void DeserializeBlock(const CodeBlock& blk, std::ostringstream& out_str, bool pad4)
@ -524,8 +525,10 @@ void AssemblerWidget::OnAssemble(std::vector<CodeBlock>* asm_out)
if (!good)
{
base_address = 0;
m_error_box->append(
tr("<span style=\"color:#ffcc00\">Warning</span> invalid base address, defaulting to 0"));
const QString warning =
QStringLiteral("<span style=\"color:#ffcc00\">%1</span>").arg(tr("Warning"));
// i18n: '%1' is the translation of 'Warning'
m_error_box->append(tr("%1 invalid base address, defaulting to 0").arg(warning));
}
const std::string contents = active_editor->toPlainText().toStdString();