Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt: translating standard buttons

How can I easily translate standard buttons (Yes, No) from QMessageBox? I can't use self.tr on those arguments, so I would like to achieve it in some other simple way. Do I have to use whole translation system?

like image 346
gruszczy Avatar asked Dec 07 '22 05:12

gruszczy


1 Answers

Here is how I did :

First you need to copy the qt_LOCALE.qm file to your application directory. Mine was :

cp /usr/share/qt4/translations/qt_fr.qm .

Secondly, you need to load a translator for your application.

application = QApplication(argv)

locale = QLocale.system().name()
qtTranslator = QTranslator()
if qtTranslator.load("qt_"+locale):
    application.installTranslator(qtTranslator)

main_window = QMainWindow()
main_window.show()

exit(application.exec_())
like image 81
Natim Avatar answered Dec 11 '22 11:12

Natim