summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorruki <[email protected]>2024-05-15 23:19:46 +0800
committerGitHub <[email protected]>2024-05-15 23:19:46 +0800
commita88318a2a9ca5f28ac330e3046703babe182c2ad (patch)
tree582aa96d4ea046073d40c9367f6d4c7b4efc4d47 /tests
parent304943e79b6e2c67d2c010f053d8cd2a42460ddd (diff)
parent81be0de6945e4633693a0f8306f1a95446cf3794 (diff)
Merge pull request #5103 from 1143910315/support-qt-translation
add qt ts files building
Diffstat (limited to 'tests')
-rw-r--r--tests/projects/qt/with_ts/src/demo_zh_CN.ts17
-rw-r--r--tests/projects/qt/with_ts/src/demo_zh_TW.ts17
-rw-r--r--tests/projects/qt/with_ts/src/main.cpp23
-rw-r--r--tests/projects/qt/with_ts/src/mainwindow.cpp13
-rw-r--r--tests/projects/qt/with_ts/src/mainwindow.h22
-rw-r--r--tests/projects/qt/with_ts/src/mainwindow.ui35
-rw-r--r--tests/projects/qt/with_ts/xmake.lua9
7 files changed, 136 insertions, 0 deletions
diff --git a/tests/projects/qt/with_ts/src/demo_zh_CN.ts b/tests/projects/qt/with_ts/src/demo_zh_CN.ts
new file mode 100644
index 000000000..b712a0c4d
--- /dev/null
+++ b/tests/projects/qt/with_ts/src/demo_zh_CN.ts
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="zh_CN">
+<context>
+ <name>MainWindow</name>
+ <message>
+ <location filename="mainwindow.ui" line="14"/>
+ <source>MainWindow</source>
+ <translation>主窗口</translation>
+ </message>
+ <message>
+ <location filename="mainwindow.ui" line="27"/>
+ <source>PushButton</source>
+ <translation>按钮</translation>
+ </message>
+</context>
+</TS>
diff --git a/tests/projects/qt/with_ts/src/demo_zh_TW.ts b/tests/projects/qt/with_ts/src/demo_zh_TW.ts
new file mode 100644
index 000000000..338b5c32e
--- /dev/null
+++ b/tests/projects/qt/with_ts/src/demo_zh_TW.ts
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="zh_TW">
+<context>
+ <name>MainWindow</name>
+ <message>
+ <location filename="mainwindow.ui" line="14"/>
+ <source>MainWindow</source>
+ <translation>主視窗</translation>
+ </message>
+ <message>
+ <location filename="mainwindow.ui" line="27"/>
+ <source>PushButton</source>
+ <translation>按鈕</translation>
+ </message>
+</context>
+</TS>
diff --git a/tests/projects/qt/with_ts/src/main.cpp b/tests/projects/qt/with_ts/src/main.cpp
new file mode 100644
index 000000000..6da7ba1ea
--- /dev/null
+++ b/tests/projects/qt/with_ts/src/main.cpp
@@ -0,0 +1,23 @@
+#include "mainwindow.h"
+#include <QApplication>
+#include <QLocale>
+#include <QTranslator>
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+
+ QTranslator translator;
+ const QStringList uiLanguages = QLocale::system().uiLanguages();
+ for (const QString& locale : uiLanguages) {
+ const QString baseName = "demo_" + QLocale(locale).name();
+ if (translator.load(baseName + ".qm")) {
+ a.installTranslator(&translator);
+ break;
+ }
+ }
+ MainWindow w;
+ w.show();
+
+ return a.exec();
+}
diff --git a/tests/projects/qt/with_ts/src/mainwindow.cpp b/tests/projects/qt/with_ts/src/mainwindow.cpp
new file mode 100644
index 000000000..ec2cba1ee
--- /dev/null
+++ b/tests/projects/qt/with_ts/src/mainwindow.cpp
@@ -0,0 +1,13 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
diff --git a/tests/projects/qt/with_ts/src/mainwindow.h b/tests/projects/qt/with_ts/src/mainwindow.h
new file mode 100644
index 000000000..8e06f4918
--- /dev/null
+++ b/tests/projects/qt/with_ts/src/mainwindow.h
@@ -0,0 +1,22 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+private:
+ Ui::MainWindow *ui;
+};
+
+#endif // MAINWINDOW_H
diff --git a/tests/projects/qt/with_ts/src/mainwindow.ui b/tests/projects/qt/with_ts/src/mainwindow.ui
new file mode 100644
index 000000000..6bbe2c1fc
--- /dev/null
+++ b/tests/projects/qt/with_ts/src/mainwindow.ui
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <widget class="QPushButton" name="pushButton">
+ <property name="geometry">
+ <rect>
+ <x>110</x>
+ <y>90</y>
+ <width>75</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>PushButton</string>
+ </property>
+ </widget>
+ </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests/projects/qt/with_ts/xmake.lua b/tests/projects/qt/with_ts/xmake.lua
new file mode 100644
index 000000000..bc9bdaffc
--- /dev/null
+++ b/tests/projects/qt/with_ts/xmake.lua
@@ -0,0 +1,9 @@
+add_rules("mode.debug", "mode.release")
+
+target("demo")
+ add_rules("qt.widgetapp")
+ add_headerfiles("src/*.h")
+ add_files("src/*.cpp")
+ add_files("src/mainwindow.ui")
+ add_files("src/mainwindow.h")
+ add_files("src/*.ts")