[Qgis-developer] Plugin Translation

Borys Jurgiel borysiasty at aster.pl
Mon Apr 27 08:24:06 EDT 2009


Monday 27 of April 2009 07:07:07 Alex Mandel napisał(a):
> I think I'm most of the way to getting a translation done on the
> metaedit plugin(added some other features too) but I wanted to check on
> how QGIS knows to load a particular language. Do I have to add code to
> my plugin or will simply having the .qm files and the .pro file do it?

I'm not sure I understand you properly. As I've written, you need to set a 
QTranslator in your code. In Geoprocessing Plugin, Horst did it in that way: 

    userPluginPath = 
QFileInfo(QgsApplication.qgisUserDbFilePath()).path()+"/python/plugins/geoprocessing"
    systemPluginPath = 
QgsApplication.prefixPath()+"/share/qgis/python/plugins/geoprocessing"
    myLocaleName = QLocale.system().name()
    myLocale = myLocaleName[0:2]

    if QFileInfo(userPluginPath).exists():
      pluginPath = userPluginPath+"/i18n/geoprocessing_"+myLocale+".qm"
    elif QFileInfo(systemPluginPath).exists():
      pluginPath = systemPluginPath+"/i18n/geoprocessing_"+myLocale+".qm"

    self.localePath = pluginPath
    self.translator = QTranslator()
    self.translator.load(self.localePath)


Of course you need also to use the QCoreApplication.translate(context,string) 
for every translated string.

The .pro file is ONLY for creating/updating the .ts files with pylupdate4. Then 
you can compile the files to .qm with lrelease-qt4.

> 
> Also is there any way to test alternate languages in qgis without
> modifying the computer's locale setting. ie: a menu or an api call via
> python console that would just switch the language? maybe a command line
> option?

You need to either run qgis with a paramater --lang , e.g. qgis --lang de
or set it in the Options dialog and restart qgis



More information about the Qgis-developer mailing list