因为是刚开始学习QT,最近的一个项目,需要支持多国语言,即中、英、俄,以下是两种实现方式:
方法一:
#多语言批处理
execute_process(
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
COMMAND "${LUPDATE_EXECUTABLE}" -recursive ./ -ts
"${LANGUAGES_DIRECTORY}/XXX_zh_CN.ts"
"${LANGUAGES_DIRECTORY}/XXX_en.ts"
"${LANGUAGES_DIRECTORY}/XXX_ru.ts"
COMMAND "${LRELEASE_EXECUTABLE}"
"${LANGUAGES_DIRECTORY}/XXX_zh_CN.ts" "${TRANSLATIONS_DIRECTORY}/XXX_zh_CN.qm"
"${LANGUAGES_DIRECTORY}/XXX_en.ts" "${TRANSLATIONS_DIRECTORY}/XXX_en.qm"
"${LANGUAGES_DIRECTORY}/XXX_ru.ts" "${TRANSLATIONS_DIRECTORY}/XXX_ru.qm"
)
方法二:
#多语言批处理
set (Langs zh_CN en_US ru_RU)
set (LUPDATE "${CMAKE_PREFIX_PATH}/bin/lupdate.exe")
set (LRELEASE "${CMAKE_PREFIX_PATH}/bin/lrelease.exe")
foreach(l ${Langs})
set (lname "${PROJECT_NAME}_${l}")
execute_process(COMMAND "${LUPDATE}" ./ -ts "${LANGUAGES_DIRECTORY}/${lname}.ts"
COMMAND "${LRELEASE}" "${lname}.ts" -qm "${TRANSLATIONS_DIRECTORY}/${lname}.qm"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
endforeach()
第二种方法只需要维护Langs就可以啦!
标签:LANGUAGES,CMake,XXX,TRANSLATIONS,ts,lupdate,语言包,DIRECTORY,qm From: https://www.cnblogs.com/kuaixue/p/18124255