Skip to content

Commit 92ddcf9

Browse files
authored
i18n: translate the remaining interface corners (#10)
Load Qt's qtbase, qtmultimedia and qt_help catalogues; translate the PE info labels, the address-list Type column, thread states, the target summary, the code-finder status, the unreadable-page message, the overlay and script defaults and the breakpoint ID header; add the newer Qt 6.11 file-dialog strings to the catalogue; make the screenshot run depend on the .qm file.
1 parent 80f007c commit 92ddcf9

17 files changed

Lines changed: 1357 additions & 917 deletions

‎CMakeLists.txt‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,14 @@ if(Qt6_FOUND)
725725
qt_add_translations(cheatengine TS_FILES translations/cheatengine_zh_CN.ts
726726
INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR})
727727
if(TARGET gui_lifecycle_smoke)
728-
# The screenshots run honours CE_LANG, so the .qm has to exist.
729-
add_dependencies(gui_lifecycle_smoke cheatengine_lrelease)
728+
# The screenshots run honours CE_LANG, so the .qm has to exist next to
729+
# the binary: the catalogue resource is embedded in the app, not in this
730+
# test executable. Depend on the file, because Qt names its lrelease
731+
# target after the executable on older releases and after project() on
732+
# newer ones (Qt 6.11: cecore_lrelease).
733+
add_custom_target(cheatengine_translations
734+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/cheatengine_zh_CN.qm)
735+
add_dependencies(gui_lifecycle_smoke cheatengine_translations)
730736
endif()
731737
message(STATUS "Translations: enabled (zh_CN)")
732738
else()

‎docs/I18N.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Qt's own translations. Linux distributions package those separately
3030
it for translated standard buttons. The application's own strings work either
3131
way.
3232

33+
A few Qt stock strings are newer than the distribution's package: the file
34+
dialog passes mnemonics for its labels (`&Look in:`, `Files of &type:`) and the
35+
icon provider names the file kinds (`Drive`, `Folder`). Those sources are kept
36+
in this catalogue as well (`gui/i18n.cpp`), so recently added dialogs still
37+
follow the interface language with an older `qtbase` translation installed.
38+
3339
## What is translated
3440

3541
Everything the GUI shows: menus, actions, window and tab titles, labels,
@@ -46,6 +52,9 @@ Not covered, deliberately:
4652
tutorial steps describe exact code and instructions in the game.
4753
- Text stored in cheat tables and Lua scripts is user data, never translated.
4854
- Lua and agent tool names are part of the scripting API, never translated.
55+
- The `readelf` output the ELF inspector shows is that tool's own English text.
56+
- The shipped documentation opened from Help (`README.md`, `docs/*.md`) is
57+
written in English.
4958

5059
## For translators
5160

‎gui/addresslist_model.cpp‎

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include <sys/wait.h>
7272

7373
#include "gui/agent_panel.hpp"
74+
#include <QCoreApplication>
7475
#include <QTimer>
7576
#include <cerrno>
7677
#include <QColor>
@@ -94,6 +95,9 @@
9495
namespace ce::gui {
9596
using namespace mainwindow_detail;
9697

98+
// Defined with the Type-column helpers near the end of the file; data() needs it.
99+
static QString valueTypeLabel(ce::ValueType t);
100+
97101
// ═══════════════════════════════════════════════════════════════
98102
// AddressListModel
99103
// ═══════════════════════════════════════════════════════════════
@@ -303,7 +307,7 @@ static std::expected<size_t, std::string> writeValueToProcess(
303307
options.codec = codec; options.bigEndian = bigEndian; options.hex = showHex;
304308
if (order != ByteOrder::Unknown) options.byteOrder = order;
305309
if (pointerWidth) options.pointerWidthOverride = pointerWidth;
306-
if (!proc) return std::unexpected("No process attached");
310+
if (!proc) return std::unexpected(QCoreApplication::translate("ce::gui::AddressListModel", "No process attached").toStdString());
307311
auto resolved = ce::valueOptionsForTarget(*proc, addr, type, options);
308312
if (!resolved) return std::unexpected(resolved.error());
309313
options = *resolved;
@@ -1174,7 +1178,7 @@ QVariant AddressListModel::data(const QModelIndex& index, int role) const {
11741178
? QString("0x%1").arg(e.address, 0, 16) : e.addressExpr;
11751179
// The type editor starts from the record's type: an empty editor
11761180
// committed by clicking away changed every record to 4 Bytes.
1177-
if (index.column() == 3) return QString(ce::valueTypeName(e.type));
1181+
if (index.column() == 3) return valueTypeLabel(e.type);
11781182
if (index.column() == 4) return e.currentValue;
11791183
return {};
11801184
}
@@ -1204,7 +1208,7 @@ QVariant AddressListModel::data(const QModelIndex& index, int role) const {
12041208
if (e.isGroup) return "";
12051209
// CE-canonical name; String/Array records also show their element length
12061210
// in brackets (e.g. "String[10]", "Array of byte[8]"), like Cheat Engine.
1207-
QString name = ce::valueTypeName(e.type);
1211+
QString name = valueTypeLabel(e.type);
12081212
if ((e.type == ValueType::String || e.type == ValueType::UnicodeString ||
12091213
e.type == ValueType::ByteArray) && e.byteCount > 0)
12101214
name += QString("[%1]").arg(e.byteCount);
@@ -1368,18 +1372,42 @@ void AddressListModel::groupSelectedRows(const QList<int>& rows, const QString&
13681372
endResetModel();
13691373
}
13701374

1375+
// Localized name of the Type column. The canonical English ce::valueTypeName() stays
1376+
// the format used by cheat tables, Lua and the CLI; only the table and its editor
1377+
// show this translation.
1378+
static QString valueTypeLabel(ce::ValueType t) {
1379+
switch (t) {
1380+
case ValueType::Byte: return QCoreApplication::translate("ce::gui::AddressListModel", "Byte");
1381+
case ValueType::Int16: return QCoreApplication::translate("ce::gui::AddressListModel", "2 Bytes");
1382+
case ValueType::Int32: return QCoreApplication::translate("ce::gui::AddressListModel", "4 Bytes");
1383+
case ValueType::Int64: return QCoreApplication::translate("ce::gui::AddressListModel", "8 Bytes");
1384+
case ValueType::Float: return QCoreApplication::translate("ce::gui::AddressListModel", "Float");
1385+
case ValueType::Double: return QCoreApplication::translate("ce::gui::AddressListModel", "Double");
1386+
case ValueType::String: return QCoreApplication::translate("ce::gui::AddressListModel", "String");
1387+
case ValueType::UnicodeString: return QCoreApplication::translate("ce::gui::AddressListModel", "Unicode String");
1388+
case ValueType::ByteArray: return QCoreApplication::translate("ce::gui::AddressListModel", "Array of byte");
1389+
case ValueType::Binary: return QCoreApplication::translate("ce::gui::AddressListModel", "Binary");
1390+
case ValueType::All: return QCoreApplication::translate("ce::gui::AddressListModel", "All");
1391+
case ValueType::Grouped: return QCoreApplication::translate("ce::gui::AddressListModel", "Grouped");
1392+
case ValueType::Custom: return QCoreApplication::translate("ce::gui::AddressListModel", "Custom");
1393+
case ValueType::Pointer: return QCoreApplication::translate("ce::gui::AddressListModel", "Pointer");
1394+
}
1395+
return QCoreApplication::translate("ce::gui::AddressListModel", "4 Bytes");
1396+
}
1397+
13711398
// Parse a Type-column display name back to a ValueType. First matches the canonical
1372-
// name (ce::valueTypeName), so every name the column can show round-trips ("String",
1373-
// "Unicode String", "Array of byte", "All", ...); then a few common synonyms. Int32 fallback.
1374-
// A record's type from its name; nothing for an unknown name or a scan-only
1375-
// type (All, Grouped), which a record cannot hold.
1399+
// name (ce::valueTypeName) and its translation, so every name the column can show
1400+
// round-trips ("String", "Unicode String", "Array of byte", "All", ...); then a few
1401+
// common synonyms. Int32 fallback. A record's type from its name; nothing for an
1402+
// unknown name or a scan-only type (All, Grouped), which a record cannot hold.
13761403
static std::optional<ValueType> valueTypeFromDisplayName(const QString& s) {
13771404
QString n = s.trimmed().toLower();
13781405
if (const auto bracket = n.indexOf('['); bracket > 0) n = n.left(bracket).trimmed(); // "string[10]"
13791406
for (auto t : {ValueType::Byte, ValueType::Int16, ValueType::Int32, ValueType::Int64,
13801407
ValueType::Float, ValueType::Double, ValueType::String, ValueType::UnicodeString,
13811408
ValueType::ByteArray, ValueType::Binary, ValueType::Custom, ValueType::Pointer})
1382-
if (n == QString(ce::valueTypeName(t)).toLower()) return t;
1409+
if (n == QString(ce::valueTypeName(t)).toLower() ||
1410+
n == valueTypeLabel(t).toLower()) return t;
13831411
if (n == "word" || n == "short") return ValueType::Int16;
13841412
if (n == "dword" || n == "int") return ValueType::Int32;
13851413
if (n == "qword" || n == "long" || n == "int64") return ValueType::Int64;

‎gui/breakpointlist.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ BreakpointListWindow::BreakpointListWindow(BreakpointManager* mgr, QWidget* pare
1818
table_ = new QTableWidget;
1919
table_->setColumnCount(6);
2020
table_->setHorizontalHeaderLabels(
21-
{"ID", tr("Address"), tr("Type"), tr("Action"), tr("Hits"), tr("Enabled")});
21+
{tr("ID"), tr("Address"), tr("Type"), tr("Action"), tr("Hits"), tr("Enabled")});
2222
table_->horizontalHeader()->setStretchLastSection(true);
2323
table_->setSelectionBehavior(QAbstractItemView::SelectRows);
2424
table_->setProperty("monospace", true); // font from the theme sheet

‎gui/codefinder.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void CodeFinderWindow::refresh() {
249249
void CodeFinderWindow::onStop() {
250250
finder_->stop();
251251
stopBtn_->setEnabled(false);
252-
statusLabel_->setText(QString("Stopped. %1 unique instructions found").arg(finder_->results().size()));
252+
statusLabel_->setText(tr("Stopped. %1 unique instructions found").arg(finder_->results().size()));
253253
}
254254

255255
void CodeFinderWindow::onAddToList() {

‎gui/i18n.cpp‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ QString configuredUiLanguage() {
4646
}
4747

4848
QString installTranslators(QApplication& app, const QString& explicitLocale) {
49+
// A few Qt 6.11 stock-dialog sources are newer than the translation packages
50+
// ship: the file dialog now passes mnemonics ("&Look in:", "Files of &type:")
51+
// and the icon provider names the file kinds ("Drive", "Folder"). Marking the
52+
// newer sources here puts them in our catalogue, and the application translator
53+
// is installed last, so these stock labels are answered before Qt's own .qm.
54+
(void)QT_TRANSLATE_NOOP("QFileDialog", "&Look in:");
55+
(void)QT_TRANSLATE_NOOP("QFileDialog", "Files of &type:");
56+
(void)QT_TRANSLATE_NOOP("QAbstractFileIconProvider", "Drive");
57+
struct StockWithComment { const char* text; const char* comment; };
58+
const StockWithComment kQtStockWithComment[] = {
59+
QT_TRANSLATE_NOOP3("QAbstractFileIconProvider", "Folder", "All other platforms"),
60+
QT_TRANSLATE_NOOP3("QFileSystemModel", "Type", "All other platforms"),
61+
QT_TRANSLATE_NOOP3("QFontDatabase", "Normal", "The Normal or Regular font weight"),
62+
};
63+
(void)kQtStockWithComment;
64+
4965
// Number and date formatting keeps following the desktop locale, as before;
5066
// only the interface language changes when Settings picks one.
5167
const QLocale desktopLocale(desktopLocaleName());
@@ -56,10 +72,18 @@ QString installTranslators(QApplication& app, const QString& explicitLocale) {
5672
if (wanted.isEmpty()) wanted = desktopLocale.name();
5773
const QLocale uiLocale(wanted);
5874

59-
auto* qtTranslator = new QTranslator(&app);
60-
if (qtTranslator->load(uiLocale, QStringLiteral("qt"), QStringLiteral("_"),
61-
QLibraryInfo::path(QLibraryInfo::TranslationsPath))) {
62-
app.installTranslator(qtTranslator);
75+
// Qt 6 keeps its stock strings (dialog buttons, file dialogs, the Copy/Paste/
76+
// Select All text menu) in qtbase_<locale>.qm; qt_<locale>.qm is only a
77+
// small meta catalogue, so every module catalogue is loaded when present.
78+
const QString qtTranslationsDir = QLibraryInfo::path(QLibraryInfo::TranslationsPath);
79+
for (const QString& module : {QStringLiteral("qt"), QStringLiteral("qtbase"),
80+
QStringLiteral("qtmultimedia"), QStringLiteral("qt_help")}) {
81+
auto* qtTranslator = new QTranslator(&app);
82+
if (qtTranslator->load(uiLocale, module, QStringLiteral("_"), qtTranslationsDir)) {
83+
app.installTranslator(qtTranslator);
84+
} else {
85+
delete qtTranslator;
86+
}
6387
}
6488

6589
// A catalogue dropped next to the executable wins over the built-in one, so

‎gui/mainwindow.hpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
class QDockWidget;
4949
class QMenu;
5050
namespace ce { class ExpressionParser; }
51+
namespace ce { struct TargetProfile; }
5152

5253
namespace ce::gui {
5354

@@ -654,4 +655,9 @@ class AddressListModel : public QAbstractTableModel, public ce::IAddressList {
654655
uint64_t replaceGeneration_ = 0; // see IAddressList::replaceGeneration
655656
};
656657

658+
/// Localized one-line description of a target ("x86-64 native process",
659+
/// "Wine/Proton x86-64 game", ...), for the process header, the status bar and
660+
/// the system info dialog. ce::TargetProfile::summary() is Qt-free and English.
661+
QString targetSummaryText(const ce::TargetProfile& profile);
662+
657663
} // namespace ce::gui

‎gui/mainwindow_menus.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void MainWindow::buildProcessMenu(const MenuBarMenus& menus) {
279279
target->addRow(tr("PID:"), value(QString::number(currentPid_)));
280280
target->addRow(tr("Executable:"), value(modules.empty() ? QString(tr("(unknown)")) : QString::fromStdString(modules.front().path)));
281281
if (auto localPid = ce::localTargetPid(process_.get()))
282-
target->addRow(tr("Kind:"), value(QString::fromStdString(ce::probeTarget(*localPid).summary())));
282+
target->addRow(tr("Kind:"), value(targetSummaryText(ce::probeTarget(*localPid))));
283283
target->addRow(tr("Program:"), value(QString(tr("%1, %2-byte pointers, %3"))
284284
.arg(ce::cpuArchitectureName(description.program.architecture)).arg(description.program.pointerWidth)
285285
.arg(ce::byteOrderName(description.program.byteOrder))));

‎gui/mainwindow_process.cpp‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ void MainWindow::attachToPid(pid_t pid, const QString& name) {
300300
// explicit note, not a silent surprise later. See docs/CHALLENGING_TARGETS.md.
301301
{
302302
ce::TargetProfile prof = ce::probeTarget(pid);
303-
processDetail_->setText(QString("PID %1 · %2").arg(pid).arg(QString::fromStdString(prof.summary())));
303+
processDetail_->setText(QString("PID %1 · %2").arg(pid).arg(targetSummaryText(prof)));
304304
statusBar()->showMessage(
305-
QString(tr("Attached to %1: %2")).arg(label, QString::fromStdString(prof.summary())), 8000);
305+
QString(tr("Attached to %1: %2")).arg(label, targetSummaryText(prof)), 8000);
306306
// The summary + every note live on the process label's tooltip (persistent,
307307
// non-intrusive; hover to read).
308-
QString tip = QString::fromStdString(prof.summary());
308+
QString tip = targetSummaryText(prof);
309309
for (const auto& n : prof.notes) tip += "\n\n• " + QString::fromStdString(n);
310310
auto target = process_->targetDescription();
311311
tip += QString(tr("\n\nProgram: %1, %2-byte pointers, %3\nHost ABI: %4"))
@@ -324,6 +324,20 @@ void MainWindow::attachToPid(pid_t pid, const QString& name) {
324324
}
325325
}
326326

327+
QString targetSummaryText(const ce::TargetProfile& profile) {
328+
if (!profile.valid) return QCoreApplication::translate("ce::gui::MainWindow", "unknown target");
329+
const QString arch = QString::fromStdString(profile.archName());
330+
if (!profile.emulator.empty())
331+
return QCoreApplication::translate("ce::gui::MainWindow", "%1 emulator (%2)")
332+
.arg(QString::fromStdString(profile.emulator), arch);
333+
if (profile.wine)
334+
return QCoreApplication::translate("ce::gui::MainWindow", "Wine/Proton %1 game").arg(arch);
335+
if (!profile.runtimes.empty())
336+
return QCoreApplication::translate("ce::gui::MainWindow", "%1 app (%2)")
337+
.arg(QString::fromStdString(profile.runtimes.front()), arch);
338+
return QCoreApplication::translate("ce::gui::MainWindow", "%1 native process").arg(arch);
339+
}
340+
327341
void MainWindow::onOpenProcess() {
328342
ProcessListDialog dlg(this);
329343
if (dlg.exec() == QDialog::Accepted)

‎gui/memorybrowser.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2371,7 +2371,7 @@ void MemoryBrowser::syncViews(uintptr_t addr) {
23712371
auto pr = proc_->read(addr, &probe, 1);
23722372
if (!pr || *pr != 1)
23732373
statusBar()->showMessage(
2374-
QString("0x%1 is not readable (unmapped or protected page)").arg(addr, 0, 16), 5000);
2374+
tr("0x%1 is not readable (unmapped or protected page)").arg(addr, 0, 16), 5000);
23752375
}
23762376
}
23772377

0 commit comments

Comments
 (0)