[Qgis-developer] Plugin Translation
Alex Mandel
tech_dev at wildintellect.com
Tue Apr 28 14:10:59 EDT 2009
Borys Jurgiel wrote:
>> I was wondering if the mySettings is available via the python api so
>> that it can be checked by my new function. In fact changing the setting
>> in QGIS doesn't work either for plugins(Horst's or mine) since we don't
>> know how to detect the QGIS setting and only rely on the system setting
>> for now.
>
> Yes, it's very simple to use:
>
> settings = QSettings()
> if settings.value("locale/overrideFlag").toBool():
> myLocale = settings.value("locale/userLocale").toString()
> else:
> myLocale = ... # give the system settings
>
>
> For more info look:
> http://doc.trolltech.com/4.1/qsettings.html
> http://doc.trolltech.com/4.1/qvariant.html
> ~/.config/QuantumGIS/QGIS.conf
>
> Nice Day to Everybody!
> B.
That was the last little magic piece, now it works for all 3 ways:
QGIS Setting
Command Line --lang option
or System Locale
I noticed that the current setup doesn't allow for temporary override of
a QGIS setting, it rather changes it, but thats a minor issue for later.
Here's my code for use in other plugins
http://apps.sourceforge.net/trac/qgismetaedit/browser/trunk/translate.py
This might be something good to roll into QGIS and made available via
the api so that all plugins can trigger translations if they want
without a whole new copy of the code.
In your main plugin file you need something like
import os.path
from translate import localeSwitch
currentPath = os.path.dirname(__file__)
class MetaEditPlugin:
def __init__(self,iface):
self.iface = iface
try:
self.QgisVersion = unicode( QGis.QGIS_VERSION_INT )
# Apply translation if appropirate
localeSwitch(self,currentPath,"metaedit")
Thanks,
Alex
More information about the Qgis-developer
mailing list