[Qgis-developer] plugin translation

Matthias Kuhn matthias at opengis.ch
Tue Mar 22 02:35:57 PDT 2016

Hi Matteo

The pieces to put together a functional translation are:

* Use a tr() function to translate strings in your app and "mark" them
as translatable for lupdate
* Let lupdate find the strings
* Translate the strings (.ts files)
* Let lrelease compile the translation file
* Load the compiled translation file in your app with a QTranslator
* tr() will now return translated strings instead of the original (menu,
label, whatever...)

Some of these jobs can be done by a Makefile or by qmake (.pro) but in
the background, the above steps are what actually happen

I hope this helps,

On 03/22/2016 10:27 AM, matteo wrote:
> Hi Richard (and all),
> I'm still fighting with the menu translation of the plugin..
> I read the Qt Documentation and other related questions in forums, but
> I'm still struggling.
> It seems that, as you said, the tr function should do the magic, but it
> won't..
> I found out that with the main menu the method
> QCoreApplication.translate is used while with the submenus nothing is
> used.. for example:
> #main menu
> self.menu.ModelSetUp_menu =
> QMenu(QCoreApplication.translate("my_plugin", "Model Setup"))
> #submenu of menu "model Setup"
> self.actionProgramLocations = QAction( "&Program &Locations",
> self.iface.mainWindow())
> I tried to add the tr function in both, like
> self.menu.ModelSetUp_menu = QMenu(self.tr("my_plugin", "Model Setup"))
> #submenu of menu "model Setup"
> self.actionProgramLocations = QAction( self.tr("&Program &Locations"),
> self.iface.mainWindow())
> and then updated pro file.. but in the final ts, these strings are not
> taken into account..
> I also tried to find other plugins that maybe have implemented this menu
> translation function, but I did not find anything (just the UIs and
> their strings translated, but not the menus)...
> Somebody has an idea on how to implement that?
> Thanks for the help
> Cheers
> Matteo
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer

Matthias Kuhn
OPENGIS.ch - https://www.opengis.ch
Spatial • (Q)GIS • PostGIS • Open Source

More information about the Qgis-developer mailing list