A while ago I had the need to translate labels, I was creating eMail bodys while using SysMailer and wanted to use different languages for different customers.
I found the class SysLabel and tried to use it. But the problem was that this didn´t work. I allways got the string in the language that was set up under Tools/Options.
print SysLabel::labelId2String2("@SYS54971", "en-us");
I usually have Swedish setup as language when I run Dynamics AX, and this is the result when running previous code.
If there are any english readers: “Aktiveringsdatum” is the Swedish translation of “Activation date“.
I traced the code and found out that the label converts to it’s string before it´s sent into the method labelId2String2. Since the input value wasn’t a labelId anymore, the method just returned the exact string that was sent in.
I found a solution to this problem by piecing together the labelname in the call to the method. It seems that the label didn’t convert to it’s string when I did it this way.
3 4 5 6 7 8 9 10 11 12 13 14 15
str labelStringSwedish; str labelStringEngUS; ; labelStringSwedish = SysLabel::labelId2String2("@"+"SYS54971", "en-us"); labelStringEngUS = SysLabel::labelId2String2("@"+"SYS54971", "sv"); print labelStringSwedish; print labelStringEngUS; pause;
Some of you might have noticed that I use the method labelId2String2, therefore there should also exist a method named labelId2String. This is true, the difference between this two methods is not a big one.
If a valid labelId is sent into either of these two methods, the label string is returned.