From ccf2c0d32521e3d86a9886eac53644b3e5ba030b Mon Sep 17 00:00:00 2001 From: KasaneTeto-LLY Date: Mon, 7 Sep 2026 20:32:56 +0800 Subject: [PATCH 1/4] feat(i18n): add Qt-native multilingual UI with Simplified Chinese pack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a language selector (Options -> Language: System default / English / 简体中文) backed by the Qt translation system: - New I18n module loads tux-manager_.qm and the Qt qtbase_* catalog. Translations are embedded in the binary via CONFIG += lrelease embed_translations (:/i18n/) and are also installed as filesystem .qm files for the .deb. - Language preference is stored in General/Language (empty = follow the system locale). - Switching languages prompts the user and restarts the application so every widget/model is re-translated consistently. - Wrap previously hard-coded process-table headers and process-state strings in tr(). - Add tux-manager_zh_CN.ts with 399 translated messages (0 unfinished). - Package translations under /usr/share/tux-manager/translations/ and add the qt6 qttools/lrelease build dependency for the Debian build. --- .gitignore | 4 + debian/control | 3 +- debian/install | 1 + src/TuxManager.pro | 11 + src/configuration.cpp | 2 + src/configuration.h | 2 + src/i18n.cpp | 197 +++ src/i18n.h | 48 + src/main.cpp | 6 + src/mainwindow.cpp | 60 +- src/mainwindow.h | 1 + src/os/process.cpp | 17 +- src/os/processmodel.cpp | 36 +- src/os/processtreemodel.cpp | 36 +- src/translations/tux-manager_zh_CN.ts | 2244 +++++++++++++++++++++++++ 15 files changed, 2622 insertions(+), 46 deletions(-) create mode 100644 src/i18n.cpp create mode 100644 src/i18n.h create mode 100644 src/translations/tux-manager_zh_CN.ts diff --git a/.gitignore b/.gitignore index 260907c..bb20a1e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ Makefile .qmake.stash .qmake.cache +# lrelease-generated compiled translations (embedded into the binary at build) +src/.qm/ +*.qm + # Build directories build/ debug/ diff --git a/debian/control b/debian/control index 0a53a47..6453512 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,8 @@ Priority: optional Maintainer: Petr Bena Build-Depends: debhelper-compat (= 12), pkg-config, - qtbase5-dev | qt6-base-dev + qtbase5-dev | qt6-base-dev, + qt6-l10n-tools | qttools5-dev-tools Standards-Version: 4.6.2 Rules-Requires-Root: no diff --git a/debian/install b/debian/install index 0474b0d..7af522d 100644 --- a/debian/install +++ b/debian/install @@ -1,3 +1,4 @@ debian/build/tux-manager usr/bin/ +debian/build/.qm/tux-manager_zh_CN.qm usr/share/tux-manager/translations/ src/tux_manager_icon.svg usr/share/pixmaps/ packaging/data/io.github.benapetr.TuxManager.desktop usr/share/applications/ diff --git a/src/TuxManager.pro b/src/TuxManager.pro index 983b55e..c49df9b 100644 --- a/src/TuxManager.pro +++ b/src/TuxManager.pro @@ -13,6 +13,7 @@ SOURCES += \ aboutdialog.cpp \ colorschemedialog.cpp \ colorscheme.cpp \ + i18n.cpp \ main.cpp \ mainwindow.cpp \ metrics.cpp \ @@ -68,6 +69,7 @@ HEADERS += \ colorschemedialog.h \ colorscheme.h \ globals.h \ + i18n.h \ mainwindow.h \ metrics.h \ misc.h \ @@ -138,6 +140,15 @@ FORMS += \ RESOURCES += \ resources.qrc +# ── Translations ────────────────────────────────────────────────────────────── +# Qt Linguist machinery: the .ts files in TRANSLATIONS are compiled into .qm at +# build time (lrelease) and embedded into the binary under :/i18n/. That keeps +# the translations working no matter where the application is installed from. +TRANSLATIONS += \ + translations/tux-manager_zh_CN.ts + +CONFIG += lrelease embed_translations + # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin diff --git a/src/configuration.cpp b/src/configuration.cpp index 34d16c3..1338f31 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -82,6 +82,7 @@ void Configuration::Load() this->RefreshPaused = s.value("General/RefreshPaused", this->RefreshPaused).toBool(); this->UseCustomColorScheme = s.value("General/UseCustomColorScheme", this->UseCustomColorScheme).toBool(); this->CustomColorScheme = s.value("General/CustomColorScheme", this->CustomColorScheme).toMap(); + this->Language = s.value("General/Language", this->Language).toString(); this->EUID = ::geteuid(); this->IsSuperuser = (this->EUID == 0); @@ -171,6 +172,7 @@ void Configuration::Save() s.setValue("General/RefreshPaused", this->RefreshPaused); s.setValue("General/UseCustomColorScheme", this->UseCustomColorScheme); s.setValue("General/CustomColorScheme", this->CustomColorScheme); + s.setValue("General/Language", this->Language); // Processes s.setValue("Processes/ShowKernelTasks", this->ShowKernelTasks); diff --git a/src/configuration.h b/src/configuration.h index 85551a2..302ada1 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -52,6 +52,8 @@ class Configuration : public QObject bool RefreshPaused { false }; ///< True when periodic refresh is paused. bool UseCustomColorScheme { false }; QVariantMap CustomColorScheme; + //! UI language as chosen by the user: "" = follow system, "en", "zh_CN", ... + QString Language; bool IsSuperuser { false }; ///< True when effective UID is 0 (runtime-only). uid_t EUID { 0 }; ///< Effective user ID captured at startup (runtime-only). bool IOMetricsEnabled { false }; ///< True when any Processes I/O column is visible (runtime-only). diff --git a/src/i18n.cpp b/src/i18n.cpp new file mode 100644 index 0000000..ad35c6a --- /dev/null +++ b/src/i18n.cpp @@ -0,0 +1,197 @@ +/* + * Tux Manager - Linux system monitor + * Copyright (C) 2026 Petr Bena + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "i18n.h" +#include "configuration.h" +#include "logger.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace +{ + // Translators live for the whole application lifetime (until restart). + QTranslator *appTranslator() + { + static QTranslator *t = new QTranslator(); + return t; + } + + QTranslator *qtTranslator() + { + static QTranslator *t = new QTranslator(); + return t; + } + + // Directories that may contain our "_.qm" files. + // The resource path is always available because translations are embedded + // at build time (:/i18n/), the filesystem paths cover packaged installs + // and development builds. A custom directory can be supplied through the + // TUX_MANAGER_I18N_DIR environment variable. + QStringList translationSearchDirs() + { + QStringList dirs; + const QString overrideDir = qEnvironmentVariable("TUX_MANAGER_I18N_DIR"); + if (!overrideDir.isEmpty()) + dirs << overrideDir; + dirs << QCoreApplication::applicationDirPath() + QStringLiteral("/translations"); + dirs << QStringLiteral("/usr/share/tux-manager/translations"); + dirs << QCoreApplication::applicationDirPath() + QStringLiteral("/../share/tux-manager/translations"); + dirs << QStringLiteral(":/i18n"); + return dirs; + } + + bool isEnglishLanguage(const QString &code) + { + if (code.isEmpty()) + return true; + // "C" / "POSIX" mean the classic unlocalized environment. + const QString base = code.section('_', 0, 0).toLower(); + return base == QStringLiteral("en") + || base == QStringLiteral("c") + || base == QStringLiteral("posix"); + } + + // Try to load a catalog (e.g. "tux-manager" or "qtbase") for the given + // language. Exact match is preferred, then the language part only. + bool loadCatalog(QTranslator *translator, const QString &catalog, const QString &language) + { + QStringList candidates; + candidates << language; + const int underscore = language.indexOf(QLatin1Char('_')); + if (underscore > 0) + candidates << language.left(underscore); + + for (const QString &dir : translationSearchDirs()) + { + for (const QString &lang : candidates) + { + const QString fileName = catalog + QLatin1Char('_') + lang + QStringLiteral(".qm"); + const QString path = dir.endsWith(QLatin1Char('/')) ? dir + fileName : dir + QLatin1Char('/') + fileName; + if (!QFile::exists(path)) + continue; + if (translator->load(fileName, dir)) + { + LOG_DEBUG(QString("I18n: loaded %1 from %2").arg(fileName, dir)); + return true; + } + } + } + return false; + } + + QString resolveLanguageCode() + { + QString code = CFG->Language.trimmed(); + if (code.isEmpty()) + code = QLocale::system().name(); + return code; + } +} + +QStringList I18n::availableLanguageCodes() +{ + // "" = follow system language; these are the shipped languages. + return { QString(), QStringLiteral("en"), QStringLiteral("zh_CN") }; +} + +QString I18n::configuredLanguage() +{ + return CFG->Language; +} + +QString I18n::installTranslators() +{ + QString code = resolveLanguageCode(); + + // Always drop any previously installed translator first so a restart or + // repeated call can never stack two translations. + if (appTranslator()->isEmpty() == false) + QCoreApplication::removeTranslator(appTranslator()); + if (qtTranslator()->isEmpty() == false) + QCoreApplication::removeTranslator(qtTranslator()); + + if (isEnglishLanguage(code)) + { + LOG_DEBUG("I18n: no translation needed, using built-in English UI"); + return QStringLiteral("en"); + } + + const QString matched = loadCatalog(appTranslator(), QStringLiteral("tux-manager"), code) ? code : QString(); + if (matched.isEmpty()) + { + // No translation file for this language, fall back to English UI. + LOG_INFO(QString("I18n: no translation available for '%1', falling back to English").arg(code)); + return QStringLiteral("en"); + } + + // Best effort: also localize Qt built-in dialogs (QMessageBox buttons etc.) + // using the matching qtbase catalog from the Qt installation. + const QString qtTranslationsDir = QLibraryInfo::path(QLibraryInfo::TranslationsPath); + if (QFile::exists(qtTranslationsDir)) + { + QStringList candidates; + candidates << matched; + const int underscore = matched.indexOf(QLatin1Char('_')); + if (underscore > 0) + candidates << matched.left(underscore); + + for (const QString &lang : candidates) + { + const QString fileName = QStringLiteral("qtbase_") + lang + QStringLiteral(".qm"); + const QString path = qtTranslationsDir.endsWith(QLatin1Char('/')) ? qtTranslationsDir + fileName + : qtTranslationsDir + QLatin1Char('/') + fileName; + if (QFile::exists(path)) + { + if (qtTranslator()->load(fileName, qtTranslationsDir)) + { + QCoreApplication::installTranslator(qtTranslator()); + LOG_DEBUG(QString("I18n: loaded Qt base translation %1").arg(fileName)); + } + break; + } + } + } + + QCoreApplication::installTranslator(appTranslator()); + LOG_INFO(QString("I18n: using language '%1'").arg(matched)); + return matched; +} + +void I18n::restartApplication() +{ + const QString appPath = QCoreApplication::applicationFilePath(); + const QStringList args = QCoreApplication::arguments().mid(1); + LOG_INFO(QString("I18n: restarting %1 to apply language change").arg(appPath)); + if (QProcess::startDetached(appPath, args)) + { + // Give the new instance a moment to start before we tear down. + QTimer::singleShot(200, qApp, &QCoreApplication::quit); + } + else + { + LOG_ERROR(QString("I18n: failed to restart %1, please start it manually").arg(appPath)); + } +} + diff --git a/src/i18n.h b/src/i18n.h new file mode 100644 index 0000000..7c1d76b --- /dev/null +++ b/src/i18n.h @@ -0,0 +1,48 @@ +/* + * Tux Manager - Linux system monitor + * Copyright (C) 2026 Petr Bena + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef I18N_H +#define I18N_H + +#include +#include + +//! Application localization helpers (Qt Linguist / QTranslator). +namespace I18n +{ + /// Language codes available in the UI language selector. An empty code + /// means "follow the system language". Entries are ordered as they + /// should appear in the menu. + QStringList availableLanguageCodes(); + + /// Language preference currently stored in the configuration + /// (may be empty, meaning "follow system language"). + QString configuredLanguage(); + + /// Install application and Qt translators for the configured language + /// (or for the system language when the preference is empty). + /// Must be called after QApplication and CFG->Load() exist. + /// Returns the language code that was actually applied, e.g. "en" or + /// "zh_CN" ("" when no translation file was found). + QString installTranslators(); + + /// Restart the running application so a language change fully applies. + void restartApplication(); +} + +#endif // I18N_H diff --git a/src/main.cpp b/src/main.cpp index 0e934e6..458a705 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ #include "mainwindow.h" #include "configuration.h" +#include "i18n.h" #include "logger.h" #include "globals.h" @@ -103,6 +104,11 @@ int main(int argc, char *argv[]) // ── Bootstrap ───────────────────────────────────────────────────────────── CFG->Load(); CFG->ForceGpuDrm = parser.isSet(forceDrmOption); + + // Install translations for the configured (or system) language before any + // widget is created, so all tr() calls already resolve to the right text. + I18n::installTranslators(); + LOG_INFO(QString("%1 %2 starting (verbosity=%3)").arg(a.applicationName(), a.applicationVersion()).arg(verbosity)); MainWindow w; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 23bc0c9..83fc20a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -19,6 +19,13 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "configuration.h" +#include "i18n.h" + +#include +#include +#include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -33,7 +40,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) if (CFG->IsSuperuser) { // Make user aware of this - this->setWindowTitle(this->windowTitle() + " (superuser)"); + this->setWindowTitle(this->windowTitle() + tr(" (superuser)")); } this->ui->processesLayout->addWidget(this->m_processesWidget); @@ -41,6 +48,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) this->ui->usersLayout->addWidget(this->m_usersWidget); this->ui->servicesLayout->addWidget(this->m_servicesWidget); + this->buildMenus(); + // Restore previous window layout if (!CFG->WindowGeometry.isEmpty()) this->restoreGeometry(CFG->WindowGeometry); @@ -85,3 +94,52 @@ void MainWindow::updateTabActivity(int index) this->m_usersWidget->SetActive(index == 2); this->m_servicesWidget->SetActive(index == 3); } + +void MainWindow::buildMenus() +{ + // Options → Language selector. Language changes are applied by restarting + // the application so every widget, model and dialog is consistently rebuilt. + QMenu *optionsMenu = this->ui->menubar->addMenu(tr("Options")); + QMenu *languageMenu = optionsMenu->addMenu(tr("Language")); + languageMenu->setToolTipsVisible(true); + + auto *group = new QActionGroup(languageMenu); + group->setExclusive(true); + + const QString current = CFG->Language; + const auto addLanguageAction = [this, languageMenu, group, current](const QString &code, const QString &label) + { + QAction *action = languageMenu->addAction(label); + action->setCheckable(true); + action->setData(code); + action->setChecked(code == current); + group->addAction(action); + }; + + addLanguageAction(QString(), tr("System default")); + addLanguageAction(QStringLiteral("en"), tr("English")); + addLanguageAction(QStringLiteral("zh_CN"), tr("Chinese (Simplified)")); + + connect(group, &QActionGroup::triggered, this, [this, group](QAction *action) + { + const QString newCode = action->data().toString(); + if (newCode == CFG->Language) + return; + + const QString newName = action->text(); + const QString question = tr("Switch the interface language to \"%1\"?\n\nThe application needs to restart for the change to take effect.").arg(newName); + const auto answer = QMessageBox::question(this, tr("Language"), question, + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (answer != QMessageBox::Yes) + { + // Keep the previously active entry selected. + for (QAction *other : group->actions()) + other->setChecked(other->data().toString() == CFG->Language); + return; + } + + CFG->Language = newCode; + CFG->Save(); + I18n::restartApplication(); + }); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index a130a6d..7400edf 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -47,6 +47,7 @@ class MainWindow : public QMainWindow private: void updateTabActivity(int index); + void buildMenus(); Ui::MainWindow *ui; diff --git a/src/os/process.cpp b/src/os/process.cpp index 5c11dd3..1ee0f1e 100644 --- a/src/os/process.cpp +++ b/src/os/process.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -61,14 +62,14 @@ QString Process::GetStateString(char state) { switch (state) { - case 'R': return "Running"; - case 'S': return "Sleeping"; - case 'D': return "Disk sleep"; - case 'Z': return "Zombie"; - case 'T': return "Stopped"; - case 't': return "Tracing stop"; - case 'I': return "Idle"; - case 'X': return "Dead"; + case 'R': return QObject::tr("Running"); + case 'S': return QObject::tr("Sleeping"); + case 'D': return QObject::tr("Disk sleep"); + case 'Z': return QObject::tr("Zombie"); + case 'T': return QObject::tr("Stopped"); + case 't': return QObject::tr("Tracing stop"); + case 'I': return QObject::tr("Idle"); + case 'X': return QObject::tr("Dead"); default: return QString(state); } } diff --git a/src/os/processmodel.cpp b/src/os/processmodel.cpp index b2f2b96..174f073 100644 --- a/src/os/processmodel.cpp +++ b/src/os/processmodel.cpp @@ -414,24 +414,24 @@ QString ProcessModel::columnHeader(Column col) { switch (col) { - case ColPid: return "PID"; - case ColName: return "Name"; - case ColUser: return "User"; - case ColState: return "State"; - case ColCpu: return "CPU %"; - case ColMemRss: return "MEM RES"; - case ColMemVirt: return "MEM VIRT"; - case ColMemShared:return "MEM SHR"; - case ColMemText: return "MEM TEXT"; - case ColMemData: return "MEM DATA"; - case ColIoReads: return "IO Reads"; - case ColIoWrites: return "IO Writes"; - case ColIoReadsPerSec: return "IO Read/s"; - case ColIoWritesPerSec:return "IO Write/s"; - case ColThreads: return "Threads"; - case ColPriority: return "Priority"; - case ColNice: return "Nice"; - case ColCmdline: return "Command"; + case ColPid: return tr("PID"); + case ColName: return tr("Name"); + case ColUser: return tr("User"); + case ColState: return tr("State"); + case ColCpu: return tr("CPU %"); + case ColMemRss: return tr("MEM RES"); + case ColMemVirt: return tr("MEM VIRT"); + case ColMemShared:return tr("MEM SHR"); + case ColMemText: return tr("MEM TEXT"); + case ColMemData: return tr("MEM DATA"); + case ColIoReads: return tr("IO Reads"); + case ColIoWrites: return tr("IO Writes"); + case ColIoReadsPerSec: return tr("IO Read/s"); + case ColIoWritesPerSec:return tr("IO Write/s"); + case ColThreads: return tr("Threads"); + case ColPriority: return tr("Priority"); + case ColNice: return tr("Nice"); + case ColCmdline: return tr("Command"); default: return {}; } } diff --git a/src/os/processtreemodel.cpp b/src/os/processtreemodel.cpp index 39c7691..be08875 100644 --- a/src/os/processtreemodel.cpp +++ b/src/os/processtreemodel.cpp @@ -238,24 +238,24 @@ QString ProcessTreeModel::columnHeader(Column col) { switch (col) { - case ColPid: return "PID"; - case ColName: return "Name"; - case ColUser: return "User"; - case ColState: return "State"; - case ColCpu: return "CPU %"; - case ColMemRss: return "MEM RES"; - case ColMemVirt: return "MEM VIRT"; - case ColMemShared:return "MEM SHR"; - case ColMemText: return "MEM TEXT"; - case ColMemData: return "MEM DATA"; - case ColIoReads: return "IO Reads"; - case ColIoWrites: return "IO Writes"; - case ColIoReadsPerSec: return "IO Read/s"; - case ColIoWritesPerSec:return "IO Write/s"; - case ColThreads: return "Threads"; - case ColPriority: return "Priority"; - case ColNice: return "Nice"; - case ColCmdline: return "Command"; + case ColPid: return tr("PID"); + case ColName: return tr("Name"); + case ColUser: return tr("User"); + case ColState: return tr("State"); + case ColCpu: return tr("CPU %"); + case ColMemRss: return tr("MEM RES"); + case ColMemVirt: return tr("MEM VIRT"); + case ColMemShared:return tr("MEM SHR"); + case ColMemText: return tr("MEM TEXT"); + case ColMemData: return tr("MEM DATA"); + case ColIoReads: return tr("IO Reads"); + case ColIoWrites: return tr("IO Writes"); + case ColIoReadsPerSec: return tr("IO Read/s"); + case ColIoWritesPerSec:return tr("IO Write/s"); + case ColThreads: return tr("Threads"); + case ColPriority: return tr("Priority"); + case ColNice: return tr("Nice"); + case ColCmdline: return tr("Command"); default: return {}; } } diff --git a/src/translations/tux-manager_zh_CN.ts b/src/translations/tux-manager_zh_CN.ts new file mode 100644 index 0000000..a5f69b5 --- /dev/null +++ b/src/translations/tux-manager_zh_CN.ts @@ -0,0 +1,2244 @@ + + + + AboutDialog + + + About TuxManager + 关于 TuxManager + + + + Close + 关闭 + + + + Tux Manager + Tux Manager + + + + Version + 版本 + + + + <html><head/><body><p>Created by Petr Bena and <a href="https://github.com/benapetr/TuxManager/graphs/contributors"><span style=" text-decoration: underline; color:#8ab4f8;">many other contributors</span></a></p></body></html> + <html><head/><body><p>由 Petr Bena 及 <a href="https://github.com/benapetr/TuxManager/graphs/contributors"><span style=" text-decoration: underline; color:#8ab4f8;">众多其他贡献者</span></a>创建</p></body></html> + + + + A Linux Task Manager alternative built with Qt6, inspired by the Windows Task Manager but designed to go further - providing deep visibility into system processes, performance metrics, users, and services.<br><br><a href="https://github.com/benapetr/TuxManager">https://github.com/benapetr/TuxManager</a><br><br>License - GPL-3.0-or-later + 一款使用 Qt6 构建的 Linux 任务管理器替代品,灵感来自 Windows 任务管理器,但致力于更进一步——深度洞察系统进程、性能指标、用户和服务。<br><br><a href="https://github.com/benapetr/TuxManager">https://github.com/benapetr/TuxManager</a><br><br>许可证 - GPL-3.0-or-later + + + + Version %1 + 版本 %1 + + + + ColorSchemeDialog + + + Customize Colors + 自定义颜色 + + + + Use custom colors + 使用自定义颜色 + + + + When disabled, the default light or dark palette is used automatically. + 禁用后,将自动使用默认的浅色或深色调色板。 + + + + Choose + 选择 + + + + Reset + 重置 + + + + CpuDetailWidget + + + CPU + CPU + + + + font-size: 18pt; font-weight: bold; + font-size: 18pt; font-weight: bold; + + + + + + font-size: 8pt; + font-size: 8pt; + + + + + 0% + 0% + + + + font-size: 18pt; + font-size: 18pt; + + + + 60 seconds + 60 秒 + + + + 0 + 0 + + + + Utilization + 利用率 + + + + Speed + 速度 + + + + + + + + + + — + — + + + + Processes + 进程数 + + + + Threads + 线程 + + + + Uptime + 运行时间 + + + + Logical processors + 逻辑处理器 + + + + Virtual machine + 虚拟机 + + + + Temperature + 温度 + + + + DiskDetailWidget + + + Disk + 磁盘 + + + + font-size: 18pt; font-weight: bold; + font-size: 18pt; font-weight: bold; + + + + font-size: 12pt; + font-size: 12pt; + + + + + Active time + 活动时间 + + + + + + + + + + + font-size: 8pt; + font-size: 8pt; + + + + 100% + 100% + + + + + 60 seconds + 60 秒 + + + + + 0 + 0 + + + + Disk transfer rate + 磁盘传输速率 + + + + + + 0 KB/s + 0 KB/s + + + + 0% + 0% + + + + Capacity + 容量 + + + + + + + + + — + — + + + + Read speed + 读取速度 + + + + Formatted + 已格式化 + + + + Write speed + 写入速度 + + + + System disk + 系统磁盘 + + + + Device + 设备 + + + + Page file + 页面文件 + + + + Type + 类型 + + + + GpuDetailWidget + + + font-size: 18pt; font-weight: bold; + font-size: 18pt; font-weight: bold; + + + + GPU + GPU + + + + font-size: 11pt; + font-size: 11pt; + + + + Dedicated GPU memory usage + 专用 GPU 显存使用量 + + + + + 0 GB + 0 GB + + + + + + 60 seconds + 60 秒 + + + + + + 0 + 0 + + + + Shared GPU memory usage + 共享 GPU 显存使用量 + + + + Copy bandwidth + 复制带宽 + + + + Light: TX Dark: RX + 浅色:TX 深色:RX + + + + 0 KB/s + 0 KB/s + + + + Utilization + 利用率 + + + + 0% + 0% + + + + Dedicated GPU memory + 专用 GPU 显存 + + + + + + 0 / 0 GB + 0 / 0 GB + + + + GPU Memory + GPU 显存 + + + + Shared GPU memory + 共享 GPU 显存 + + + + Temperature + 温度 + + + + + + + + — + — + + + + Driver version + 驱动程序版本 + + + + Backend + 后端 + + + + Core clock + 核心频率 + + + + Power usage + 功耗 + + + + MainWindow + + + Tux Manager + Tux Manager + + + + Processes + 进程 + + + + Performance + 性能 + + + + Users + 用户 + + + + Services + 服务 + + + + (superuser) + (超级用户) + + + + Options + 选项 + + + + + Language + 语言 + + + + System default + 系统默认 + + + + English + 英语 + + + + Chinese (Simplified) + 简体中文 + + + + Switch the interface language to "%1"? + +The application needs to restart for the change to take effect. + 确定将界面语言切换为“%1”吗? + +需要重启应用程序才能生效。 + + + + MemoryDetailWidget + + + font-size: 18pt; font-weight: bold; + font-size: 18pt; font-weight: bold; + + + + Memory + 内存 + + + + font-size: 18pt; + font-size: 18pt; + + + + — GB + — GB + + + + + + + + + + + + + + + + font-size: 8pt; + font-size: 8pt; + + + + 60 seconds + 60 秒 + + + + 0 + 0 + + + + Memory composition + 内存构成 + + + + + + + + ■ + ■ + + + + + In use + 使用中 + + + + + Compressed + 已压缩 + + + + + Dirty + 脏页 + + + + Free (Cached) + 空闲(已缓存) + + + + + Free + 空闲 + + + + + + + + + + + + — + — + + + + Available + 可用 + + + + Cached + 已缓存 + + + + Buffers + 缓冲区 + + + + DIMM slots used + 已用 DIMM 插槽 + + + + Speed + 速度 + + + + NetworkDetailWidget + + + font-size: 18pt; font-weight: bold; + font-size: 18pt; font-weight: bold; + + + + Ethernet + 以太网 + + + + + + + font-size: 8pt; + font-size: 8pt; + + + + Throughput + 吞吐量 + + + + + + 0 KB/s + 0 KB/s + + + + 60 seconds + 60 秒 + + + + 0 + 0 + + + + Send + 发送 + + + + Adapter + 适配器 + + + + + + + + — + — + + + + Receive + 接收 + + + + Connection type + 连接类型 + + + + Link speed + 链接速度 + + + + IPv4 address + IPv4 地址 + + + + IPv6 addresses + IPv6 地址 + + + + OS::ProcessModel + + + + measuring... + 正在测量… + + + + PID + PID + + + + Name + 名称 + + + + User + 用户 + + + + State + 状态 + + + + CPU % + CPU % + + + + MEM RES + 常驻内存 + + + + MEM VIRT + 虚拟内存 + + + + MEM SHR + 共享内存 + + + + MEM TEXT + 代码内存 + + + + MEM DATA + 数据内存 + + + + IO Reads + I/O 读取 + + + + IO Writes + I/O 写入 + + + + IO Read/s + I/O 读取/秒 + + + + IO Write/s + I/O 写入/秒 + + + + Threads + 线程 + + + + Priority + 优先级 + + + + Nice + Nice + + + + Command + 命令行 + + + + OS::ProcessTreeModel + + + + measuring... + 正在测量… + + + + PID + PID + + + + Name + 名称 + + + + User + 用户 + + + + State + 状态 + + + + CPU % + CPU % + + + + MEM RES + 常驻内存 + + + + MEM VIRT + 虚拟内存 + + + + MEM SHR + 共享内存 + + + + MEM TEXT + 代码内存 + + + + MEM DATA + 数据内存 + + + + IO Reads + I/O 读取 + + + + IO Writes + I/O 写入 + + + + IO Read/s + I/O 读取/秒 + + + + IO Write/s + I/O 写入/秒 + + + + Threads + 线程 + + + + Priority + 优先级 + + + + Nice + Nice + + + + Command + 命令行 + + + + OS::ServiceModel + + + Service + 服务 + + + + Load + 加载 + + + + Active + 活动 + + + + SubState + 子状态 + + + + Description + 描述 + + + + Perf::CpuDetailWidget + + + %1 GHz + %1 GHz + + + + + — + — + + + + %1 C + %1 C + + + + %1d %2:%3:%4 + %1天 %2:%3:%4 + + + + %1:%2:%3 + %1:%2:%3 + + + + Yes + 是 + + + + Yes (%1) + 是 (%1) + + + + No + 否 + + + + CPU graph options + CPU 图形选项 + + + + Change graph to + 切换图形为 + + + + Overall utilization + 总体利用率 + + + + Logical processors + 逻辑处理器 + + + + Show kernel times + 显示内核时间 + + + + Perf::CpuGraphArea + + + CPU + CPU + + + + + Kernel + 内核 + + + + %1 GHz + %1 GHz + + + + + CPU %1 + CPU %1 + + + + Perf::DiskDetailWidget + + + Active time + 活动时间 + + + + Read + 读取 + + + + Write + 写入 + + + + 100% + 100% + + + + Disk (%1) + 磁盘 (%1) + + + + - + - + + + + + Yes + 是 + + + + + No + 否 + + + + Perf::GpuDetailWidget + + + Dedicated memory usage + 专用显存使用量 + + + + Shared memory usage + 共享显存使用量 + + + + TX + TX + + + + RX + RX + + + + Copy bandwidth: light trace = TX, dark trace = RX + 复制带宽:浅色轨迹 = TX,深色轨迹 = RX + + + + %1 C + %1 C + + + + — + — + + + + + + %1 / %2 + %1 / %2 + + + + %1 MHz + %1 MHz + + + + %1 W + %1 W + + + + + GB + GB + + + + GPU %1 + GPU %1 + + + + Value + 数值 + + + + Perf::GraphWidget + + + + %1: %2 + %1:%2 + + + + +%1 s ago + +%1 秒前 + + + + + % + % + + + + %1 (%2 %3) + %1=percent text %2=absolute value %3=absolute unit + %1 (%2 %3) + + + + Value + 数值 + + + + Secondary + 次要 + + + + Perf::MemoryBar + + + Used + 已用 + + + + Used (compressed) + 已用(压缩) + + + + Dirty + 脏页 + + + + Free (cached) + 空闲(缓存) + + + + Free + 空闲 + + + + %1: %2 (%3%) + %1: %2 (%3%) + + + + Perf::MemoryDetailWidget + + + Used memory + 已用内存 + + + + GB + GB + + + + %1 / %2 + %1 / %2 + + + + + + — + — + + + + %1 MT/s + %1 MT/s + + + + %1 (using %2 RAM) + %1(使用 %2 内存) + + + + Perf::NetworkDetailWidget + + + Receive + 接收 + + + + Send + 发送 + + + + NIC (%1) + 网卡 (%1) + + + + Mbps + Mbps + + + + Unknown + 未知 + + + + + — + — + + + + Network graph options + 网络图形选项 + + + + Show speeds in bits + 以比特显示速度 + + + + Show speeds in bytes + 以字节显示速度 + + + + Perf::SwapDetailWidget + + + Swap in + 换入 + + + + Swap out + 换出 + + + + Swap in: disk -> RAM (pages read back into memory) +Swap out: RAM -> disk (pages written to swap storage) + 换入:磁盘 -> 内存(将页面读回内存) +换出:内存 -> 磁盘(将页面写入交换存储) + + + + Swap graph options + 交换图形选项 + + + + Change graph to + 切换图形为 + + + + Overall usage + 总体使用量 + + + + Swap devices + 交换设备 + + + + Perf::SwapGraphArea + + + Swap usage + 交换空间使用量 + + + + + + GB + GB + + + + PerformanceWidget + + + CPU + CPU + + + + Memory + 内存 + + + + Swap + 交换空间 + + + + Disk (%1) + 磁盘 (%1) + + + + GPU %1 + GPU %1 + + + + NIC (%1) + 网卡 (%1) + + + + %1%2 %3C + %1=value %2=percent sign %3=temperature in Celsius + %1%2 %3C + + + + Off + 关闭 + + + + %1 %2 + %1=disk type %2=active percentage + %1 %2 + + + + %1%2 + %1=GPU utilization value %2=percent sign + %1%2 + + + + %1 %2C + %1=GPU utilization %2=temperature in Celsius + %1 %2C + + + + U:%1 D:%2 + %1=upload rate %2=download rate + ↑%1 ↓%2 + + + + Settings + 设置 + + + + Customize order... + 自定义顺序… + + + + Customize colors... + 自定义颜色… + + + + Show grid in side panel + 在侧面板中显示网格 + + + + ProcessesWidget + + + Search: + 搜索: + + + + Filter processes… + 筛选进程… + + + + Run new task + 运行新任务 + + + + Open terminal + 打开终端 + + + + Tasks: 0 + 任务:0 + + + + Copy + 复制 + + + + Entire row + 整行 + + + + Selected cell + 所选单元格 + + + + PIDs + PID + + + + PID + PID + + + + + View + 视图 + + + + + Kernel tasks + 内核任务 + + + + + Processes of other users + 其他用户的进程 + + + + + Table view + 表格视图 + + + + + Tree view + 树形视图 + + + + Send signal + 发送信号 + + + + Custom signal... + 自定义信号… + + + + + Terminate (SIGTERM) + 终止 (SIGTERM) + + + + + Kill (SIGKILL) + 强制结束 (SIGKILL) + + + + + Change priority (renice)... + 更改优先级 (renice)… + + + + Tasks: %1 Threads: %2 + 任务:%1 线程:%2 + + + + Send custom signal + 发送自定义信号 + + + + Signal number: + 信号编号: + + + + + Open terminal failed + 打开终端失败 + + + + No supported terminal emulator was found on this system. + 系统上未找到受支持的终端模拟器。 + + + + Failed to start terminal: %1 + 启动终端失败:%1 + + + + You are about to send signal %1 to process PID %2. + +Do you want to continue? + 即将向进程 PID %2 发送信号 %1。 + +是否继续? + + + + You are about to send signal %1 to %2 selected processes. +This will affect all selected processes. + +PIDs: %3 + +Do you want to continue? + 即将向选中的 %2 个进程发送信号 %1。 +这将影响所有选中的进程。 + +PID:%3 + +是否继续? + + + + +Target owners: %1 + +目标所有者:%1 + + + + + +Warning: one or more selected processes are owned by another user. This application is running without superuser privileges, so this signal will most likely be rejected and nothing will happen. + + +警告:一个或多个选中的进程归其他用户所有。此应用程序未以超级用户权限运行,因此该信号很可能会被拒绝且不会生效。 + + + + Confirm Signal + 确认信号 + + + + Signal failed + 信号发送失败 + + + + Change priority + 更改优先级 + + + + Nice value (-20 = highest priority, 19 = lowest): + Nice 值(-20 = 最高优先级,19 = 最低): + + + + Renice failed + renice 失败 + + + + QObject + + + GB/s + GB/s + + + + MB/s + MB/s + + + + KB/s + KB/s + + + + B/s + B/s + + + + Gb/s + Gb/s + + + + Mb/s + Mb/s + + + + Kb/s + Kb/s + + + + b/s + b/s + + + + Running + 运行中 + + + + Sleeping + 睡眠中 + + + + Disk sleep + 磁盘睡眠 + + + + Zombie + 僵尸 + + + + Stopped + 已停止 + + + + Tracing stop + 跟踪停止 + + + + Idle + 空闲 + + + + Dead + 已结束 + + + + Unable to query services via sd-bus or systemctl + 无法通过 sd-bus 或 systemctl 查询服务 + + + + libsystemd not found + 未找到 libsystemd + + + + libsystemd missing sd-bus symbols + libsystemd 缺少 sd-bus 符号 + + + + + systemctl not found + 未找到 systemctl + + + + systemd runtime directory not present + systemd 运行时目录不存在 + + + + Failed to start systemctl + 启动 systemctl 失败 + + + + systemctl timed out + systemctl 超时 + + + + + sd-bus open system failed (%1) + sd-bus 打开系统总线失败 (%1) + + + + sd-bus ListUnits call failed (%1) + sd-bus ListUnits 调用失败 (%1) + + + + sd-bus decode failed (%1) + sd-bus 解码失败 (%1) + + + + sd-bus read row failed (%1/%2) + sd-bus 读取行失败 (%1/%2) + + + + sd-bus iteration failed (%1) + sd-bus 迭代失败 (%1) + + + + Invalid service action + 无效的服务操作 + + + + libsystemd missing interactive sd-bus symbols + libsystemd 缺少交互式 sd-bus 符号 + + + + systemd D-Bus call %1 for %2 failed (%3) + systemd D-Bus 调用 %1(针对 %2)失败 (%3) + + + + systemctl %1 %2 failed + systemctl %1 %2 失败 + + + + CPU + CPU + + + + Memory + 内存 + + + + Swap + 交换空间 + + + + Disks + 磁盘 + + + + NICs + 网卡 + + + + GPUs + GPU + + + + Network + 网络 + + + + Unknown device + 未知设备 + + + + Unknown + 未知 + + + + About TuxManager + 关于 TuxManager + + + + Copy + 复制 + + + + + Copy graph + 复制图形 + + + + Refresh interval + 刷新间隔 + + + + Paused + 已暂停 + + + + Graph time + 图形时间 + + + + %1 (%2) + %1(%2) + + + + %1 (pid %2) + %1(pid %2) + + + + RunTaskDialog + + + Run new task + 运行新任务 + + + + Open: + 打开: + + + + ... + ... + + + + Enter an executable name or path, with optional arguments + 输入可执行文件名称或路径,可附带参数 + + + + Run new task failed + 运行新任务失败 + + + + Failed to start command. + +%1 + 启动命令失败。 + +%1 + + + + Select executable + 选择可执行文件 + + + + All files (*) + 所有文件 (*) + + + + + Command is empty + 命令为空 + + + + Executable was not found: %1 + 找不到可执行文件:%1 + + + + Executable does not exist: %1 + 可执行文件不存在:%1 + + + + File is not executable: %1 + 文件不可执行:%1 + + + + Failed to start executable: %1 + 启动可执行文件失败:%1 + + + + ServicesWidget + + + Search: + 搜索: + + + + Filter services… + 筛选服务… + + + + systemd required + 需要 systemd + + + + Services: 0 + 服务:0 + + + + systemd required (%1) + 需要 systemd (%1) + + + + + Services unavailable + 服务不可用 + + + + Failed to query services: %1 + 查询服务失败:%1 + + + + Services: %1 + 服务:%1 + + + + Copy + 复制 + + + + Entire row + 整行 + + + + Selected cell + 所选单元格 + + + + Start + 启动 + + + + start + 启动 + + + + Stop + 停止 + + + + stop + 停止 + + + + Restart + 重启 + + + + restart + 重启 + + + + Reload + 重新加载 + + + + reload + 重新加载 + + + + Try Restart + 尝试重启 + + + + try restart + 尝试重启 + + + + Reload Or Restart + 重新加载或重启 + + + + reload or restart + 重新加载或重启 + + + + Service action failed + 服务操作失败 + + + + Failed to %1 service %2. + +%3 + 对服务 %2 执行“%1”操作失败。 + +%3 + + + + SidePanelOrderDialog + + + Side Panel Order + 侧面板顺序 + + + + Change the order of item groups in the Performance side panel. + 更改“性能”侧面板中项目组的排列顺序。 + + + + Move Up + 上移 + + + + Move Down + 下移 + + + + SwapDetailWidget + + + font-size: 18pt; font-weight: bold; + font-size: 18pt; font-weight: bold; + + + + Swap + 交换空间 + + + + font-size: 11pt; + font-size: 11pt; + + + + + + 0 GB + 0 GB + + + + Swap usage + 交换空间使用量 + + + + 0% + 0% + + + + + 60 seconds + 60 秒 + + + + + 0 + 0 + + + + Swap activity + 交换活动 + + + + + + 0 KB/s + 0 KB/s + + + + In use + 使用中 + + + + Free + 空闲 + + + + + Swap in direction: disk -> RAM + 换入方向:磁盘 -> 内存 + + + + Swap in + 换入 + + + + + Swap out direction: RAM -> disk + 换出方向:内存 -> 磁盘 + + + + Swap out + 换出 + + + + UsersWidget + + + + User / Process + 用户 / 进程 + + + + + CPU + CPU + + + + + Memory + 内存 + + + + Logged in users: 0 + 已登录用户:0 + + + + Go to process + 转到进程 + + + + Logged in users: %1 + 已登录用户:%1 + + + \ No newline at end of file From 47b630b2386dbc6e077552724e8ef9b0a0167a2c Mon Sep 17 00:00:00 2001 From: Petr Bena Date: Wed, 9 Sep 2026 21:10:25 +0200 Subject: [PATCH 2/4] fixed CI and packaging --- .github/workflows/build-arch-aur.yml | 3 +- .github/workflows/build-debian-qt6.yml | 1 + debian/control | 3 +- flake.nix | 2 +- packaging/README.md | 14 +++---- packaging/package-appimage.sh | 10 +++++ packaging/package-arch.sh | 4 +- packaging/package-deb.sh | 57 +++++++++++--------------- packaging/package-rpm.sh | 4 ++ src/i18n.cpp | 6 ++- 10 files changed, 59 insertions(+), 45 deletions(-) diff --git a/.github/workflows/build-arch-aur.yml b/.github/workflows/build-arch-aur.yml index b9af209..fe6351b 100644 --- a/.github/workflows/build-arch-aur.yml +++ b/.github/workflows/build-arch-aur.yml @@ -27,7 +27,8 @@ jobs: run: | pacman -Syu --noconfirm --needed \ git \ - qt6-base + qt6-base \ + qt6-tools - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/build-debian-qt6.yml b/.github/workflows/build-debian-qt6.yml index 1b5c078..bf2341b 100644 --- a/.github/workflows/build-debian-qt6.yml +++ b/.github/workflows/build-debian-qt6.yml @@ -33,6 +33,7 @@ jobs: qmake6 \ qt6-base-dev \ qt6-base-dev-tools \ + qt6-l10n-tools \ libgl1-mesa-dev - name: Checkout diff --git a/debian/control b/debian/control index 6453512..147c85f 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: Petr Bena Build-Depends: debhelper-compat (= 12), pkg-config, - qtbase5-dev | qt6-base-dev, + qt6-base-dev | qtbase5-dev, qt6-l10n-tools | qttools5-dev-tools Standards-Version: 4.6.2 Rules-Requires-Root: no @@ -12,6 +12,7 @@ Rules-Requires-Root: no Package: tux-manager Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} +Recommends: qt6-translations-l10n | qttranslations5-l10n Description: Tux Manager - Linux system monitor inspired by Windows Task Manager Tux Manager is a C++/Qt system monitor with tabs for processes, performance, users and services. diff --git a/flake.nix b/flake.nix index 3acc650..2480e97 100644 --- a/flake.nix +++ b/flake.nix @@ -25,7 +25,7 @@ version = "1.0.7"; src = ./.; - nativeBuildInputs = with pkgs.kdePackages; [ qmake wrapQtAppsHook ]; + nativeBuildInputs = with pkgs.kdePackages; [ qmake qttools wrapQtAppsHook ]; buildInputs = with pkgs.kdePackages; [ qtbase ]; configurePhase = "qmake6 $src/src"; diff --git a/packaging/README.md b/packaging/README.md index 590c970..3de5f3a 100644 --- a/packaging/README.md +++ b/packaging/README.md @@ -20,23 +20,23 @@ This directory contains Linux packaging scripts for Tux Manager. Required build tools/packages: ```bash -sudo apt-get install build-essential debhelper dpkg-dev pkg-config qt6-base-dev +sudo apt-get install build-essential debhelper dpkg-dev pkg-config qt6-base-dev qt6-l10n-tools ``` Notes: -- The script accepts either `qmake6` or `qmake`. -- Qt5 can also work if your distro provides it (`qtbase5-dev`). +- On distributions without Qt6, install `qtbase5-dev qttools5-dev-tools` instead. +- The script prefers `qmake6` when both Qt versions are installed. ### Fedora/RHEL family Required build tools/packages: ```bash -sudo dnf install rpm-build rsync git pkgconf-pkg-config qt6-qtbase-devel +sudo dnf install rpm-build rsync git pkgconf-pkg-config qt6-qtbase-devel qt6-linguist ``` Notes: -- The script can also build with Qt5 if only that is available (`qt5-qtbase-devel`). +- The script can also build with Qt5 if `qt5-qtbase-devel` and `qt5-linguist` are installed. - The script uses `rpmbuild` and creates both binary RPM and source RPM. ### Flatpak @@ -66,7 +66,7 @@ Required tools/packages: Download released appimages from all 3, put them into some directory and create symlinks with bare names, then add this folder to PATH variable ```bash -sudo apt-get install build-essential pkg-config qt6-base-dev +sudo apt-get install build-essential pkg-config qt6-base-dev qt6-l10n-tools linuxdeploy --version linuxdeploy-plugin-qt --help linuxdeploy-plugin-appimage --help @@ -82,7 +82,7 @@ Notes: Required build tools/packages: ```bash -sudo pacman -S --needed base-devel git qt6-base +sudo pacman -S --needed base-devel git qt6-base qt6-tools ``` Notes: diff --git a/packaging/package-appimage.sh b/packaging/package-appimage.sh index cdb31c7..5877815 100755 --- a/packaging/package-appimage.sh +++ b/packaging/package-appimage.sh @@ -69,6 +69,16 @@ else fi fi +QT_TOOLS_BIN="$("$QMAKE_CMD" -query QT_HOST_BINS 2>/dev/null || true)" +if [ ! -x "$QT_TOOLS_BIN/lrelease" ]; then + QT_TOOLS_BIN="$("$QMAKE_CMD" -query QT_INSTALL_BINS 2>/dev/null || true)" +fi +if [ ! -x "$QT_TOOLS_BIN/lrelease" ]; then + echo "Error: Qt Linguist lrelease not found for $QMAKE_CMD." + echo "Install the matching Qt Linguist tools package or include it in --qt." + exit 1 +fi + if ! command -v linuxdeploy >/dev/null 2>&1; then echo "Error: linuxdeploy not found in PATH." echo "Install linuxdeploy and re-run." diff --git a/packaging/package-arch.sh b/packaging/package-arch.sh index 1d82c23..0517217 100755 --- a/packaging/package-arch.sh +++ b/packaging/package-arch.sh @@ -44,7 +44,7 @@ if [[ ${EUID:-$(id -u)} -eq 0 ]]; then exit 1 fi -for cmd in makepkg qmake6 tar b2sum; do +for cmd in makepkg qmake6 lrelease6 tar b2sum; do if ! command -v "$cmd" >/dev/null 2>&1; then echo "Error: required command not found: $cmd" exit 1 @@ -87,7 +87,7 @@ arch=('x86_64') url="${APP_HOMEPAGE_URL}" license=('GPL-3.0-or-later') depends=('qt6-base') -makedepends=('qt6-base') +makedepends=('qt6-base' 'qt6-tools') options=('!debug') source=("${APP_NAME}-${APP_VERSION}.tar.gz::file://${SOURCE_TARBALL}") b2sums=('${LOCAL_CHECKSUM}') diff --git a/packaging/package-deb.sh b/packaging/package-deb.sh index 56a8ef9..ab6e2d9 100755 --- a/packaging/package-deb.sh +++ b/packaging/package-deb.sh @@ -46,9 +46,10 @@ echo "Version: $APP_VERSION" echo "" # Preflight: check build dependencies and print install command if missing +qt6_ready=false +qt5_ready=false if command -v dpkg-query >/dev/null 2>&1; then missing=() - missing_groups=() require_pkg() { local pkg="$1" @@ -57,28 +58,19 @@ if command -v dpkg-query >/dev/null 2>&1; then fi } - require_one_of() { - local group=("$@") - local found="" - local pkg - for pkg in "${group[@]}"; do - if dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -q "install ok installed"; then - found="yes" - break - fi - done - if [ -z "$found" ]; then - missing_groups+=("${group[*]}") - fi - } - require_pkg build-essential require_pkg debhelper require_pkg dpkg-dev require_pkg pkg-config - require_one_of qtbase5-dev qt6-base-dev - if [ ${#missing[@]} -gt 0 ] || [ ${#missing_groups[@]} -gt 0 ]; then + if dpkg-query -W -f='${Status}\n' qt6-base-dev qt6-l10n-tools 2>/dev/null | grep -c "install ok installed" | grep -q '^2$'; then + qt6_ready=true + fi + if dpkg-query -W -f='${Status}\n' qtbase5-dev qttools5-dev-tools 2>/dev/null | grep -c "install ok installed" | grep -q '^2$'; then + qt5_ready=true + fi + + if [ ${#missing[@]} -gt 0 ] || { [ "$qt6_ready" = false ] && [ "$qt5_ready" = false ]; }; then echo "Missing build dependencies detected." echo "" echo "Install the following packages (or equivalent) and re-run:" @@ -86,23 +78,18 @@ if command -v dpkg-query >/dev/null 2>&1; then if [ ${#missing[@]} -gt 0 ]; then echo " sudo apt-get install ${missing[*]}" fi - if [ ${#missing_groups[@]} -gt 0 ]; then - echo "" - echo "Choose one package from each group:" - for group in "${missing_groups[@]}"; do - for pkg in $group; do - echo " sudo apt-get install $pkg" - done - echo "" - done + if [ "$qt6_ready" = false ] && [ "$qt5_ready" = false ]; then + echo " sudo apt-get install qt6-base-dev qt6-l10n-tools" + echo " or: sudo apt-get install qtbase5-dev qttools5-dev-tools" fi else for pkg in "${missing[@]}"; do echo " - $pkg" done - for group in "${missing_groups[@]}"; do - echo " - one of: $group" - done + if [ "$qt6_ready" = false ] && [ "$qt5_ready" = false ]; then + echo " - Qt6: qt6-base-dev and qt6-l10n-tools" + echo " - Qt5: qtbase5-dev and qttools5-dev-tools" + fi fi echo "" exit 1 @@ -110,9 +97,15 @@ if command -v dpkg-query >/dev/null 2>&1; then fi -# Resolve qmake (prefer qmake6, fallback to qmake) +# Resolve qmake for a complete Qt base + Linguist toolchain. if [ -z "$QT_BIN_PATH" ]; then - if command -v qmake6 >/dev/null 2>&1; then + if [ "$qt6_ready" = true ] && command -v qmake6 >/dev/null 2>&1; then + QMAKE_CMD="qmake6" + elif [ "$qt5_ready" = true ] && command -v qmake-qt5 >/dev/null 2>&1; then + QMAKE_CMD="qmake-qt5" + elif [ "$qt5_ready" = true ] && command -v qmake >/dev/null 2>&1; then + QMAKE_CMD="qmake" + elif command -v qmake6 >/dev/null 2>&1; then QMAKE_CMD="qmake6" elif command -v qmake >/dev/null 2>&1; then QMAKE_CMD="qmake" diff --git a/packaging/package-rpm.sh b/packaging/package-rpm.sh index fc79ae8..a8c94cf 100755 --- a/packaging/package-rpm.sh +++ b/packaging/package-rpm.sh @@ -82,8 +82,10 @@ if command -v rpm >/dev/null 2>&1; then if [ "$QT_MAJOR" -eq 5 ]; then require_pkg qt5-qtbase-devel + require_pkg qt5-linguist else require_pkg qt6-qtbase-devel + require_pkg qt6-linguist fi if [ ${#missing[@]} -gt 0 ]; then @@ -186,8 +188,10 @@ Source0: %{name}-%{version}.tar.gz %if 0%{?qt_major} == 5 BuildRequires: qt5-qtbase-devel +BuildRequires: qt5-linguist %else BuildRequires: qt6-qtbase-devel +BuildRequires: qt6-linguist %endif BuildRequires: pkgconf-pkg-config diff --git a/src/i18n.cpp b/src/i18n.cpp index ad35c6a..e1a960e 100644 --- a/src/i18n.cpp +++ b/src/i18n.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace { @@ -148,7 +149,11 @@ QString I18n::installTranslators() // Best effort: also localize Qt built-in dialogs (QMessageBox buttons etc.) // using the matching qtbase catalog from the Qt installation. +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) const QString qtTranslationsDir = QLibraryInfo::path(QLibraryInfo::TranslationsPath); +#else + const QString qtTranslationsDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); +#endif if (QFile::exists(qtTranslationsDir)) { QStringList candidates; @@ -194,4 +199,3 @@ void I18n::restartApplication() LOG_ERROR(QString("I18n: failed to restart %1, please start it manually").arg(appPath)); } } - From 843fdb7c91fae5ab29c0ad823616c3be71fb67da Mon Sep 17 00:00:00 2001 From: Petr Bena Date: Wed, 9 Sep 2026 21:37:11 +0200 Subject: [PATCH 3/4] localization UI removal we don't need it, that extra menu is cluttering the simple UI layout and there is virtually no need for user to ever decide to pick a different language for a tool of this kind from the OS language that menu where you could explicitly set a language made sense only for debugging of localizations themselves and that can be overriden via env var --- README.md | 10 +++++ packaging/package-deb.sh | 58 +++++++++++++++------------ src/configuration.cpp | 2 - src/configuration.h | 2 - src/i18n.cpp | 49 +++------------------- src/i18n.h | 24 ++--------- src/main.cpp | 4 +- src/mainwindow.cpp | 58 --------------------------- src/mainwindow.h | 1 - src/translations/tux-manager_zh_CN.ts | 37 +---------------- src/ui/uihelper.cpp | 2 +- 11 files changed, 55 insertions(+), 192 deletions(-) diff --git a/README.md b/README.md index 52a4b36..9894862 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,16 @@ make -j$(nproc) ./tux-manager ``` +To test a different UI locale without changing the system settings, override +the process locale when launching the application: + +```bash +LC_ALL=zh_CN.UTF-8 ./tux-manager # Simplified Chinese +LC_ALL=C ./tux-manager # Built-in English +``` + +The requested locale may need to be generated or installed on the host system. + ## Core philosophy and goals of this project * KISS - keep it simple stupid diff --git a/packaging/package-deb.sh b/packaging/package-deb.sh index ab6e2d9..e2cea75 100755 --- a/packaging/package-deb.sh +++ b/packaging/package-deb.sh @@ -46,10 +46,9 @@ echo "Version: $APP_VERSION" echo "" # Preflight: check build dependencies and print install command if missing -qt6_ready=false -qt5_ready=false if command -v dpkg-query >/dev/null 2>&1; then missing=() + missing_groups=() require_pkg() { local pkg="$1" @@ -58,19 +57,29 @@ if command -v dpkg-query >/dev/null 2>&1; then fi } + require_one_of() { + local group=("$@") + local found="" + local pkg + for pkg in "${group[@]}"; do + if dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -q "install ok installed"; then + found="yes" + break + fi + done + if [ -z "$found" ]; then + missing_groups+=("${group[*]}") + fi + } + require_pkg build-essential require_pkg debhelper require_pkg dpkg-dev require_pkg pkg-config + require_one_of qt6-base-dev qtbase5-dev + require_one_of qt6-l10n-tools qttools5-dev-tools - if dpkg-query -W -f='${Status}\n' qt6-base-dev qt6-l10n-tools 2>/dev/null | grep -c "install ok installed" | grep -q '^2$'; then - qt6_ready=true - fi - if dpkg-query -W -f='${Status}\n' qtbase5-dev qttools5-dev-tools 2>/dev/null | grep -c "install ok installed" | grep -q '^2$'; then - qt5_ready=true - fi - - if [ ${#missing[@]} -gt 0 ] || { [ "$qt6_ready" = false ] && [ "$qt5_ready" = false ]; }; then + if [ ${#missing[@]} -gt 0 ] || [ ${#missing_groups[@]} -gt 0 ]; then echo "Missing build dependencies detected." echo "" echo "Install the following packages (or equivalent) and re-run:" @@ -78,18 +87,23 @@ if command -v dpkg-query >/dev/null 2>&1; then if [ ${#missing[@]} -gt 0 ]; then echo " sudo apt-get install ${missing[*]}" fi - if [ "$qt6_ready" = false ] && [ "$qt5_ready" = false ]; then - echo " sudo apt-get install qt6-base-dev qt6-l10n-tools" - echo " or: sudo apt-get install qtbase5-dev qttools5-dev-tools" + if [ ${#missing_groups[@]} -gt 0 ]; then + echo "" + echo "Choose one package from each group:" + for group in "${missing_groups[@]}"; do + for pkg in $group; do + echo " sudo apt-get install $pkg" + done + echo "" + done fi else for pkg in "${missing[@]}"; do echo " - $pkg" done - if [ "$qt6_ready" = false ] && [ "$qt5_ready" = false ]; then - echo " - Qt6: qt6-base-dev and qt6-l10n-tools" - echo " - Qt5: qtbase5-dev and qttools5-dev-tools" - fi + for group in "${missing_groups[@]}"; do + echo " - one of: $group" + done fi echo "" exit 1 @@ -97,15 +111,9 @@ if command -v dpkg-query >/dev/null 2>&1; then fi -# Resolve qmake for a complete Qt base + Linguist toolchain. +# Resolve qmake (prefer qmake6, fallback to qmake) if [ -z "$QT_BIN_PATH" ]; then - if [ "$qt6_ready" = true ] && command -v qmake6 >/dev/null 2>&1; then - QMAKE_CMD="qmake6" - elif [ "$qt5_ready" = true ] && command -v qmake-qt5 >/dev/null 2>&1; then - QMAKE_CMD="qmake-qt5" - elif [ "$qt5_ready" = true ] && command -v qmake >/dev/null 2>&1; then - QMAKE_CMD="qmake" - elif command -v qmake6 >/dev/null 2>&1; then + if command -v qmake6 >/dev/null 2>&1; then QMAKE_CMD="qmake6" elif command -v qmake >/dev/null 2>&1; then QMAKE_CMD="qmake" diff --git a/src/configuration.cpp b/src/configuration.cpp index 1338f31..34d16c3 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -82,7 +82,6 @@ void Configuration::Load() this->RefreshPaused = s.value("General/RefreshPaused", this->RefreshPaused).toBool(); this->UseCustomColorScheme = s.value("General/UseCustomColorScheme", this->UseCustomColorScheme).toBool(); this->CustomColorScheme = s.value("General/CustomColorScheme", this->CustomColorScheme).toMap(); - this->Language = s.value("General/Language", this->Language).toString(); this->EUID = ::geteuid(); this->IsSuperuser = (this->EUID == 0); @@ -172,7 +171,6 @@ void Configuration::Save() s.setValue("General/RefreshPaused", this->RefreshPaused); s.setValue("General/UseCustomColorScheme", this->UseCustomColorScheme); s.setValue("General/CustomColorScheme", this->CustomColorScheme); - s.setValue("General/Language", this->Language); // Processes s.setValue("Processes/ShowKernelTasks", this->ShowKernelTasks); diff --git a/src/configuration.h b/src/configuration.h index 302ada1..85551a2 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -52,8 +52,6 @@ class Configuration : public QObject bool RefreshPaused { false }; ///< True when periodic refresh is paused. bool UseCustomColorScheme { false }; QVariantMap CustomColorScheme; - //! UI language as chosen by the user: "" = follow system, "en", "zh_CN", ... - QString Language; bool IsSuperuser { false }; ///< True when effective UID is 0 (runtime-only). uid_t EUID { 0 }; ///< Effective user ID captured at startup (runtime-only). bool IOMetricsEnabled { false }; ///< True when any Processes I/O column is visible (runtime-only). diff --git a/src/i18n.cpp b/src/i18n.cpp index e1a960e..fd5da9c 100644 --- a/src/i18n.cpp +++ b/src/i18n.cpp @@ -17,22 +17,18 @@ */ #include "i18n.h" -#include "configuration.h" #include "logger.h" #include -#include #include #include #include -#include -#include #include #include namespace { - // Translators live for the whole application lifetime (until restart). + // Translators live for the whole application lifetime. QTranslator *appTranslator() { static QTranslator *t = new QTranslator(); @@ -102,29 +98,11 @@ namespace return false; } - QString resolveLanguageCode() - { - QString code = CFG->Language.trimmed(); - if (code.isEmpty()) - code = QLocale::system().name(); - return code; - } -} - -QStringList I18n::availableLanguageCodes() -{ - // "" = follow system language; these are the shipped languages. - return { QString(), QStringLiteral("en"), QStringLiteral("zh_CN") }; -} - -QString I18n::configuredLanguage() -{ - return CFG->Language; } -QString I18n::installTranslators() +void I18n::installTranslators() { - QString code = resolveLanguageCode(); + const QString code = QLocale::system().name(); // Always drop any previously installed translator first so a restart or // repeated call can never stack two translations. @@ -136,7 +114,7 @@ QString I18n::installTranslators() if (isEnglishLanguage(code)) { LOG_DEBUG("I18n: no translation needed, using built-in English UI"); - return QStringLiteral("en"); + return; } const QString matched = loadCatalog(appTranslator(), QStringLiteral("tux-manager"), code) ? code : QString(); @@ -144,7 +122,7 @@ QString I18n::installTranslators() { // No translation file for this language, fall back to English UI. LOG_INFO(QString("I18n: no translation available for '%1', falling back to English").arg(code)); - return QStringLiteral("en"); + return; } // Best effort: also localize Qt built-in dialogs (QMessageBox buttons etc.) @@ -181,21 +159,4 @@ QString I18n::installTranslators() QCoreApplication::installTranslator(appTranslator()); LOG_INFO(QString("I18n: using language '%1'").arg(matched)); - return matched; -} - -void I18n::restartApplication() -{ - const QString appPath = QCoreApplication::applicationFilePath(); - const QStringList args = QCoreApplication::arguments().mid(1); - LOG_INFO(QString("I18n: restarting %1 to apply language change").arg(appPath)); - if (QProcess::startDetached(appPath, args)) - { - // Give the new instance a moment to start before we tear down. - QTimer::singleShot(200, qApp, &QCoreApplication::quit); - } - else - { - LOG_ERROR(QString("I18n: failed to restart %1, please start it manually").arg(appPath)); - } } diff --git a/src/i18n.h b/src/i18n.h index 7c1d76b..02fc14e 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -19,30 +19,12 @@ #ifndef I18N_H #define I18N_H -#include -#include - //! Application localization helpers (Qt Linguist / QTranslator). namespace I18n { - /// Language codes available in the UI language selector. An empty code - /// means "follow the system language". Entries are ordered as they - /// should appear in the menu. - QStringList availableLanguageCodes(); - - /// Language preference currently stored in the configuration - /// (may be empty, meaning "follow system language"). - QString configuredLanguage(); - - /// Install application and Qt translators for the configured language - /// (or for the system language when the preference is empty). - /// Must be called after QApplication and CFG->Load() exist. - /// Returns the language code that was actually applied, e.g. "en" or - /// "zh_CN" ("" when no translation file was found). - QString installTranslators(); - - /// Restart the running application so a language change fully applies. - void restartApplication(); + /// Install application and Qt translators for the system language. + /// Must be called after QApplication exists and before widgets are created. + void installTranslators(); } #endif // I18N_H diff --git a/src/main.cpp b/src/main.cpp index 458a705..8d14a14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -105,8 +105,8 @@ int main(int argc, char *argv[]) CFG->Load(); CFG->ForceGpuDrm = parser.isSet(forceDrmOption); - // Install translations for the configured (or system) language before any - // widget is created, so all tr() calls already resolve to the right text. + // Install translations for the system language before any widget is + // created, so all tr() calls already resolve to the right text. I18n::installTranslators(); LOG_INFO(QString("%1 %2 starting (verbosity=%3)").arg(a.applicationName(), a.applicationVersion()).arg(verbosity)); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 83fc20a..f652ac7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -19,13 +19,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "configuration.h" -#include "i18n.h" - -#include -#include -#include -#include -#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -48,8 +41,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) this->ui->usersLayout->addWidget(this->m_usersWidget); this->ui->servicesLayout->addWidget(this->m_servicesWidget); - this->buildMenus(); - // Restore previous window layout if (!CFG->WindowGeometry.isEmpty()) this->restoreGeometry(CFG->WindowGeometry); @@ -94,52 +85,3 @@ void MainWindow::updateTabActivity(int index) this->m_usersWidget->SetActive(index == 2); this->m_servicesWidget->SetActive(index == 3); } - -void MainWindow::buildMenus() -{ - // Options → Language selector. Language changes are applied by restarting - // the application so every widget, model and dialog is consistently rebuilt. - QMenu *optionsMenu = this->ui->menubar->addMenu(tr("Options")); - QMenu *languageMenu = optionsMenu->addMenu(tr("Language")); - languageMenu->setToolTipsVisible(true); - - auto *group = new QActionGroup(languageMenu); - group->setExclusive(true); - - const QString current = CFG->Language; - const auto addLanguageAction = [this, languageMenu, group, current](const QString &code, const QString &label) - { - QAction *action = languageMenu->addAction(label); - action->setCheckable(true); - action->setData(code); - action->setChecked(code == current); - group->addAction(action); - }; - - addLanguageAction(QString(), tr("System default")); - addLanguageAction(QStringLiteral("en"), tr("English")); - addLanguageAction(QStringLiteral("zh_CN"), tr("Chinese (Simplified)")); - - connect(group, &QActionGroup::triggered, this, [this, group](QAction *action) - { - const QString newCode = action->data().toString(); - if (newCode == CFG->Language) - return; - - const QString newName = action->text(); - const QString question = tr("Switch the interface language to \"%1\"?\n\nThe application needs to restart for the change to take effect.").arg(newName); - const auto answer = QMessageBox::question(this, tr("Language"), question, - QMessageBox::Yes | QMessageBox::No, QMessageBox::No); - if (answer != QMessageBox::Yes) - { - // Keep the previously active entry selected. - for (QAction *other : group->actions()) - other->setChecked(other->data().toString() == CFG->Language); - return; - } - - CFG->Language = newCode; - CFG->Save(); - I18n::restartApplication(); - }); -} diff --git a/src/mainwindow.h b/src/mainwindow.h index 7400edf..a130a6d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -47,7 +47,6 @@ class MainWindow : public QMainWindow private: void updateTabActivity(int index); - void buildMenus(); Ui::MainWindow *ui; diff --git a/src/translations/tux-manager_zh_CN.ts b/src/translations/tux-manager_zh_CN.ts index a5f69b5..768577f 100644 --- a/src/translations/tux-manager_zh_CN.ts +++ b/src/translations/tux-manager_zh_CN.ts @@ -439,41 +439,6 @@ (superuser) (超级用户) - - - Options - 选项 - - - - - Language - 语言 - - - - System default - 系统默认 - - - - English - 英语 - - - - Chinese (Simplified) - 简体中文 - - - - Switch the interface language to "%1"? - -The application needs to restart for the change to take effect. - 确定将界面语言切换为“%1”吗? - -需要重启应用程序才能生效。 - MemoryDetailWidget @@ -2241,4 +2206,4 @@ Warning: one or more selected processes are owned by another user. This applicat 已登录用户:%1 - \ No newline at end of file + diff --git a/src/ui/uihelper.cpp b/src/ui/uihelper.cpp index f649e45..5b86512 100644 --- a/src/ui/uihelper.cpp +++ b/src/ui/uihelper.cpp @@ -296,4 +296,4 @@ void UIHelper::EnableGraphContextMenu(QWidget *widget) AddGraphContextMenuItems(&menu, widget); menu.exec(widget->mapToGlobal(pos)); }); -} \ No newline at end of file +} From 7beafe3f012e86d1695dd63324927d30b3ef7163 Mon Sep 17 00:00:00 2001 From: Petr Bena Date: Wed, 9 Sep 2026 21:56:55 +0200 Subject: [PATCH 4/4] simplified localization loader we are using embed_translations we don't need to ship localizations twice --- debian/install | 1 - src/i18n.cpp | 41 +++++++++-------------------------------- src/i18n.h | 2 +- src/main.cpp | 2 +- 4 files changed, 11 insertions(+), 35 deletions(-) diff --git a/debian/install b/debian/install index 7af522d..0474b0d 100644 --- a/debian/install +++ b/debian/install @@ -1,4 +1,3 @@ debian/build/tux-manager usr/bin/ -debian/build/.qm/tux-manager_zh_CN.qm usr/share/tux-manager/translations/ src/tux_manager_icon.svg usr/share/pixmaps/ packaging/data/io.github.benapetr.TuxManager.desktop usr/share/applications/ diff --git a/src/i18n.cpp b/src/i18n.cpp index fd5da9c..1b2cdd7 100644 --- a/src/i18n.cpp +++ b/src/i18n.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -41,24 +42,6 @@ namespace return t; } - // Directories that may contain our "_.qm" files. - // The resource path is always available because translations are embedded - // at build time (:/i18n/), the filesystem paths cover packaged installs - // and development builds. A custom directory can be supplied through the - // TUX_MANAGER_I18N_DIR environment variable. - QStringList translationSearchDirs() - { - QStringList dirs; - const QString overrideDir = qEnvironmentVariable("TUX_MANAGER_I18N_DIR"); - if (!overrideDir.isEmpty()) - dirs << overrideDir; - dirs << QCoreApplication::applicationDirPath() + QStringLiteral("/translations"); - dirs << QStringLiteral("/usr/share/tux-manager/translations"); - dirs << QCoreApplication::applicationDirPath() + QStringLiteral("/../share/tux-manager/translations"); - dirs << QStringLiteral(":/i18n"); - return dirs; - } - bool isEnglishLanguage(const QString &code) { if (code.isEmpty()) @@ -70,8 +53,8 @@ namespace || base == QStringLiteral("posix"); } - // Try to load a catalog (e.g. "tux-manager" or "qtbase") for the given - // language. Exact match is preferred, then the language part only. + // Load an embedded application catalog. Exact locale match is preferred, + // then the language part only. bool loadCatalog(QTranslator *translator, const QString &catalog, const QString &language) { QStringList candidates; @@ -80,19 +63,13 @@ namespace if (underscore > 0) candidates << language.left(underscore); - for (const QString &dir : translationSearchDirs()) + for (const QString &lang : candidates) { - for (const QString &lang : candidates) + const QString path = QStringLiteral(":/i18n/") + catalog + QLatin1Char('_') + lang + QStringLiteral(".qm"); + if (translator->load(path)) { - const QString fileName = catalog + QLatin1Char('_') + lang + QStringLiteral(".qm"); - const QString path = dir.endsWith(QLatin1Char('/')) ? dir + fileName : dir + QLatin1Char('/') + fileName; - if (!QFile::exists(path)) - continue; - if (translator->load(fileName, dir)) - { - LOG_DEBUG(QString("I18n: loaded %1 from %2").arg(fileName, dir)); - return true; - } + LOG_DEBUG(QString("I18n: loaded embedded catalog %1").arg(path)); + return true; } } return false; @@ -100,7 +77,7 @@ namespace } -void I18n::installTranslators() +void I18n::InstallTranslators() { const QString code = QLocale::system().name(); diff --git a/src/i18n.h b/src/i18n.h index 02fc14e..72ddddf 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -24,7 +24,7 @@ namespace I18n { /// Install application and Qt translators for the system language. /// Must be called after QApplication exists and before widgets are created. - void installTranslators(); + void InstallTranslators(); } #endif // I18N_H diff --git a/src/main.cpp b/src/main.cpp index 8d14a14..bcd4e49 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) // Install translations for the system language before any widget is // created, so all tr() calls already resolve to the right text. - I18n::installTranslators(); + I18n::InstallTranslators(); LOG_INFO(QString("%1 %2 starting (verbosity=%3)").arg(a.applicationName(), a.applicationVersion()).arg(verbosity));