Qt Quick I18N

Qt Quick 애플리케이션에 대한 번역 파일(TS 및 QM) 생성하기.

예제 애플리케이션을 실행하면 QML 런타임이 시스템 언어에 따라 기본 .qml 파일이 포함된 디렉터리의 i18n 하위 디렉터리에서 번역을 자동으로 로드합니다.

텍스트를 번역 가능으로 표시

Main.qml 파일에서 qsTr 명령을 사용하여 UI 텍스트를 번역 가능으로 표시합니다:

        Text {
            text: qsTr("Hello")

번역 활성화하기

main.cpp 파일에서 QQmlApplicationEngine 을 사용하여 기본 QML 파일이 포함된 디렉터리의 i18n 이라는 하위 디렉터리에서 번역 파일을 자동으로 로드합니다:

#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;

i18n 하위 디렉터리의 번역 파일 이름에는 접두사 qml_ 가 있어야 합니다. 예를 들어 qml_en_AU.ts 입니다.

번역 파일 만들기

CMakeLists.txt 파일에 find_package 명령의 값으로 LinguistTools 모듈을 추가합니다:

find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Qml LinguistTools)

qt_add_translations 명령에서 생성할 번역 파일을 정의합니다:

qt_add_translations(qmli18n
    RESOURCE_PREFIX /qt/qml/Translated/i18n
    TS_FILE_BASE qml
    TS_FILE_DIR i18n
)

애플리케이션을 빌드하여 TS 및 QM 파일을 생성합니다.

참고: Android에서는 QM 파일을 리소스로 포함해야 합니다.

번역 추가하기

새 언어에 대한 번역을 만들려면 i18n/base.ts를 i18n/qml_<lang>.ts에 복사합니다. 문자열을 번역하려면 Qt Linguist 을 사용하여 문자열을 번역할 수 있습니다.

예제 프로젝트 @ code.qt.io

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