Showing posts with label language. Show all posts
Showing posts with label language. Show all posts

Wednesday, June 30, 2010

How to translate an enumerated text

You can easily convert an enumerated text to a string value with the enum2str function. Example:

info(enum2str(SalesType::Sales));

But this will get you the label in the default language. What about other languages?
The following small job will get you the translated label info for all values of a specified enum, with a specified language.

static void Enum2Label(Args _args)
{   DictEnum                dictEnum;

int                     valueIndex;
LanguageId              languageId='de';

int                     enumId=enumNum(SalesType);
str                     labelId;
;

dictEnum = new DictEnum(enumId);
if (dictEnum)
{
for (valueIndex = 0 ; valueIndex < dictEnum.values(); valueIndex++)
{
labelId = dictEnum.index2LabelId(valueIndex);
info(SysLabel::labelId2String2(labelId, languageId));
}
}
}
Result: Journal Angebot Dauerauftrag Auftrag Zurückgegebener Auftrag Abrufauftrag Artikelbedarf

Similar code as above is used in the SRS classes in Ax. They make it possible for humans to understand and interpret the different enum values, as they merely are integer values in the database and as such for third party applications.

Wednesday, March 31, 2010

How to set the language used on forms and menus

Ax is available in many languages (approx 45 I believe). It comes in Spanish, English, Polish, German, Arabic, ... thereby underlining it's global presence.

In reports, you can use any supported language, weather you bought a license key for it or not.

This policy makes senses, as your company, your customers or vendors may not speak the same language. When you exchange documents (for example an order), you need to understand its contents.

I had a post about how to change the language in a report a while back.

Another thing is the user interface, the client you do your every day work in. You can set the language used in forms and menus with the user options. You can find them under Administration - Users - User Options.

In this setting, you are limited to the languages you bought a license for.

Now you can set the language used in the user interface by code as well. And strangely enough, this way you are not limited to the set of licensed languages (this applies to MS Dynamics Ax 2009 SP1).

You can set the language like this

infolog.language('en-us');

Play around with it and see what's available!



Friday, February 26, 2010

How to get a label in a different language

The tasks seems easy enough: How the get a specific label in a different language.
(Remember my post, 'How to set the language used on a report')

Now we only need to retrieve the text for one label id, in any given language. Going through the help files of Ax, you come across this class SysLabel. It contains the labelid2String method.

Example:

info(SysLabel::labelId2String2("@SYS87980","de"));

Only... This does not work like that. Didn't work in Ax 4.0, doesn't work in Ax 2009. You always get the label back in the language that's been setup for the current user, no matter which language you specify in the call to this function.

Luckily, there's an easy workaround, tricking Ax: Split up your label id. Like this:

info(SysLabel::labelId2String2("@"+"SYS87980","de"));

Credits: With thanx to this blog for this simple but yet very effective solution.

Edit: SysDictCoder pointed out a nicer solution in the comments, by using literalstr.

info(SysLabel::labelId2String2(literalstr("@SYS87980"),"de"));

Monday, December 21, 2009

How to set the language used on a report

When printing a report, Ax sets the used language automatically based on the user's settings. The selection of available languages for the client interface depends on the installed language license keys.

But sometimes, it may be necessary to change the default settings for reports. With reports needed for external use for example. Like invoices and packings slips you send to your customers. These documents require to be made up in the language of your customer. Ax is designed with this scenario in mind.

The language to use in the report can be set with following command:

element.design().languageID();

So for example:

element.design().languageID('en-us');


Place the code in the init method of your report, or in the fetch method.


You can use this in your own custom reports as well, with no limitation regarding the language license keys you bought. All you need are the appropriate label files. (Otherwise you get error messages like 'label @SYS123 not found in language xyz'.)

Got some time to spare? It can be fun to see how your documents look like in he - Hebrew, with its right to left printing.