-
Notifications
You must be signed in to change notification settings - Fork 19
refactor: simplify Qt5 translation generation #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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. 检查所有翻译文件是否正确包含在最终二进制文件中
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors the Qt5 translation generation in CMake to directly invoke Flow diagram for updated Qt5 translation generation in CMakeflowchart TD
A[Configure_project CMake] --> B{QT_VERSION_MAJOR}
B -->|6| C[Use Qt6 built_in_translation_support]
B -->|5| D[Qt5_manual_QM_generation]
subgraph Qt5_translation_generation
D --> E[Iterate_TS_FILES]
E --> F[Compute_QM_file_path_for_each_TS]
F --> G[add_custom_command
COMMAND lrelease TS_FILE -qm QM_FILE
DEPENDS TS_FILE]
G --> H[Collect_QM_FILES]
H --> I[QM_FILES_used_as_dependencies_in_other_targets]
end
C --> J[Build_targets]
I --> J
J --> K[Application_binary_with_translations]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review我来帮你审查这个 CMakeLists.txt 的变更:
if (QT_VERSION_MAJOR MATCHES 6)
# Qt6 的处理保持不变
else()
# Qt5 处理翻译文件
find_program(QT_LRELEASE_EXECUTABLE
NAMES lrelease-qt5 lrelease
REQUIRED # 确保找到命令
)
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")
# 检查源文件是否存在
if(NOT EXISTS ${TS_FILE})
message(WARNING "Translation source file ${TS_FILE} does not exist")
continue()
endif()
add_custom_command(
OUTPUT ${QM_FILE}
COMMAND ${QT_LRELEASE_EXECUTABLE}
-compress
-nounfinished
-removeidentical
${TS_FILE}
-qm ${QM_FILE}
DEPENDS ${TS_FILE}
COMMENT "Generating ${QM_FILE} from ${TS_FILE}"
VERBATIM # 确保命令正确执行
)
list(APPEND QM_FILES ${QM_FILE})
endforeach()
# 确保翻译文件被构建
if(QM_FILES)
add_custom_target(translations ALL DEPENDS ${QM_FILES})
endif()
endif()
这些改进会使构建系统更加健壮和可靠,同时保持良好的性能。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Directly invoking
lreleaseinstead of using a discovered executable may break environments where onlylrelease-qt5exists or wherelreleaseis not on PATH; consider keepingfind_programor adding a configurable override to maintain portability. - By removing the
translationscustom target, QM generation now relies solely on existing dependencies; double-check that all relevant build targets (e.g., the main executable or bundles) still depend onQM_FILESso translations are consistently generated in all build configurations.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Directly invoking `lrelease` instead of using a discovered executable may break environments where only `lrelease-qt5` exists or where `lrelease` is not on PATH; consider keeping `find_program` or adding a configurable override to maintain portability.
- By removing the `translations` custom target, QM generation now relies solely on existing dependencies; double-check that all relevant build targets (e.g., the main executable or bundles) still depend on `QM_FILES` so translations are consistently generated in all build configurations.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Kakueeen, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
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:
binary
refactor: 简化 Qt5 翻译生成流程
移除 Qt5 构建配置中不必要的 lrelease 程序查找调用
直接使用 lrelease 命令替代 QT_LRELEASE_EXECUTABLE 变量
移除冗余的 translations 自定义目标,因为 QM 文件已作为依赖项处理
这简化了构建配置并避免了 lrelease 可执行文件检测的潜在问题
Influence:
Summary by Sourcery
Simplify Qt5 translation generation by invoking lrelease directly and relying on existing QM file dependencies instead of a separate translations target.
Build: