Question

Subj: is it possible? For example, can I translate QtGui.QFileDialog().getSaveFileName() button "Save" to "Conservare", and "Cancel" to "Ignorare"? Is it possible to create my class based on QFileDialog/QFontDialog without inventing a velocity? Someone said that these functions will be always translated, depending os system locale. Don't believe, my Russian version of OpenSUSE says that it is a lie. :-) And Russian Windows 7 has a such behaviour. All strings which I see on my systems are English. I'm not a nationalist, but I want to use strings in other languages. :-) Thanks!

Was it helpful?

Solution

A standard Qt installation should include 20 or so translation files for the Qt library itself.

An explanantion of how to use them can be found in this section of the Qt i18n docs.

Here's a basic PyQt4 example:

from PyQt4 import QtGui, QtCore

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.buttons = QtGui.QDialogButtonBox(self)
        button = self.buttons.addButton(QtGui.QDialogButtonBox.Open)
        button.clicked.connect(self.handleOpen)
        button = self.buttons.addButton(QtGui.QDialogButtonBox.Close)
        button.clicked.connect(self.close)
        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(self.buttons)

    def handleOpen(self):
        dialog = QtGui.QFileDialog()
        dialog.exec_()

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    translator = QtCore.QTranslator()
    if len(sys.argv) > 1:
        locale = sys.argv[1]
    else:
        locale = QtCore.QLocale.system().name()
    translator.load('qt_%s' % locale,
        QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath))
    app.installTranslator(translator)
    window = Window()
    window.show()
    sys.exit(app.exec_())

OTHER TIPS

I've already found a solution: qm files. You can get them from ts files, using lrelease.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top