PySide Internationalization: Difference between revisions
No edit summary |
AutoSpider (talk | contribs) (Add "cleanup" tag) |
||
Line 1: | Line 1: | ||
{{Cleanup | reason=Auto-imported from ExpressionEngine.}} | |||
[[Category:LanguageBindings::PySide]] | [[Category:LanguageBindings::PySide]] | ||
Revision as of 16:18, 3 March 2015
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine. Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. |
English 日本語
Internationalizing PySide programs
You will need to make a project file first: kalam.pro
SOURCES = main.py
TRANSLATIONS = i18n/en_GB.ts i18n/eo_EO.ts
The two files in TRANSLATIONS will create two files for both languages (UK English and Esperanto here).
Now run:
# you can find this tool in Ubuntu in the package pyside-tools
$ pyside-lupdate kalam.pro
Now you have your translation files ready to be used with Qt Linguist per "this tutorial.":http://doc.qt.nokia.com/4.7/linguist-translators.html Load the .ts file, double click entries and type the translation, click the ? icon to mark them as finished then do File -> Release to compile a new .qm file. The translator uses the .qm files.
Adding translation support to your application is trivially easy:
translator = QtCore.QTranslator()
translator.load('i18n/eo_EO')
app = QtGui.QApplication(sys.argv)
app.installTranslator(translator)
Will load the Esperanto translations.
Every QObject has a function called tr which returns the translated string. pyside-lupdate which we ran above, simply scans your sourcecode to find all instances where it's called.
self.tr('sksddsl')
QObject.tr('xyz')
MyClassX.tr('nanana')