Check out the latest Business Central updates!Learn about the key capabilities and features of Dynamics 365 Business Central and experience some of the new features.
Overview | Guided Tour | Free Trial
2022 Release Wave 1 PlanDynamics 365 release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.
2022 release wave 1 plan
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Community | FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Upcoming TechTalks | All TechTalks
Hello, Bonjour, Ciao, こんにちは, …
If you seek international growth for your solution and look for reaching markets across the world, you will be faced with the need to translate your software. Business Central AL extensions already allow you to package your translation together with your extension. In this blog post, I will show how to write a Visual Studio Code extension, which can automatically translate your Business Central Extension using Azure translation services.
XLIFF stands for XML Localization Interchange File Format. It is an XML-based format that is widely used in the translation world. Many tools used by translators understand this format and XLIFF files usually have the .xlf extension.
The format itself is rather self-explanatory. Strings to be translated are listed with a ‘source’ XML tag and the corresponding translation is marked with a ‘target’ tag. At the top of the file, a ‘file’ tag has attributes to specify the source and target language. Quite straight forward indeed.
Auto creating the XLIFF file
The first step is to have all the strings from your extension that need to be translated, gathered in such a file. You can of course always author the file by hand, but that is rather tedious and error prone. Fortunately, the Visual Studio Code AL environment can generate this file automatically for you. Microsoft documentation describes here how to do that.
All you need to do is to add the following entry in the app.json file of your extension:
Rebuild and ‘voilà’, you now have a new folder called ‘Translations’ which contains an .xlf file with all the strings from your extension:
Now the next step is important. This file gets regenerated each time you build, so you should not work directly with this file to enter your translations, as those will end up being overwritten at each build.
Instead, you should make a copy of this file for each of the languages that you want to support. A good practice is to name the files with the following scheme ..xlf like this.
Then you need to edit the target-language attribute to specify the language for each file:
At this point, you could proceed by manually entering the translated strings in the files, but let’s take this to the next level and use Azure cognitive translation services.
The Azure Translator Text API
The Translator Text API, is an Azure cognitive service that leverages advanced neural network technology to deliver high-quality AI powered translations. This could be the subject of an entire blog series, so I will not digress here but if you want to learn more you can click on this link.
In this blog post, we will be using this service to translate the XLIFF files, so first thing is to deploy a translation service in you Azure subscription.
In the Azure portal, click on ‘Create a resource’ and search for ‘Translator Text’ and then click create.
Fill out the various information required and click ‘Create’ again. After a while, the service gets deployed, then click on it and go to ‘Keys’. There you can see the API keys that you will need to call the service:
Copy one of the key values, we will need it for later.
Now that the service is created, you can translate strings by issuing REST API calls as documented here.
So, let’s put this all together in a nice little VS Code extension, that can automate all that for you.
Just to avoid the confusion, what I am about to talk about, is how to write a VS Code extension, not an AL extension. This extension, once installed in your VS Code editor, will translate any XLIFF file in your workspace. Actually, it does not even have to be an AL extension and you can use this tool to translate any XLIFF file in any VS Code project.
If you are not familiar with VS Code extension development, there are lots of resources and samples online to get you started.
The full source code for the XLIFF extension is available on GitHub here, so go ahead and download it. This VS Code extension is written in Typescript, so get ready, I am going to walk you through it.
Upon activation, the extension registers a command binding to call the translate() method on the XLIFFTranslator class where all the magic happens.
In order to call the Translator Text service, the API key is needed. The getTranslationServiceApiKey() tries to retrieve the key from the settings and if it does not find it, it prompts the user for it:
Then the translate() method iterates over the *.xlf files in the workspace and calls the translateFile() method for each of them:
After reading the *.xlf file and parsing it using the XML DOM parser, the translateFile()method finds out what the target language is by looking at the target-language attribute of the file element, so now we know which language the file needs to be translated to.
The next thing is to gather all the source strings in an appropriate format. The Translator Text API gets invoked via a REST call and it expects a list of strings to translate in the body of the call, in a JSON format looking like this:
So, let’s extract the strings from the DOM and create the JSON list in that format:
The URL of the Translator Text service has the following format:
So now that we have all the pieces, calling the service is rather straight forward:
Now, all we have left to do is to parse this JSON response and put back the translated strings in the .xlf file. This is also quite easy using again a bit of DOM manipulation:
Finally, we serialize back the DOM, save it and show the document in VS Code:
That’s it! Now let’s try it out.
To see the code in action, press F5 to build and deploy the VS Code extension to a VS Code development host environment. From there, load you favorite AL extension that you want to translate and enable the “TranslationFile” feature to autogenerate the XLIFF file and create a copy for each language as described earlier.
Then hit Ctrl+Shift+P to get the command drop-down and look for the “Translate XLIFF files” command that comes from your freshly deployed new translation extension.
Run the command and (almost) magically the translated strings are added to the translation file:
To really see it all come together, you can now deploy your AL extension to your Business Central environment, go to your settings and change the language to one of the languages that you just translated your extension to:
Download the code and take it to the next level
The complete sample code is available here in the BCTech GitHub repository. It includes a test AL extension with a single page containing some random strings to be translated.
I will conclude with a few words about machine-generated translation. You might find the quality of the translations is not good enough for you and your users, especially if your domain is very specific, which is often the case with ERP verticals. If you use the Translator Text service as I demonstrated in this post, you will get generic translations, albeit with a powerful backend neural network. But the Azure translation services have a lot more to offer. The essence of machine learning in general and neural networks, in particular, is that models can be trained to learn and become better at their tasks. If you already have high quality translations which have been performed by humans, you can use those to train a model which will learn about your domain. The result will be even higher quality translations, tailored to your business. This could be the subject of an entire different blog post, but in the meantime you might want to take a look at Azure Custom Translators. The cool thing about this, is that the API for custom translators is the same, so our XLIFF translator will still work, just with better translations!
Is it possible to get the translation of the base application to use them as training data for the service? I guess that would allow us to translate our developments in the same fashion as the base app.
@Daniel, at this point Microsoft does not offer a tailored translation service for Business Central, but as I describe in the post, you can potentially create your own using a custom translator based trained with your own translations.
Is there are custom translator for Business Central? The German Translation Result is not that great.
Business Applications communities