In some business scenarios, you may need to display data in multiple languages dynamically on forms or reports in Microsoft Dynamics 365 Finance and Operations. While D365FO supports label-based translations, these are statically defined and managed through configurations. However, if the content is dynamic (like customer-entered data), label translations won’t suffice.
In such cases, you can use code to call external translation services—such as Google Translate API—at runtime. Below is a simple X++ example that demonstrates how to translate text between two languages (e.g., English to Hindi) using a web service.
✅ Use Case
Translate a string from English (en
) to Hindi (hi
) during runtime using a direct HTTP call to the Google Translate API.
๐ป X++ Code Example
str inputStr = "Uma Mahesh";
str url = strFmt(
"hi", // Target language
inputStr
);
System.Net.WebClient webClient = new System.Net.WebClient();
// Parse translated text (first occurrence between double quotes)
len = downloadedString.get_Length();
startPos = strScan(downloadedString, '"', 1, len) + 1;
๐ง Key Points
-
URL Format: The URL is built using source and target language codes (
sl
,tl
) and the text to translate (q
). -
System.Net.WebClient: We use .NET interop to make the web request and handle the UTF-8 encoded response.
-
Simple JSON Parsing: The API response is a nested JSON array. For this basic use case, we extract the first quoted string after parsing.
⚠️ Important Notes
-
This example uses the free version of the Google Translate API, which is undocumented and may be rate-limited. For production-grade applications, consider using the official Google Cloud Translation API with proper authentication.
-
For large-scale or real-time translation needs, also consider caching frequently translated values to reduce API calls.
✅ When to Use
-
You need to display dynamic content in multiple languages on a report or form.
-
Label-based translation is not feasible.
-
The translated content is runtime-dependent and needs external translation support.