PySide/PyQt : loading Chinese language translator file (zh_CN.ts) ?



  • Hi All,
    Can any one tell me how to load Chinese language translator file (zh_CN.ts) with an exmple code .

    Please tell me what's wrong with this code and what needs to be done to get it work?
    would appreciate if any one could help meto slove this problem,thanks in advance.
    @
    from PySide import QtCore, QtGui
    import sys

    class MainWindow(QtGui.QMainWindow):
    def init(self,app,parent=None):
    QtGui.QMainWindow.init(self,parent)
    filelbl = QtGui.QLabel(self)
    filelbl.setText(self.tr("&File"))
    self.setCentralWidget(filelbl)
    self.setWindowTitle(self.tr("&File"))

    def main(args):
    app = QtGui.QApplication(args)
    translator = QtCore.QTranslator()
    translator.load("zh_CN.ts")
    app.installTranslator(translator)

    win=MainWindow(app)
    win.show()
    return app.exec_()
    

    if name=="main":
    main(sys.argv)

    zh_CN.ts file:

    <!DOCTYPE TS>
    <TS version="2.0" language="zh_CN">
    <context>
    <name>MainWindow</name>
    <message>
    <source>&File</source>
    <translation>文件(F)</translation>
    </message>
    </context>
    </TS>
    @
    thanks in advance.



  • Hi All,
    Never mind i solved it myself any ways thanks. Actually i had to generate ".qm" file for ".ts" then i have to replace "zh_CN.ts" with "zh_CN.qm" then everything worked great.

    @ translator.load("zh_CN.qm") @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.