feat(i18n): 翻译加载与 .qm 构建

- 启动时按 locale 加载 gxde-ai-see_<locale>.qm(用户数据目录 / /usr/share)
- translations/gxde-ai-see_en.ts 翻译模板,lupdate/lrelease 接入 CMake 并安装
- README 补充翻译流程
This commit is contained in:
2026-10-30 20:23:15 +08:00
parent 77a4369cd6
commit ba7f57c7d5
5 changed files with 571 additions and 0 deletions
+23
View File
@@ -4,6 +4,9 @@
#include <DApplication>
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QLocale>
#include <QStandardPaths>
#include <QTranslator>
#include "app.h"
@@ -18,6 +21,26 @@ int main(int argc, char *argv[])
app.setApplicationVersion(QStringLiteral("0.1.0"));
app.setQuitOnLastWindowClosed(false);
const QString locale = QLocale::system().name();
auto *translator = new QTranslator(&app);
const QStringList translationDirs = {
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
+ QStringLiteral("/translations"),
QStringLiteral("/usr/share/gxde-ai-see/translations"),
QStringLiteral("/usr/local/share/gxde-ai-see/translations"),
};
bool translated = false;
for (const QString &dir : translationDirs) {
if (translator->load(QStringLiteral("gxde-ai-see_") + locale, dir) ||
translator->load(QStringLiteral("gxde-ai-see_") + locale.section(QLatin1Char('_'), 0, 0),
dir)) {
app.installTranslator(translator);
translated = true;
break;
}
}
Q_UNUSED(translated)
QCommandLineParser parser;
parser.setApplicationDescription(QStringLiteral("GXDE 小埃同学"));
parser.addHelpOption();