Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-arch-aur.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
run: |
pacman -Syu --noconfirm --needed \
git \
qt6-base
qt6-base \
qt6-tools

- name: Checkout
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-debian-qt6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
qmake6 \
qt6-base-dev \
qt6-base-dev-tools \
qt6-l10n-tools \
libgl1-mesa-dev

- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ Priority: optional
Maintainer: Petr Bena <petr@bena.rocks>
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

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.
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
14 changes: 7 additions & 7 deletions packaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions packaging/package-appimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions packaging/package-arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}')
Expand Down
3 changes: 2 additions & 1 deletion packaging/package-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ if command -v dpkg-query >/dev/null 2>&1; then
require_pkg debhelper
require_pkg dpkg-dev
require_pkg pkg-config
require_one_of qtbase5-dev qt6-base-dev
require_one_of qt6-base-dev qtbase5-dev
require_one_of qt6-l10n-tools qttools5-dev-tools

if [ ${#missing[@]} -gt 0 ] || [ ${#missing_groups[@]} -gt 0 ]; then
echo "Missing build dependencies detected."
Expand Down
4 changes: 4 additions & 0 deletions packaging/package-rpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions src/TuxManager.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SOURCES += \
aboutdialog.cpp \
colorschemedialog.cpp \
colorscheme.cpp \
i18n.cpp \
main.cpp \
mainwindow.cpp \
metrics.cpp \
Expand Down Expand Up @@ -68,6 +69,7 @@ HEADERS += \
colorschemedialog.h \
colorscheme.h \
globals.h \
i18n.h \
mainwindow.h \
metrics.h \
misc.h \
Expand Down Expand Up @@ -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
Expand Down
139 changes: 139 additions & 0 deletions src/i18n.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Tux Manager - Linux system monitor
* Copyright (C) 2026 Petr Bena <petr@bena.rocks>
*
* 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 <https://www.gnu.org/licenses/>.
*/

#include "i18n.h"
#include "logger.h"

#include <QCoreApplication>
#include <QFile>
#include <QLibraryInfo>
#include <QLocale>
#include <QStringList>
#include <QTranslator>
#include <QtGlobal>

namespace
{
// Translators live for the whole application lifetime.
QTranslator *appTranslator()
{
static QTranslator *t = new QTranslator();
return t;
}

QTranslator *qtTranslator()
{
static QTranslator *t = new QTranslator();
return t;
}

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");
}

// 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;
candidates << language;
const int underscore = language.indexOf(QLatin1Char('_'));
if (underscore > 0)
candidates << language.left(underscore);

for (const QString &lang : candidates)
{
const QString path = QStringLiteral(":/i18n/") + catalog + QLatin1Char('_') + lang + QStringLiteral(".qm");
if (translator->load(path))
{
LOG_DEBUG(QString("I18n: loaded embedded catalog %1").arg(path));
return true;
}
}
return false;
}

}

void I18n::InstallTranslators()
{
const QString code = QLocale::system().name();

// 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;
}

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;
}

// 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;
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));
}
30 changes: 30 additions & 0 deletions src/i18n.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Tux Manager - Linux system monitor
* Copyright (C) 2026 Petr Bena <petr@bena.rocks>
*
* 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 <https://www.gnu.org/licenses/>.
*/

#ifndef I18N_H
#define I18N_H

//! Application localization helpers (Qt Linguist / QTranslator).
namespace I18n
{
/// 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
Loading