Translate a String containing Variables

Hello, I am working on setting up translations from English to Spanish in several Ignition programs. Any non-variable items I have translating well via changing the session locale and setting up definitions in the translation manager. I have ran into a roadblock translating strings where a variable is included. My example is a property binding with expression transform:
"Time on Mission is " + {value} + " Seconds"
What is best way to create a translation for instances like this? One of the only ideas have so far would be to layer another script transform that checks against the session locale and returns a hard coded-pretranslated string. There has to be better way.

The other translation hurtle I have encounter is when using a table component. Each row within the table I am binding to returns a string. In a different part of my program I pull the same string from the same query but use a script transform to extract one of the specific values that is then displayed in a label component. The translation works great on that sting when in the label, but when viewed as part of the complete table the translation does not apply. -Is there a way to easily/dynamically translate within a polling table?

Thanks for any help and incite!

IIRC, translatable strings can have printf-style formatting placeholders. To use them, you must call for translation before applying the value to the format. Each translation would place the format placeholder in the right spot for that language.

The translate function doesn't seem to be able to specify ranges yet. I also want to use different translations for the same text in different places. There is not a one-to-one correspondence between words in different languages.

Not sure what you mean. The translation system is extremely simple: You give it a key string and it gives the translation, if it exists. You must do this before you inject the variable parts of the string. You arrange for placeholders in the key and translations in the right place(s) for the languages involved.

You will need to manually invoke translation within the table's script transform.

What I want to say is that the same vocabulary can only be translated into the same word. But in tables and in titles (and elsewhere), the same vocabulary should be translated into different words. For example, time, sometimes should be translated as "length of time", and other times should be translated as "number of times".
The translation system is too simple. :sweat_smile:

The translation key does not have to be single word. It can be a phrase. Specifically to support your case.

Please forgive me for having to express my opinion again. I understand what you mean and try to use the translation feature as much as possible. But the reality is that sometimes there is only one word, and it needs to be translated into different content on different occasions. Sometimes, the same phrase also needs different content to correspond. I'm not a native English speaker, and in my projects, sometimes I have to give up translating something because the text needs to be translated into different things in different places, which can't be done. (if a translation is specified, it will be ambiguous or incomprehensible in some places)

Thanks for the quick reply.
So in my example: "Time on Mission is " + {value} + " Seconds"

Is the correct way to do this:
system.util.translate("Time on Mission is")
"Time on Mission is " + {value} + " Seconds"

text = ../Mission Time Display.props.text
translation = system.util.translate(text)
../Mission Time Display.props.txt = translation

Adapting above from the manual to my situation, but I can't imagine that's quite correct.

I understand (I happen to be bilingual, fwiw). That is why phrases are supported. Don't even try to provide translations for ambiguous words.

It would be nice if the translator had namespaces.

1 Like

No, the correct way is something like this:

formatter = system.util.translate("Time on Mission is %d Seconds")
output = formatter % value

Not having luck with that yet, but its much closer than I had been. Would would I put in the translation manager for something like this? It can not contain any place holder values correct?

No, the translation manager does allow placeholders. Wouldn't work this way without them.

You can prefix your keys with something, effectively creating name spaces.
The key doesn't have to be the text that will be displayed.


key          | english    | french
title_hello  | Hello      | Bonjour
text_hello   | Hey there  | Salut

Alright I have to ask- What should I be defining for the place holder value in the translation manager? I'm not seeing anything helpful for this in the manual.

I have revised my bring on the label to a script transform instead of the expression. Now it is-
def transform(self, value, quality, timestamp):
formatter = system.util.translate("Time on Mission is %d Seconds")
return formatter % value

In the translation manager I have all of the Ignore settings checked, and have attempted several different place holder characters with no success. Something isn't clicking for me yet.
Thank you for your help!

Supply the complete string, exactly as you are supplying it to system.util.translate(), including placeholder.

1 Like

My findings are that no matter what I had to specify the language to translate to with the system.util.translate function. Attached are screen shots of what I have that is now working. It would never pull off of the session locale for some reason, even though all of the other translations are. This is after trying several different formatting methods for the locale as well.
For now, this works.

A slightly contrived example of

  • the translation table "key" is not English or the text in the default language. It is a key and can have whatever context or namespace you want
  • the order of the words is different in different languages and should be different in the translated phrase
  • position based argument replacement is unnecessary and can (should) be avoided
  • even the same base language can be different

The translation table

Configuration for the dropdown for units

Binding for the text value of the label

Custom properties for the label

English locale result

en-US locale result

eo locale result