feat: 添加国际化支持,适配系统语言

- CMakeLists.txt 添加 LinguistTools 翻译构建流程
- 添加 zh_CN 翻译文件(11 条)
- 构建时自动用 lrelease 编译 .ts 到 .qm
- .qm 文件安装到 translations/ 目录,dde-shell 自动加载
- 添加 update_translations 目标用于手动更新翻译源文件
- .gitignore 忽略 .qm 编译产物
This commit is contained in:
2026-07-13 20:31:06 +08:00
parent 9fb80cdfc8
commit 63face00a7
3 changed files with 97 additions and 3 deletions
+1
View File
@@ -2,3 +2,4 @@ build/
.cache/ .cache/
*.o *.o
*.so *.so
*.qm
+34 -3
View File
@@ -10,12 +10,42 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
find_package(Qt6 REQUIRED COMPONENTS Core Quick DBus) find_package(Qt6 REQUIRED COMPONENTS Core Quick DBus LinguistTools)
find_package(Dtk6 REQUIRED COMPONENTS Core) find_package(Dtk6 REQUIRED COMPONENTS Core)
# 插件 ID
set(PLUGIN_ID "org.deepin.ds.graphics-driver")
# 翻译源文件目录
set(TRANSLATIONS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/translations)
# 翻译文件列表
set(TS_FILES
${TRANSLATIONS_DIR}/${PLUGIN_ID}_zh_CN.ts
)
# 生成 .qm 编译翻译文件
set(QM_FILES
${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_ID}_zh_CN.qm
)
add_custom_command(
OUTPUT ${QM_FILES}
COMMAND /usr/lib/qt6/bin/lrelease ${TS_FILES} -qm ${QM_FILES}
DEPENDS ${TS_FILES}
COMMENT "Compiling translations to .qm files"
)
# 手动更新翻译源文件(不加入 ALL,仅在需要时手动 make update_translations
add_custom_target(update_translations
COMMAND /usr/lib/qt6/bin/lupdate ${CMAKE_CURRENT_SOURCE_DIR}/package -ts ${TS_FILES}
COMMENT "Updating translation source files"
)
add_library(org.deepin.ds.graphics-driver SHARED add_library(org.deepin.ds.graphics-driver SHARED
graphicsdriverapplet.h graphicsdriverapplet.h
graphicsdriverapplet.cpp graphicsdriverapplet.cpp
${QM_FILES}
) )
set_target_properties(org.deepin.ds.graphics-driver PROPERTIES PREFIX "") set_target_properties(org.deepin.ds.graphics-driver PROPERTIES PREFIX "")
@@ -34,5 +64,6 @@ target_link_libraries(org.deepin.ds.graphics-driver PRIVATE
# 安装到dde-shell插件目录 # 安装到dde-shell插件目录
install(TARGETS org.deepin.ds.graphics-driver DESTINATION /usr/lib/x86_64-linux-gnu/dde-shell) install(TARGETS org.deepin.ds.graphics-driver DESTINATION /usr/lib/x86_64-linux-gnu/dde-shell)
install(FILES package/metadata.json DESTINATION /usr/share/dde-shell/org.deepin.ds.graphics-driver) install(FILES package/metadata.json DESTINATION /usr/share/dde-shell/${PLUGIN_ID})
install(FILES package/driverview.qml DESTINATION /usr/share/dde-shell/org.deepin.ds.graphics-driver) install(FILES package/driverview.qml DESTINATION /usr/share/dde-shell/${PLUGIN_ID})
install(FILES ${QM_FILES} DESTINATION /usr/share/dde-shell/${PLUGIN_ID}/translations)
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="zh_CN">
<context>
<name>driverview</name>
<message>
<location filename="../package/driverview.qml"/>
<source>Unknown</source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Graphics Driver: </source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Graphics Driver Manager</source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Driver service is not available</source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Device Information</source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Current Driver: </source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Device: </source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Refresh</source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Test Install</source>
<translation></translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Installing... </source>
<translation>...</translation>
</message>
<message>
<location filename="../package/driverview.qml"/>
<source>Cancel</source>
<translation></translation>
</message>
</context>
</TS>