Passion/Python

PyQt에서 다국어 지원 개발

sunshout 2009. 8. 5. 13:50

PyQt에서 다국어(internationalization) 하기

 

개요:

PyQt 프로그래밍은 다국어 지원을 위한 프레임워크를 지원한다.

이를 지원하는 툴 체인 프로그램은 py-lupdate4, lrelease, Qt Linguist 가 존재한다.

실제 프로그래밍에서는 다국어를 지원하고자 하는 object에 tr() 함수를 통해서 지원한다.

 

예를 들어 QString("&Save") 대신에 self.tr("&Save")로 바꾸면 시스템의 Locale에 따라서 다국어를 지원하게 된다.

 

개발 방법론:

  1. Create the application using QObject.tr() or QApplication.translate() for all user-visible strings
  2. Modify the application to read in the locale-specific .qm (Qt message)files at start-up if they are available
  3. Create a .pro file that lists the application's .ui (Qt Designer) files, its .py and .pyw source files, and the .ts (translation source) file that it will use
  4. Run pylupdate4 to create the .ts file
  5. Ask the translator to translate the .ts file's strings using Qt Linguist
  6. Run lrelease to convert the updated .ts file (that contains the translations ) to a .qm file