I HAVE PROBLEM: XLF FILES
When you have to implement an extension in a dozen of languages it is really painful to keep XLF files updated.
You probably noticed you waste a lot of time in editing these XLF file. That’s why I decided to implement an automated solution to save my time and keep me healthy.
The recipe to automate the translation of XLFF files in Business Central:
- A Business Central repository with translations in various languages
- A Visual Studio Code Extension for AL;
- An Azure Function;
- In this sample I am not using Azure Vault to store passwords and I just use settings.json, you should when in production environment 🙂
THE TRANSLATION REPOSITORY
I am using Business Central as a container itself for the translation table.
The business central extension source is available here:
In the extension you have: the table, two pages (a card list and a card page) and a query API page that is called by the Azure Function.
Once the extension is deployed in your online environment it will be accessible from the URL:
You can check if the query page is working with Insomia.
THE AZURE FUNCTION
The Azure Function works between the Visual Studio Extension and the Business Central API.
Sources available here: https://github.com/avalonit/AzBcTranslationManagement
The function accept two query parameters: the sentence to be translated and the the destination language and it returns back the translated sentence by querying Business Central API.
BusinessCentralConnector.cs is the class that manages calls to thr query API. It connects to API and get the requested translation by applying filtering to the API request.
Translations.cs is the class that represents Business Central Translations table for deserialising API data. I find useful https://app.quicktype.io/ to automatically convert Json returned from BC API to C# class. Just pay attention to DateTimeOffset field type that are not supported by JSON.
THE VISUAL STUDIO CODE EXTENSION
I used this Visual Studio Code Extension as a starting point for my customization:
This Vincent Nicolas extension is really awesome and automates the translation by using Azure Translator Text API. Unfortunately the translation for non latin languages is not that accurate and moreover some string have to be checked (eg: “Business Central” itself is translated in the local language and this causes funny results).
My fork of this extension instead of querying Azure Translator Text API it just query the previous described Azure Function to get the translation.
Soon I will publish the fork of BCTech project on github.
13th of April 2020