Pages

Friday, November 8, 2013

Translate text with Microsoft Translator from AX

I recently had a task involving the translation of a few thousand labels. To speed up the translation I figured that I would get a head start if I could somehow automate parts of the process. I found bits and pieces with which I could use the Bing or Microsoft Translator API for the task, and here is how to implement these in AX.

First of all, you need to sign up for the service. You do that from the data market on Windows Azure. You can translate up to 2000000 characters a month for free. Here is a link to sign up for the service: https://datamarket.azure.com/developer/applications/

The bits and pieces I could find for calling the service is .NET code, so I have implemented this part as a C# Project.

Here's the code for that part: http://sdrv.ms/HAOzcW. You need to add the Global class to the project, to get a proxy for it. It is used by the C# code.

With the C# Project in place, you can now do translation using this simple code:
// Sign up: https://datamarket.azure.com/developer/applications/
// Translator language codes: http://msdn.microsoft.com/en-us/library/hh456380.aspx
static void EGTranslateSample(Args _args)
{
    EGBingTranslation.Translator    translator;
    System.String                   clientId        = "YourClientId";
    System.String                   clientSecret    = "XYZ123";
    str                             translatedTxt;

    try
    {
        translator = new EGBingTranslation.Translator();

        // Create an access token
        translator.CreateToken(clientId, clientSecret);

        // Translate
        translatedTxt = translator.Translate("HvedeĂžl smager godt", "da", "en");
    }

    catch (Exception::CLRError)
    {
        error(AifUtil::getClrErrorMessage());
    }
    info (translatedTxt);
}

You get your Client Id and Client Secret when you sign up for the service on Azure.

Please note that the Microsoft translation cannot stand alone, unless you think you users are in need of some cheap laughs. You have to have a human to review the translations.

It seems that when you translate between two languages of which neither is English, that the translation is done using English as a "middleman". So for example a Danish to German translation is done first from Danish to English and then from English to German. In that process a lot of context can be lost and the result will not always be correct.

1 comment:

kurthatlevik said...

Small tip, BIG value. Thanks again Palle.