treeland/cmake/TranslationUtils.cmake

63 lines
1.8 KiB
CMake
Raw Permalink Normal View History

chore: improvement fixes the translation configuration This improvement fixes the translation configuration to automatically support multiple languages instead of being limited to Chinese and English only. Created `cmake/TranslationUtils.cmake` file with two main functions: - `setup_translations(TARGET_NAME TRANSLATION_PREFIX)`: For plugin and example translation configuration - `setup_main_translations(TARGET_NAME)`: For main program translation configuration Uses `file(GLOB ...)` command to automatically discover all available translation files, supporting languages including: - Afrikaans (af) - Amharic (am_ET) - Arabic (ar) - Asturian (ast) - Azerbaijani (az) - Bulgarian (bg) - Bengali (bn) - Tibetan (bo) - Bakhtiari (bqi) - Breton (br) - Catalan (ca) - Kurdish (ckb) - Czech (cs) - Danish (da) - German (de) - Greek (el) - English (en_US) - Spanish (es) - Persian (fa) - Finnish (fi) - French (fr) - Galician (gl_ES) - Hebrew (he) - Hindi (hi_IN) - Croatian (hr) - Hungarian (hu) - Indonesian (id) - Italian (it) - Japanese (ja) - Georgian (ka) - Kabyle (kab) - Khmer (km_KH) - Korean (ko) - Kurdish (ku) - Lithuanian (lt) - Malay (ms) - Norwegian (nb) - Nepali (ne) - Dutch (nl) - Polish (pl) - Portuguese (pt) - Brazilian Portuguese (pt_BR) - Romanian (ro) - Russian (ru) - Sinhala (si) - Slovak (sk) - Slovenian (sl) - Albanian (sq) - Serbian (sr) - Swedish (sv) - Tamil (ta) - Telugu (te) - Thai (th) - Turkish (tr) - Tamazight (tzm) - Uyghur (ug) - Ukrainian (uk) - Vietnamese (vi) - Simplified Chinese (zh_CN) - Traditional Chinese (zh_HK, zh_TW) - `src/CMakeLists.txt`: Main program translation configuration - `src/plugins/lockscreen/CMakeLists.txt`: Lock screen plugin translation configuration - `src/plugins/multitaskview/CMakeLists.txt`: Multitask view plugin translation configuration - `examples/test_set_treeland_wallpaper/CMakeLists.txt`: Wallpaper setting example translation configuration - `cmake/TranslationUtils.cmake`: New translation utilities file
2025-06-30 11:04:41 +08:00
# TranslationUtils.cmake
# Provides common functions for handling translation files
function(setup_translations TARGET_NAME TRANSLATION_PREFIX)
# Automatically discover all translation files
file(GLOB TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/translations/${TRANSLATION_PREFIX}.*.ts")
# Filter out non-translation files (if any)
list(FILTER TS_FILES INCLUDE REGEX ".*\\.ts$")
# Set translation files variable
set(TRANSLATED_FILES)
# Add lupdate target
qt_add_lupdate(
SOURCE_TARGETS ${TARGET_NAME}
TS_FILES ${TS_FILES}
NO_GLOBAL_TARGET
)
# Add lrelease target
qt_add_lrelease(
TS_FILES ${TS_FILES}
QM_FILES_OUTPUT_VARIABLE TRANSLATED_FILES
)
# Install translation files
install(FILES ${TRANSLATED_FILES} DESTINATION ${TREELAND_COMPONENTS_TRANSLATION_DIR})
# Set TRANSLATED_FILES variable to parent scope
set(TRANSLATED_FILES ${TRANSLATED_FILES} PARENT_SCOPE)
endfunction()
function(setup_main_translations TARGET_NAME)
# Automatically discover all main translation files
file(GLOB TS_FILES "${CMAKE_SOURCE_DIR}/translations/treeland.*.ts")
# Filter out non-translation files (if any)
list(FILTER TS_FILES INCLUDE REGEX ".*\\.ts$")
# Set translation files variable
set(TRANSLATED_FILES)
# Add lupdate target
qt_add_lupdate(
SOURCE_TARGETS ${TARGET_NAME}
TS_FILES ${TS_FILES}
NO_GLOBAL_TARGET
)
# Add lrelease target
qt_add_lrelease(
TS_FILES ${TS_FILES}
QM_FILES_OUTPUT_VARIABLE TRANSLATED_FILES
)
# Install translation files
install(FILES ${TRANSLATED_FILES} DESTINATION ${TREELAND_COMPONENTS_TRANSLATION_DIR})
# Set TRANSLATED_FILES variable to parent scope
set(TRANSLATED_FILES ${TRANSLATED_FILES} PARENT_SCOPE)
endfunction()