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.
Aktiveringsdatum
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; |
Result:
Aktiveringsdatum
Activation date
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.
Last 5 posts in Development
- No valid document identified from the entity key - April 9th, 2010
- Using Regular Expressions in Dynamics AX - October 2nd, 2009
- Create class and methods in x++ - December 22nd, 2008
- Simple field lookup in form - October 13th, 2008
- Get your Intercompany CustAccount - September 29th, 2008
You need to pass the label to the method labelId2String using the built in function literalstr:
labelStringSwedish = SysLabel::labelId2String2(literalstr(“@SYS54971”), “en-us”);