| title | Use Azure Translator in Foundry Tools with REST API |
|---|---|
| description | How to use prebuilt Azure AI translator in Fabric with REST API |
| ms.author | lagayhar |
| ms.reviewer | ruxu |
| ms.topic | how-to |
| ms.date | 02/28/2026 |
| ms.update-cycle | 180-days |
| ms.search.form | |
| ms.collection | ce-skilling-ai-copilot |
[!INCLUDE feature-preview]
Azure Translator in Foundry Tools is a Microsoft Foundry tool that enables you to perform language translation and other language-related operations.
This sample shows how to use the prebuilt Azure AI translator in Fabric with RESTful APIs to:
- Translate text
- Transliterate text
- Get supported languages
[!INCLUDE prerequisites]
- Create a new notebook.
- Attach your notebook to a lakehouse. On the left side of your notebook, select Add to add an existing lakehouse or create a new one.
Note
This article uses Microsoft Fabric's built-in prebuilt Foundry Tools, which handle authentication automatically. You don't need to obtain a separate Foundry Tools key - the authentication is managed through your Fabric workspace. For more information, see Prebuilt AI models in Fabric (preview).
The code samples in this article use libraries that are preinstalled in Microsoft Fabric notebooks:
- SynapseML: Preinstalled in Fabric notebooks for machine learning capabilities
synapse.ml.core- Core SynapseML functionalitysynapse.ml.fabric.service_discovery- Fabric service discovery utilitiessynapse.ml.fabric.token_utils- Authentication token utilitiessynapse.ml.services- Foundry Tools integration (includes Translate, Transliterate classes)
- PySpark: Available by default in Fabric Spark compute
pyspark.sql.functions- DataFrame transformation functions (col,flatten)
- Standard Python libraries: Built into Python runtime
json- JSON parsing and formattingrequests- HTTP client for REST API calls
# Get workload endpoints and access token
from synapse.ml.fabric.service_discovery import get_fabric_env_config
from synapse.ml.fabric.token_utils import TokenUtils
import json
import requests
fabric_env_config = get_fabric_env_config().fabric_env_config
auth_header = TokenUtils().get_openai_auth_header()
# Make a RESTful request to Foundry tool
prebuilt_AI_base_host = fabric_env_config.ml_workload_endpoint + "cognitive/texttranslation/"
print("Workload endpoint for Foundry tool: \n" + prebuilt_AI_base_host)
service_url = prebuilt_AI_base_host + "language/:analyze-text?api-version=2022-05-01"
print("Service URL: \n" + service_url)
auth_headers = {
"Authorization" : auth_header
}
def print_response(response):
print(f"HTTP {response.status_code}")
if response.status_code == 200:
try:
result = response.json()
print(json.dumps(result, indent=2, ensure_ascii=False))
except:
print(f"parse error {response.content}")
else:
print(f"error message: {response.content}")import synapse.ml.core
from synapse.ml.services import *
from pyspark.sql.functions import col, flattenText translation is the core operation of the Translator service.
service_url = prebuilt_AI_base_host + "translate?api-version=3.0&to=fr"
post_body = [{'Text':'Hello, friend.'}]
response = requests.post(service_url, json=post_body, headers=auth_headers)
# Output all information of the request process
print_response(response) HTTP 200
[
{
"detectedLanguage": {
"language": "en",
"score": 1.0
},
"translations": [
{
"text": "Bonjour cher ami.",
"to": "fr"
}
]
}
]
Text translation is the core operation of the Translator service.
df = spark.createDataFrame([
(["Hello, what is your name?", "Bye"],)
], ["text",])
translate = (Translate()
.setTextCol("text")
.setToLanguage(["zh-Hans", "fr"])
.setOutputCol("translation")
.setConcurrency(5))
result = translate.transform(df)\
.withColumn("translation", flatten(col("translation.translations")))\
.withColumn("translation", col("translation.text"))
display(result.select("text", "translation"))Transliteration converts a word or phrase from the script (alphabet) of one language to another, based on phonetic similarity.
service_url = prebuilt_AI_base_host + "transliterate?api-version=3.0&language=ja&fromScript=Jpan&toScript=Latn"
post_body = [
{"Text":"こんにちは"},
{"Text":"さようなら"}
]
response = requests.post(service_url, json=post_body, headers=auth_headers)
# Output all information of the request process
print_response(response) HTTP 200
[
{
"text": "Kon'nichiwa",
"script": "Latn"
},
{
"text": "sayonara",
"script": "Latn"
}
]
Transliteration converts a word or phrase from the script (alphabet) of one language to another, based on phonetic similarity.
transliterateDf = spark.createDataFrame([
(["こんにちは", "さようなら"],)
], ["text",])
transliterate = (Transliterate()
.setLanguage("ja")
.setFromScript("Jpan")
.setToScript("Latn")
.setTextCol("text")
.setOutputCol("result"))
result = transliterate.transform(transliterateDf)\
.withColumn("script", col("result.script"))
display(result.select("text", "script"))Returns a list of languages that Translator operations support.
service_url = prebuilt_AI_base_host + "languages?api-version=3.0"
response = requests.get(service_url, headers=auth_headers)
# Output all information of the request process
print_response(response)No steps for SynapseML in this section.