C
Qt Quick Ultralite translation Example
# Copyright (C) 2026 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial
cmake_minimum_required(VERSION 3.21.1)
project(translation VERSION 0.0.1 LANGUAGES C CXX ASM)
find_package(QulApp)
add_subdirectory(imports/static/fontconfiguration)
if(TARGET Qul::MonotypeSpark)
add_subdirectory(imports/spark/fontconfiguration)
endif()
set(TRANSLATION_FLAGS
japan-flag-small.png
latvia-flag-small.png
norway-flag-small.png
saudi-arabia-flag-small.png
thai-flag-small.png
usa-flag-small.png
japan-flag-small-icon.png
latvia-flag-small-icon.png
norway-flag-small-icon.png
saudi-arabia-flag-small-icon.png
thai-flag-small-icon.png
usa-flag-small-icon.png
)
set(TRANSLATION_ALL_TS_FILES
translation_ar_SA.ts
translation_ja_JP.ts
translation_lv_LV.ts
translation_nb_NO.ts
translation_th_TH.ts
)
# Every variant builds its own module from translation.qml, because the
# translations are embedded into the QML modules of the application target.
# The modules share the URI, so OUTPUT_DIRECTORY keeps their generated files apart.
function(add_translation_variant target fontconfig_module)
set(options OMIT_SOURCE_LANGUAGE)
set(single_args "")
set(multi_args TS_FILES IMAGES)
cmake_parse_arguments(arg "${options}" "${single_args}" "${multi_args}" ${ARGN})
if(QUL_PLATFORM MATCHES "autosar")
qul_add_library(${target})
else()
qul_add_executable(${target})
endif()
qul_add_qml_module(${target}
URI TranslationApp
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${target}_qml
QML_FILES translation.qml
RESOURCES ${arg_IMAGES}
NO_SBOM
)
qul_add_translations(${target} TS_FILES ${arg_TS_FILES})
if(arg_OMIT_SOURCE_LANGUAGE)
set_target_properties(${target} PROPERTIES QUL_OMIT_SOURCE_LANGUAGE ON)
endif()
target_link_libraries(${target} PRIVATE Qul::Controls ${fontconfig_module})
app_target_setup_os(${target})
app_target_default_entrypoint(${target} translation MODULE TranslationApp)
endfunction()
set(TRANSLATION_STATIC_FONT_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/fonts/kosugi/Kosugi-Regular.ttf"
"${CMAKE_CURRENT_SOURCE_DIR}/fonts/sarabun/Sarabun-Regular.ttf"
)
# Set up a target that includes all bundled languages
add_translation_variant(translation_all translation_fontconfig_static_module
TS_FILES ${TRANSLATION_ALL_TS_FILES}
IMAGES ${TRANSLATION_FLAGS}
)
# Qul ships some default fonts. Since they don't contain glyphs for all the
# characters that are needed for this application, add some extra fonts.
set_target_properties(translation_all PROPERTIES
QUL_FONT_FILES "${TRANSLATION_STATIC_FONT_FILES}"
)
# The StaticText item uses rich text, so merging static text glyphs, which some platforms do
# by default, is disabled with this internal property (formerly mergeStaticTextGlyphs).
set_target_properties(translation_all PROPERTIES
QUL_PRIVATE_PLATFORM_MERGE_STATIC_TEXT_GLYPHS OFF
)
# Set up a lv_LV-only target
add_translation_variant(translation_lv translation_fontconfig_static_module
TS_FILES translation_lv_LV.ts
IMAGES latvia-flag-small.png latvia-flag-small-icon.png
OMIT_SOURCE_LANGUAGE
)
set_target_properties(translation_lv PROPERTIES
QUL_FONT_FILES "${TRANSLATION_STATIC_FONT_FILES}"
QUL_PRIMARY_LANGUAGE "lv_LV"
)
# Rich text in StaticText: see translation_all
set_target_properties(translation_lv PROPERTIES
QUL_PRIVATE_PLATFORM_MERGE_STATIC_TEXT_GLYPHS OFF
)
if(TARGET Qul::MonotypeSpark)
# Set up Spark target
add_translation_variant(translation_spark translation_fontconfig_spark_module
TS_FILES ${TRANSLATION_ALL_TS_FILES}
IMAGES ${TRANSLATION_FLAGS}
)
set_target_properties(translation_spark PROPERTIES
QUL_FONT_ENGINE "Spark"
QUL_DEFAULT_FONT_FAMILY "arabic-style-font"
QUL_FONT_CACHE_SIZE 1 # Disable the cache
QUL_FONT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/fonts/monotype/TranslationsSampleFontmap.fmp"
)
if(QUL_PLATFORM MATCHES "^ek-ra8d1")
set_target_properties(translation_spark PROPERTIES
QUL_FONT_FILES_RESOURCE_STORAGE_SECTION "QulFontResourceDataInExternalFlash"
)
endif()
endif()