Is it possible to combine a key and literal constant?

I want to use the translation function for parts of the text in a label so I dont have to translate the same word more than once.

For example.
I want to show 4 texts to show the status of Vacuum 1 - 4, but I do not want to have 4 translation keys. It does not seem to be possible to use !!Vacuum!! 1 and so on.

Hi, you can use classic approach to build custom strings. Like for example: const stringTest = ${string1} ${string2}; Or you can just add two strings like const stringTest = translatedString + String(index);

Hi,

I don’t think you have fully understood my question.
I know how to combine strings in javascript. What I want is to do it without breaking the translation function in AppStudio.

I have been trying to combine a translation key with additional text, but so far I have not been able to get the key to translate when it is concatenated with other strings.

If there is a supported way to combine a !!key!! with other values (for example, an index or suffix), I would really appreciate seeing a concrete code example that demonstrates how this should be done.

For reference, the following does not work in my case, as !!vacuum!! is not replaced with its translated value:


const stringTest = "!!vacuum!!" + String(index);

Thank you in advance for any clarification or guidance you can provide.

Hi, do you want to use code to parse the current multilingual entries in AppStudio?

You’ve noticed that App Studio uses !! + key name + !! as the multilingual key, but if you want to dynamically retrieve its value, you can use TComponents.Component_A.t(‘key name’) to get its value.

like:

const stringTest = TComponents.Component_A.t(‘vacuum’) + String(index);

AppStudio is about to release a new version. In the new version, you can get help by referring to the API Documentation. Hope this helps :laughing:.

TComponents.Component_A.html#.t

2 Likes

Thank you! That is exactly what I’m looking for.

What did I miss here? It doesn’t work and then it does?

The response from yitong answered my question, it popped to the top as is was marked best answer

Oh, I see. Thanks for clarifying that. :+1: