user1224233 user1224233 - 1 year ago 144
Python Question

Pyqt English to Finnish Translation

I want to convert the langauge of pyqt application from english to finnish . I saw that pyqt has some methods for it and i try to use it but it didnt help me

app = QtGui.QApplication(sys.argv)
translator = QtCore.QTranslator()

.qm file is present at right path (right now its taking french i guess) and on button i use this text

name = "File"

Answer Source

It seems you are mixing two things: the translations of Qt itself (which are provided via qt_xx.qm files and distributed along with Qt) and your own translations.

Here you have an example using the russian translation file of Qt itself:

from PyQt4.QtGui import *
from PyQt4.QtCore import *

class MyWindow(QWidget):
    def __init__(self, parent=None):
        super(QWidget, self).__init__(parent)

        self.hbox = QHBoxLayout(self)
        self.myButtons = QDialogButtonBox(self)
        button = self.myButtons.addButton(QDialogButtonBox.Open)

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    translator = QTranslator()
    print translator.load("qt_ru", QLibraryInfo.location(QLibraryInfo.TranslationsPath))
    ui = MyWindow()

If you need your own translations then the Produce translations section of the i18n with Qt can be of help to you. You will need to provide a project file, your translation files (.ts) and use the Qt Linguist tool.

You can mix both the Qt itself translation and your own app translation by installing multiple translators.

Please note that when loading the translator you don't have to add the .qm extension to the filename.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download