Localization with Azure Cognitive Services
If you need to translate your website to different languages, there's a useful service called Translator that you can find in Azure Cognitive Services. This is where you'll find all of Azure's other AI services too. The Translator service provides a REST API that's straightforward to use for translating all sorts of text into any language. In this article, I'll explain how we utilize this service in a client's solution.
The customer's website displays various measurement data for facilities. While all the content is in Swedish, it also supports 4 other languages. It consists of both static texts, such as headings and labels, and dynamic texts in the form of questions and answers (=measured data) such as "Entrance / Outer door / Surface in front of door / Length: 145 cm".
In the past, the customer used a translation agency to translate all the texts on their website. However, this solution was both expensive and time-consuming, and needed to be redone frequently, especially for dynamic content that was regularly updated.
The website is a single page application built on Vue.js. It retrieves data via Azure API. The backend is a regular ASP.NET Web API.
Using the Translator service eliminates the need for resource files and human translation. Translator charges per character, which can add up quickly. To keep costs under control, we built a layer on top of it that saves the translations. This was easy to do because we were already using the Azure API.
Initially, we check if we have already translated the text for the chosen language. If we have, we simply return it. If we haven't translated the text before, we use the Translator service to translate it and then store the translation in our database.
Since the dynamic texts contain measurement data, there can potentially be many variations of the same text, for example, "Width: 60 cm" and "Width: 80 cm". To avoid it being treated as different texts, we mask all numeric fields, and the text becomes "Width:  cm".
Example Swedish to German request:
Response to client in German
Translations in the database
FromText is the masked original text in Swedish and ToText is the translation, which is also masked. FromHash is a hash of FromText and is used to index the table together with Language.
If you are not satisfied with the translation, you can simply go into the database and change the ToText field.
What does it cost?
There is a unique page for each facility in the system. Currently, there are 8,200 pages that can be translated into English, German, Spanish, or Finnish. Because much of the content that is being translated has already been saved, we are able to keep the cost below 10 SEK per month. The total cost so far is 250 SEK. Azure charges $10 per 1 million characters.
The customer is currently satisfied with the translations provided by the Translator service. However, in the future, we might need to develop an admin tool to modify translations in the database. We are also considering building a separate service to use in other solutions.
When it comes to Azure services, it's always wise to keep an eye on costs or, even better, use budget alerts to stay on top of your spending. Otherwise, you might be in for an unpleasant surprise. However, in our case, it was a no-brainer. Not only was it cheap, but it was also easy to implement.