I did experience slow translations with a 8.1.37 gateway.
It was really frustrating, and decided to come up with a solution of my own.
Essentially, this is somewhat of a drop-in replacement to the existing translate() expression function. All you have to do is perform a find and replace, search for translate( and replace with runScript('yourLibrary.getTranslation', 0, .
Put the below code in a scripting project library (I used yourLibrary in my example above)
def getTranslationTerms():
from com.inductiveautomation.ignition.gateway import IgnitionGateway
from com.inductiveautomation.ignition.gateway.script import GatewaySystemUtilities
system.util.globals["translations"] = {}
package = IgnitionGateway.get().getLocalizationManager().loadFullPackage()
for translation in package.getAllTranslations():
try:
system.util.globals["translations"][unicode(translation.getSourceTerm())] = {}
system.util.globals["translations"][unicode(translation.getSourceTerm())][unicode(translation.getLocale())] = unicode(translation.getTranslation())
except Exception as e:
system.util.getLogger("badTranslation").info("following translation didn't work: " + unicode(translation.getSourceTerm()) + " " + unicode(translation.getLocale()) + " " + unicode(translation.getTranslation()))
def getTranslation(sourceTerm, locale):
try:
locale = str(locale)[:2]
sourceTerm = unicode(sourceTerm)
if sourceTerm in system.util.globals["translations"] and locale in system.util.globals["translations"][sourceTerm]:
return system.util.globals["translations"][sourceTerm][locale]
return sourceTerm
except Exception as e:
return str(e)
and put this line in the gateway startup script and update script :
yourLibrary.getTranslationTerms()
Please note : In the getTranslation function, the first line removes the last two characters of the locale in the session.props.locale . This worked nicely for my case, but might not work for you so you might have to tweak this.
What this code does is store in globals all the defined translations.
As everything is already loaded, the call to getTranslation is much faster. I haven’t experienced slow translations since using this.
Also apologies, this is definitely not my cleanest code and can certainly be improved.
Also, I’m fairly positive using the scripting approach you mentioned (system.util.translate) will yield worse results.