General and Desktop
2018.01.27 00:27

다국어 지원 어플리케이션 개발

조회 수 5422 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

어플리케이션 개발시 유니코드및 다국어 지원을 기본으로 하는 것이 바람직한 개발 방향이다.

Qt는 다국어 개발에 대한 좋은 솔루션을 제공하고있는데 여기서 다국어 사용 및 개발방법을 설명하고자 한다.

Linguist툴은 QML에서 qsTr(), C++소스코드의 tr()을 사용한 문자열을 가져와 XML구조의 ts파일을 만든다. 

 

예를 들어 QML의 문자열이 사용되는 곳에 아래 코드와 같이 사용될 것이다.

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
}

 

언어별 ts파일이 생성되어야 하는데 프로젝트파일(.pro)에 정의해주어야한다.

.pro파일을 열고 아래처럼 언어별 정의를 해주는데 이름에 규칙이나 제한은 없지만 여기선 "_" 다음에 ISO 3166-1 alpha-2 국가부호로 해줬다.

TRANSLATIONS += lang_ko.ts

 

이제 ts파일을 생성하기위해 QtCreator에서 Tools - External - Linguist - Update Translations (lupdate)를 실행한다.

lupdate.png

 

프로젝트가 위치한 곳에 ts파일이 생성된다.

Linguist 실행하고 생성된 ts파일을 열면 컨텍스트, 문자열, 원본 코드를 볼 수 있다.

편집 - 번역파일설정을 선택해서 해당되는 언어, 국가를 설정한다.

linguist_setting.png

원본 텍스트에 해당하는 문자열을 입력하고 ctrl + 엔터를 누르거나 linguist-doneandnext.png 아이콘을 클릭해서 번역을 수행한다.

Linguist.png

 

번역을 완료하고 저장후에 파일 - 배포 클릭하면 ts파일이 위치한 곳에 qm파일이 생성된다.

이제 프로젝트의 메인 함수에서 QTranslator객체를 생성하고 생성된 qm파일을 로드하고 install하는 코드를 작성한다.
...

QGuiApplication app(argc, argv);

QTranslator translator;
translator.load("lang_ko.qm");
app.installTranslator(&translator);

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
    return -1;

return app.exec();

...

 

아래의 코드는 QML에서 3D Studio 컴포넌트의 텍스트 요소의 속성(문자열)을 바꾸도록한 예제이다.

...

function setLanguageMenu()
{
    menuLight.setAttribute("textstring", qsTr("Light"))
    menuDrive.setAttribute("textstring", qsTr("Drive"))
    menuRotate.setAttribute("textstring", qsTr("Rotate"))
}

Studio3D{
    anchors.fill: parent

    Presentation {
        id: cluster
        source: "qrc:/presentation/3d_example.uia"

        Element{
            id: menuLight
            elementPath: "Scene.MenuLayer.Menu.Light"
        }
        Element{
            id: menuDrive
            elementPath: "Scene.MenuLayer.Menu.Drive"
        }
        Element{
            id: menuRotate
            elementPath: "Scene.MenuLayer.Menu.Rotate"
        }

        Component.onCompleted: {
            if(langKor)
                setLanguageMenu()
        }
    }
}

...

 

이제 프로젝트를 빌드하고 어플리케이션이 실행되면 번역된 문자열이 출력된다.

translation_kor.png

 

 


  1. No Image notice

    Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서

    Date2019.01.05 CategoryQML and Qt Quick By운영자 Views109964
    read more
  2. Windows환경에서 mingw로 Qt 5.10 정적(static)빌드

    Date2018.02.01 CategoryInstallation and Deployment Bymakersweb Views8240
    Read More
  3. 다국어 지원 어플리케이션 개발

    Date2018.01.27 CategoryGeneral and Desktop Bymakersweb Views5422
    Read More
  4. No Image

    Qt 어플리에이션 전역에 폰트 설정

    Date2018.01.24 CategoryGeneral and Desktop Bymakersweb Views8498
    Read More
  5. Qt 3D Studio 시작하기

    Date2018.01.11 CategoryInstallation and Deployment Bymakersweb Views6234
    Read More
  6. No Image

    QPA 플러그인과 HTML5 Backend

    Date2017.12.27 CategoryMobile and Embedded Bymakersweb Views3695
    Read More
  7. 임의의 메모리 영역(QImage)에 QPainter를 이용하여 그리기

    Date2017.12.19 CategoryGeneral and Desktop Bymakersweb Views6538
    Read More
  8. No Image

    QML에서 undefined를 확인하는 방법

    Date2017.11.29 CategoryQML and Qt Quick Bymakersweb Views4358
    Read More
  9. QPA 플러그인과 EGLFS

    Date2017.11.21 CategoryMobile and Embedded Bymakersweb Views7315
    Read More
  10. No Image

    타임스탬프( timestamp) 유닉스 시간

    Date2017.10.19 CategoryGeneral and Desktop Bymakersweb Views4661
    Read More
  11. No Image

    Qt Logging Rule, Qt 프레임워크 로그 출력

    Date2017.01.13 CategoryGeneral and Desktop Bymakersweb Views7295
    Read More
  12. No Image

    QString 문자열에서 숫자만 추출해서 QString으로 반환

    Date2017.01.10 Bymakersweb Views5977
    Read More
  13. No Image

    멀티 스레드환경, 스레드에 안전한 이벤트처리

    Date2016.10.27 CategoryGeneral and Desktop Bymakersweb Views7680
    Read More
  14. Ubuntu Linux에서 Qt Creator 설치

    Date2016.03.06 CategoryInstallation and Deployment Bymakersweb Views13827
    Read More
  15. QtConcurrent를 이용하여 쓰레드를 만드는 방법과 MapReduce

    Date2016.01.24 Bymakersweb Views12231
    Read More
  16. No Image

    Qt 프로그래밍의 시작

    Date2015.10.25 CategoryGeneral and Desktop Bymakersweb Views17904
    Read More
  17. No Image

    Qt의 스레드간 시그널 슬롯의 커넥션타입

    Date2015.10.24 CategoryGeneral and Desktop Bymakersweb Views13736
    Read More
  18. Qt의 시그널 슬롯 시스템

    Date2015.10.20 CategoryGeneral and Desktop Bymakersweb Views27639
    Read More
  19. No Image

    QQuickImageProvider 를 이용한 Qml 에서 이미지 표시

    Date2015.10.18 CategoryC++ Class Bymakersweb Views8530
    Read More
  20. Qml 사용자 ScrollBar 구현

    Date2015.07.24 CategoryQML and Qt Quick Bymakersweb Views8667
    Read More
  21. No Image

    z-order 를 컨트롤 하기위한 방법

    Date2015.05.13 CategoryQML and Qt Quick Bymakersweb Views9615
    Read More
Board Pagination Prev 1 ... 5 6 7 8 9 Next
/ 9