Perspective - Scripting system.util.translate

I have to use the system.util.translate function for some reasons in binding and it’s very slow to proceed translation.

It takes more than 3 sec. to proceed 16 entries.

I run on a local gateway with Windows 10 pro x64, I7-10750H CPU @ 2.6GHZ, 16G RAM

If you’re looping over multiple terms, then I’m not surprised. The runtime for the system.util.translate() is going to equate to roughly one round trip call to the Gateway, plus a query execution and response for every invocation. If you’re doing that over sixteen terms, the execution time os going to add up.

Could you post the code in question just so the use-case is clear? If you’re translating a single phrase with sixteen words it should be quicker than 3 seconds.

Are you doing this:

terms = ['Let', 'us', 'try', 'out', 'how', 'this', 'translate', 'function', 'works']
translated = []
for term in terms:
    translated.append(system.util.translate(term, 'it'))
print(translated)

Or something like this:

print(system.util.translate('Let us try out how this translate function works'))
1 Like

I’m building a dropdown in that case.

    from _Class import CONVERT_MM
	dv = CONVERT_MM()
	
	instances=[]
	sp = chr(160)
	#Add home position if >=0
	if not value["home"] is None and value["home"] >= 0:
		convert_val = dv.indirect(value["home"], value["unit"])
		tagVal = '{:f}'.format(convert_val)
		val = unicode("{:.3f}".format(float(tagVal)))
		lbl = system.util.translate('lbl_Home',self.session.props.locale)
		instances.append({"value":value["home"],"label": lbl + ': ' + val.rjust(10 + (6-len(val)),sp)})
	
	#add closed position if > 0
	if not value["closed"] is None and value["closed"] > 0:
		convert_val = dv.indirect(value["closed"], value["unit"])
		tagVal = '{:f}'.format(convert_val)
		val = unicode("{:.3f}".format(float(tagVal)))
		lbl = system.util.translate('lbl_Closed',self.session.props.locale)
		instances.append({"value":value["closed"],"label": lbl + ': ' + val.rjust(10 + (6-len(val)),sp)})
		
	#add mid die stop position if > 0
	if not value["mid_die"] is None and value["mid_die"] > 0:
		convert_val = dv.indirect(value["mid_die"], value["unit"])
		tagVal = '{:f}'.format(convert_val)
		val = unicode("{:.3f}".format(float(tagVal)))
		lbl = system.util.translate('lbl_MidDieStop',self.session.props.locale)
		instances.append({"value":value["mid_die"],"label": lbl + ': ' + val.rjust(10 + (6-len(val)),sp)})
	
	tag = system.tag.read(self.view.custom.moving_platten_path + "/preset/homes_nominal").value
	lbl_Home = system.util.translate('lbl_Home',self.session.props.locale)		
	for i in range(value["nb"]):
		if tag[i]<=value["closed"]:
			convert_val = dv.indirect(tag[i], value["unit"])
			tagVal = '{:f}'.format(convert_val)
			val = unicode("{:.3f}".format(float(tagVal)))
			no = unicode(str(i+1))
			instances.append({"value":tag[i],"label": lbl_Home + no.rjust(3 + (2-len(no)),sp) + ': ' + val.rjust(10 + (6-len(val)),sp)})

	return instances

Each translation can be a single or multiple words

Is there any reason you can’t cache these translations in a script module?

For wich reason the gateway don’t translate dropdown items?