Language Translation in Perspective - translating sentences with dynamic labels/texts

Hi,

I'm trying to translate my perspective project from English to Spanish and I'm kind of stuck on how to translate some sentences with dynamic texts/popup labels.

For eg : "Do you want to move the [item] from [HELD] state to [RUNNING] ?"

For the above sentence, words inside [square brackets] are dynamic, so how can I translate the rest of the sentence keeping the dynamic words intact?

1 Like

You can first generate your text and then perform the translation.
https://docs.inductiveautomation.com/display/DOC81/system.util.translate

we have a simular use case with the powerchart, and we need to translate all combination....

I suppose you need to post a feature request:

If I want to translate all possible inputs, I have to create translation for :

Last 1 hours
Last 2 hours

Last 8 hours

Assuming that your dropdown text is being created with an expression function, you can combine the stringFormat() and translate() expressions to do the work for you.

Something along the lines of
stringFormat(translate("Last %d hours"), hours))

This is for the built-in popup of the powerchart...I don't have any control on bindings

Hmm... I checked with the Perspective team and they are telling me that component should be translating since 8.1.3. You would need to have a translation in place for the word "Last" and one in place for the units ('hour', 'hours', 'minute', 'minutes', 'second', 'seconds')

Ignition 8.1.27

Seems not working for me. Last 5 days is only translated if I add the Full term...

I have to replaced date selection and conditional filtering with simpler components. Translators cannot be relied upon on these complex components.

1 Like

His example has multiple variables to substitute, and word order is often different in other language. This makes position based substitution unwieldy - either you have to write your own string interpolation routines or the translated phrases are pidgin rather than native.

Are there any plans to implement string interpolation (name based substitution rather than ordinal)? That would eliminate a lot of opportunities for error, and many other development environments have implemented it. Ignition uses name based lookup in many other places as well.

You can use named parameters for the string.format function.
I can't think of a proper example right now, so I'll be very abstract, but let's say you have this as your translation strings:
en:

  • s: "something {foo} other thing {bar}"
  • foo: "the_foo"
  • bar: "the_bar"

fr:

  • s: "quelque chose {bar} autre chose {foo}"
  • foo: "le_foo"
  • bar: "le_bar"
s = translate(s)
foo = translate(foo)
bar = translate(bar)
return s.format(foo=foo, bar=bar)

Didn't try, but I believe this should return either
"something the_foo other thing the_bar"
or "quelque chose le_bar autre chose le_foo"

edit: I just tried and it works:

image

2 Likes

Cool! Thanks. I didn't get that from the IU materials.

We are often having similar use cases for alarm texts. If there is a device multiple times in a machine and the device is having multiple fault messages, it creates a huge variation of messages and translations. The scripting approach doesn’t really work for us because we would have these issues in lots of places and would need a more generic solution.

For example: machine with 20 frequency converters. Every converter has 30 different fault messages, it means 600 different language keys.

I think something like the following would be very beneficial to the translation system of Ignition.

It would need to have 2 Features:
----------------------------------------------------------------------------------------------------------------------------------

  • Nesting of Translations

the opportunity to inject one translation into another by a Variable, that is coming from a string variable. This String also represents a language key that gets injected in the place where it is specified in the Translation.

Example:

Key : FaultDevice @'VarReason'@

English Text: The device is faulted because {Var_Reason}

Key: Reason1

English Text: the Voltage is too low

PLC variable: Var_Reason = Reason1

Result : The device is faulted because the voltage is too low

----------------------------------------------------------------------------------------------------------------------------------

  • Injection of variables in Translations

Insert a variable value in a translation, to give additional Information about a fault.

Example: Temperature to high. Setpoint: @Var_Setpoint@°C Actual: @Var_actual Temperature@°C

PLC variable s: Var_Setpoint = 200°C

Var_actual Temperature =250°C

Result: Temperature to high. Setpoint: 200°C Actual: 250°C

We already talked about this with @Marco_Keller from our local Ignition supplier. I think something like this would benefit everyone here who has such issues.

1 Like

The nesting request is not possible, I think. (More not recursion-safe than not possible, but unlikely to be safely solvable.)

Variable substitution is possible already, using printf-style placeholders. At least, from an SDK module. You might want to write a simple add-on to expose that functionality to scripts and expressions.

That is what was being discussed here: