qt_collect_translation_source_targets
翻訳の対象となるターゲットを収集します。
このコマンドは、Qt6 パッケージのLinguistTools コンポーネントで定義されています。以下のコマンドでパッケージを読み込みます:
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)このコマンドは Qt 6.7 で導入されました。
概要
qt_collect_translation_source_targets(out_var [DIRECTORY path])バージョン指定なしのコマンドが無効になっている場合は、代わりにqt6_collect_translation_source_targets() を使用してください。このコマンドと同じ引数セットをサポートしています。
説明
指定されたDIRECTORY およびそのすべてのサブディレクトリ内から、翻訳対象となるターゲットを収集します。DIRECTORY が指定されていない場合は、CMAKE_CURRENT_SOURCE_DIR からターゲットの収集を開始します。
このコマンドは、最初の引数として指定された変数にターゲットのリストを格納します。
翻訳対象からターゲットを除外する
デフォルトでは、インポートされていないすべての実行ファイルおよびライブラリ・ターゲットが翻訳の対象となります。
ターゲットプロパティ QT_EXCLUDE_FROM_TRANSLATION を設定することで、個々のターゲットを翻訳対象から除外することができます。
ディレクトリプロパティ QT_EXCLUDE_FROM_TRANSLATION を設定することで、特定のディレクトリ以下のターゲットを除外することができます。
このコマンドを呼び出すタイミング
qt_collect_translation_source_targets コマンドは、BUILDSYSTEM_TARGETSディレクトリのプロパティを読み取ります。その結果、このコマンドはすでに作成されているターゲットのみを収集します。qt_collect_translation_source_targets が呼び出された後に作成されたターゲットは収集されません。
ビルドシステムのすべてのターゲットを収集するには、最上位のCMakeLists.txt の最後にqt_collect_translation_source_targets を呼び出すか、最上位ディレクトリスコープの最後にcmake_language(DEFER CALL) を使用してi18nを設定してください。
例
qt_collect_translation_source_targets の結果を出力としてqt_add_lupdate に渡します。
add_subdirectory(src) # The actual application is defined here.
# All targets that have been defined up to this point will be in i18n_targets.
qt_collect_translation_source_targets(i18n_targets)
qt_add_lupdate(SOURCE_TARGETS ${i18n_targets})
# No targets from this directory are in i18n_targets.
add_subdirectory(tests) # Unit tests - we don't want to translate those.CMake 3.19 以降では、ディレクトリスコープの末尾でソースターゲットを収集できます。これにより、すべてのターゲットが定義される前にqt_collect_translation_source_targets を呼び出すことが可能になります。ただし、ディレクトリプロパティQT_EXCLUDE_FROM_TRANSLATION を ON に設定して、テストを除外する必要があります。
function(set_up_translations)
qt_collect_translation_source_targets(i18n_targets)
qt_add_lupdate(SOURCE_TARGETS ${i18n_targets})
endfunction()
cmake_language(DEFER CALL set_up_translations)
add_subdirectory(src) # The actual application is defined here.
add_subdirectory(tests) # Unit tests - we don't want to translate those.
set_property(DIRECTORY tests PROPERTY QT_EXCLUDE_FROM_TRANSLATION ON)© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.