Get label string in different languages

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.

  • labelId2String – Returns an empty string if an invalid labelId is used in the method.
  • labelId2String2 – Returns the string that was sent into the method if it isn’t a valid labelId.
  • If a valid labelId is sent into either of these two methods, the label string is returned.

    Last 5 posts in Development

    One thought on “Get label string in different languages

    1. You need to pass the label to the method labelId2String using the built in function literalstr:
      labelStringSwedish = SysLabel::labelId2String2(literalstr(“@SYS54971”), “en-us”);

    Leave a Reply

    Your email address will not be published. Required fields are marked *