[QGIS-Developer] Is a plugin for QGIS3 with the user interface defined by code acceptable for the repository?

Richard Duivenvoorde rdmailings at duif.net
Mon Sep 7 01:21:28 PDT 2020


On 9/6/20 11:38 PM, Luis Eduardo wrote:
> Hello everyone
> 
> I am working on a plugin, I have created a minimal Plugin, the user interface (dialog) I have defined by code. Without using Qt Designer.
> If I would like to upload this plugin to the QGIS repository, for the community in general, would it be acceptable?
> 
> In that case, how can I handle the translation of the interface into different languages. Can I do it by code?
> 
> I explain, get QSettings by knowing the language uploading the plugin this way. Is this acceptable too?
> 
> If not, how can I implement QTranslator in this case?

Hi Luis,

Yes, plugins is fine, there is rule that you only can uploade .ui files based plugins.

Yes you can do translation by code.
If you create a test plugin using the Plugin Builder plugin, you get the idea how that is using the Qt translation framework.

See for example here: https://doc.qt.io/qt-5/i18n-source-translation.html
and https://doc.qt.io/qt-5/qtlinguist-hellotr-example.html

So using the 'tr' function instead of hard coded labels for your widgets you should be able to create a <yourlanguage>.ts file (source) and then using Linguist translate those to <otherlanguage>.ts files which you then compile to <otherlanguage.qm> files which should be picked up by your plugin (by pointing to the dir where they are in your plugin. See plugin builder example for that)

HTH

Regards,

Richard Duivenvoorde




More information about the QGIS-Developer mailing list