[Interest] QTranslator.load and builtin translations

Jérôme Laheurte jerome at jeromelaheurte.net
Tue Aug 18 16:28:42 CEST 2020


Hello. Is there a way to load the « builtin » translation, say for qtbase, without having to specify a filename ? I expected the QTranslator.load(QLocale, …) method to do just that, but alas, I still need to specify that I want to load, say, « qtbase_fr ». My problem is that I don’t see any nice way to find the filename based on the current locale. QLocale.uiLanguages()[0] is « fr-FR » for a French system for example, so right now I’m doing

        path = QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)
        trans = QtCore.QTranslator(self)
        name = QtCore.QLocale.system().uiLanguages()[0].split('-')[0]
        trans.load('qtbase_%s' % name, path)
        self.installTranslator(trans)

The « split(‘-‘)[0] » part looks like a big code smell to me, but what should I do ? I tried a number of variations using both load() methods, to no avail.

Best regards
Jérôme Laheurte



More information about the Interest mailing list