From 3c85a4a13d6829427a3b4a93a079f1e3380d7bf4 Mon Sep 17 00:00:00 2001 From: Liu Zhangjian Date: Wed, 17 Dec 2025 13:12:05 +0800 Subject: [PATCH] refactor: simplify Qt5 translation generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove unnecessary find_program call for lrelease in Qt5 build configuration Use direct lrelease command instead of QT_LRELEASE_EXECUTABLE variable Remove redundant add_custom_target for translations since QM files are already handled as dependencies This simplifies the build configuration and avoids potential issues with lrelease executable detection Influence: 1. Verify Qt5 builds still generate translation files correctly 2. Test that language switching works properly in the application 3. Confirm build process completes without lrelease-related errors 4. Check that all translation files are properly included in the final binary refactor: 简化 Qt5 翻译生成流程 移除 Qt5 构建配置中不必要的 lrelease 程序查找调用 直接使用 lrelease 命令替代 QT_LRELEASE_EXECUTABLE 变量 移除冗余的 translations 自定义目标,因为 QM 文件已作为依赖项处理 这简化了构建配置并避免了 lrelease 可执行文件检测的潜在问题 Influence: 1. 验证 Qt5 构建仍能正确生成翻译文件 2. 测试应用程序中的语言切换功能正常工作 3. 确认构建过程不会出现 lrelease 相关错误 4. 检查所有翻译文件是否正确包含在最终二进制文件中 --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79b7849..cb1d333 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,20 +84,18 @@ if (QT_VERSION_MAJOR MATCHES 6) ) else() # Qt5 手动生成 QM 文件 - find_program(QT_LRELEASE_EXECUTABLE NAMES lrelease-qt5 lrelease) set(QM_FILES) foreach(TS_FILE ${TS_FILES}) get_filename_component(TS_FILE_NAME ${TS_FILE} NAME_WE) set(QM_FILE "${CMAKE_CURRENT_BINARY_DIR}/${TS_FILE_NAME}.qm") add_custom_command( OUTPUT ${QM_FILE} - COMMAND ${QT_LRELEASE_EXECUTABLE} -compress -nounfinished -removeidentical ${TS_FILE} -qm ${QM_FILE} + COMMAND lrelease ${TS_FILE} -qm ${QM_FILE} DEPENDS ${TS_FILE} COMMENT "Generating ${QM_FILE} from ${TS_FILE}" ) list(APPEND QM_FILES ${QM_FILE}) endforeach() - add_custom_target(translations ALL DEPENDS ${QM_FILES}) endif() # 在文件开头部分添加自动 moc 处理