[QGIS-Developer] Plugins translation

Jorge Moreira jorgealmerio at yahoo.com.br
Sat Jul 28 11:57:38 PDT 2018


Hi devs,
For do the plugin translations I use
1) Linguist from QT52) The command line: 
    Pylupdate4 -noobsolete PluginName.pro (Is there a new version 5??)
3) and the classical code:
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir,
            'i18n',
            'PluginName_{}.qm'.format(locale))

        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)
        def tr(self, message):
            return QCoreApplication.translate(QWaterPlugin.SETTINGS, message)

The problem is that the option to use self.tr('message string') is not working. It only works when I use QCoreApplication.translate('Escope', 'message string') even if a tr function defined.

It used to work if linguist from QT4.

What  Am I doing wrong? BTW Is there a new better way to translate plugins?
Thanks,
Jorge Almerio

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180728/4b1c4d6f/attachment.html>


More information about the QGIS-Developer mailing list