このページについて

qt_add_translation

Qt Linguist の.tsファイルを.qmファイルにコンパイルします。

このコマンドは、Qt6 パッケージのLinguistTools コンポーネントに定義されています。以下のコマンドでパッケージを読み込んでください:

find_package(Qt6 REQUIRED COMPONENTS LinguistTools)

警告: この関数は非推奨です 。代わりに、ターゲットベースの関数qt_add_lrelease()またはqt_add_translations()の使用を検討してください。

概要

qt_add_translation(<VAR> file1.ts [file2.ts ...]
                    [OPTIONS ...])

バージョン指定なしのコマンドが無効になっている場合は、代わりに `qt6_add_translation ` を使用してください。このコマンドと同じ引数のセットをサポートしています。

説明

引数として渡された各.ts ファイルに対してlrelease を呼び出し、.qm ファイルを生成します。生成されたファイルのパスは、<VAR> に追加されます。

オプション

lrelease が呼び出される際に渡すべき追加のOPTIONS を設定できます。利用可能なオプションについては、lreleaseのドキュメントを参照してください。

デフォルトでは、qm ファイルは現在のビルドディレクトリ(CMAKE_CURRENT_BINARY_DIR )に配置されます。これを変更するには、qt_add_translation を呼び出す前に、ソースファイル.ts のプロパティとしてOUTPUT_LOCATION を設定します。

たとえば、以下のコードでは、.qm ファイルが現在のビルドディレクトリ直下のtranslations ディレクトリに生成されます。

set_source_files_properties(app_en.ts app_de.ts
    PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/translations")
qt_add_translation(qmFiles app_en.ts app_de.ts)

例

ビルドディレクトリ内にhelloworld_en.qm およびhelloworld_de.qm を生成する場合:

qt_add_translation(qmFiles helloworld_en.ts helloworld_de.ts)

l10n サブディレクトリにhelloworld_en.qm 、helloworld_de.qm を生成する:

set(TS_FILES helloworld_en.ts helloworld_de.ts)
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "l10n")
qt_add_translation(qmFiles ${TS_FILES})

© 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.