I've tried to change the Language of a QColorDialog from English to German but unfortunately it's not working. I am using PyQt.
What I've tried so far:
Setting the locale for the Dialog:
colordialog = QtWidgets.QColorDialog()
colordialog.setLocale(QtCore.QLocale(QtCore.QLocale.German, QtCore.QLocale.Germany))
Installing a translator for the whole application:
app = QtWidgets.QApplication(sys.argv)
qt_translator = QtCore.QTranslator()
qt_translator.load("qt_" + QtCore.QLocale.system().name(),
QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath))
app.installTranslator(qt_translator)
If you want to translate texts to German, you need to install a translator for German, not the system locale. Also the
QColorDialog()
shows the system color dialog if you don't specify theDontUseNativeDialog
option. So do like this for "Qt for Python"(PySide2).Of course, you can use the name of the system locale instead of hard-coding the locale like this, as you did, if you want to use the system locale.
For PyQt5, do like this.
But the current version(5.15.9) has is a bug that the
qtscript_*.qm
files are missing. So you should manually copy files from other Qt distribution. The following is an example of copying files from PySide2 in my Linux Anaconda environment.For PyQt6, the above bug was fixed and you can do like this.