Create your own Visual Studio Code Extension to Manage XLF Business Central Translation File

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

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:

https://github.com/avalonit/ExBcTranslationManagement

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:

https://api.businesscentral.dynamics.com/v2.0/your_id/Sandbox/api/ALV/TransMgt/v2.0/companies(your_company_id)/Translations

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:

https://github.com/microsoft/BCTech

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).

https://community.dynamics.com/business/b/businesscentraldevitpro/posts/translate-your-extension-automatically-with-azure-translator-text

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.

LAST UPDATE

13th of April 2020

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s