Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

PySide Internationalization: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Rename category "LanguageBindings::PySide" -> "PySide")
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:LanguageBindings::PySide]]
 
 
[[Category:PySide]]


'''English''' [[PySide-Internationalization-Japanese|日本語]]
'''English''' [[PySide-Internationalization-Japanese|日本語]]
Line 5: Line 7:
= Internationalizing PySide programs =
= Internationalizing PySide programs =


You will need to make a project file first:<br />'''kalam.pro'''<br /><code>SOURCES = main.py<br />TRANSLATIONS = i18n/en_GB.ts  i18n/eo_EO.ts<br /></code>
You will need to make a project file first:
'''kalam.pro'''
<code>SOURCES = main.py
TRANSLATIONS = i18n/en_GB.ts  i18n/eo_EO.ts
</code>


The two files in TRANSLATIONS will create two files for both languages (UK English and Esperanto here).
The two files in TRANSLATIONS will create two files for both languages (UK English and Esperanto here).


Now run:<br /><code># you can find this tool in Ubuntu in the package pyside-tools<br />$ pyside-lupdate kalam.pro</code>
Now run:
<code># you can find this tool in Ubuntu in the package pyside-tools
$ pyside-lupdate kalam.pro</code>


Now you have your translation files ready to be used with Qt Linguist per &quot;this tutorial.&quot;: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 -&gt; Release to compile a new .qm file. The translator uses the .qm files.
Now you have your translation files ready to be used with Qt Linguist per [http://doc.qt.io/qt-5/linguist-translators.html this tutorial.] 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:<br /><code><br /> translator = QtCore.QTranslator()<br /> translator.load('i18n/eo_EO')<br /> app = QtGui.QApplication(sys.argv)<br /> app.installTranslator(translator)<br /></code><br />Will load the Esperanto translations.
Adding translation support to your application is trivially easy:
<code>
translator = QtCore.QTranslator()
translator.load('i18n/eo_EO')
app = QtGui.QApplication(sys.argv)
app.installTranslator(translator)
</code>
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.<br /><code><br />self.tr('sksddsl')<br />QObject.tr('xyz')<br />MyClassX.tr('nanana')
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.
<code>
self.tr('sksddsl')
QObject.tr('xyz')
MyClassX.tr('nanana')

Latest revision as of 03:30, 5 June 2016


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. 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')