因為是剛開始學習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就可以啦!