I found a solution at the library VisuElems. It actually works. This is the function:
FUNCTION F_GetText : STRING
VAR_INPUT
sTextList : STRING;
sId : STRING;
END_VAR
sTextList := CONCAT('Port_851.',sTextList);
F_GetText := VisuElems.CmpDynamicText.DynamicTextGetText(
pstTextList:= ADR(sTextList),
pstTextIndex:= ADR(sId)
)^;
And at the program we call it like this:
sTest := F_GetText(sId := 'maschine', sTextList := 'TL_Visu');
You might want the default translation. Lets say the default translation is german and we have the constant:
DE: STRING(8) := 'default';
The function is:
sTextList := CONCAT('Port_851.',sTextList);
IF VisuElems.CURRENTLANGUAGE = DE THEN
F_GetText := VisuElems.CmpDynamicText.DynamicTextGetDefaultText(
pstTextList:= ADR(sTextList),
pstTextIndex:= ADR(sId)
)^;
ELSE
F_GetText := VisuElems.CmpDynamicText.DynamicTextGetText(
pstTextList:= ADR(sTextList),
pstTextIndex:= ADR(sId)
)^;
END_IF
I got with this solution from this german webpage:
https://www.sps-forum.de/archive/index.php/t-88760.html