Thursday 21 November 2019

pyqgis - Edit UI - Python Init function localization with QTranslator?



I have interaction with layer defined by custom designed UIs. In layer properties the following settings: Edit UI - customline.ui and Python Init function: customline_set.py.


#coding: utf8
from PyQt4.QtCore import *
from PyQt4.QtGui import *

nameField = None
myDialog = None

def formOpen(dialog,layerid,featureid):
global myDialog

myDialog = dialog
global nameField

translator = QTranslator()
loc = QSettings().value('locale/userLocale')[0:2]
print loc
filename = "\\i18n\\customline_%s.qm" % loc
print filename
translator.load(filename)
QCoreApplication.installTranslator(translator)


print QCoreApplication.translate('editForm',"Generals")
# return translated string ok



The code work without error but the UI it's not displayed in selected language.


Can anyone point me in the direction of the mistake here?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...