Build a Multilingual App with AI Translation in 10 Minutes
Alex Chen
Developer Advocate
Going Global with AI Translation
Your app works great in English, but 75% of internet users don't speak English as their first language. Adding multilingual support used to mean hiring translators or integrating expensive localization platforms. With an AI translation API, you can support 100+ languages in minutes.
The Translation Function
const API_URL = "https://instantapis.net/api/v1/generate";
const API_KEY = "your_api_key_here";
async function translate(text, targetLanguage, sourceLanguage = "auto") {
const response = await fetch(API_URL, {
method: "POST",
headers: {
"Authorization": Bearer ${API_KEY},
"Content-Type": "application/json",
},
body: JSON.stringify({
task: "translate",
input: text,
options: {
target_language: targetLanguage,
source_language: sourceLanguage,
},
}),
});
return response.json();
}
Translating UI Strings
const uiStrings = {
welcome: "Welcome to our platform",
signUp: "Create your free account",
dashboard: "Go to Dashboard",
pricing: "View Pricing Plans",
};
async function translateUI(strings, targetLang) {
const translated = {};
for (const [key, value] of Object.entries(strings)) {
const result = await translate(value, targetLang);
if (result.success) {
translated[key] = result.data;
}
}
return translated;
}
// Generate Spanish translations
const spanishUI = await translateUI(uiStrings, "es");
// { welcome: "Bienvenido a nuestra plataforma", ... }
// Generate Japanese translations
const japaneseUI = await translateUI(uiStrings, "ja");
Python: Translate Content Files
import requests
import json
API_URL = "https://instantapis.net/api/v1/generate"
API_KEY = "your_api_key_here"
def translate_text(text, target_lang):
response = requests.post(API_URL, json={
"task": "translate",
"input": text,
"options": {"target_language": target_lang},
}, headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
})
data = response.json()
return data["data"] if data.get("success") else text
# Translate a JSON locale file
with open("en.json") as f:
english = json.load(f)
languages = ["es", "fr", "de", "ja", "ko", "pt", "zh"]
for lang in languages:
translated = {}
for key, value in english.items():
translated[key] = translate_text(value, lang)
with open(f"{lang}.json", "w") as f:
json.dump(translated, f, ensure_ascii=False, indent=2)
print(f"Generated {lang}.json")
Real-Time Translation Middleware
For Express.js apps, add translation as middleware:
function translationMiddleware(defaultLang = "en") {
return async (req, res, next) => {
const targetLang = req.headers["accept-language"]?.split(",")[0] || defaultLang;
if (targetLang === defaultLang) {
return next();
}
// Override res.json to translate response content
const originalJson = res.json.bind(res);
res.json = async (body) => {
if (body.message && typeof body.message === "string") {
const translated = await translate(body.message, targetLang);
if (translated.success) {
body.message = translated.data;
}
}
return originalJson(body);
};
next();
};
}
app.use(translationMiddleware("en"));
Why AI Translation Beats Traditional APIs
Unlike word-for-word translation services, AI-powered translation understands:
- Context: "bank" translates differently in finance vs. geography
- Idioms: "break a leg" becomes the equivalent expression, not a literal translation
- Tone: Formal vs. casual register is preserved
- Technical terms: Domain-specific vocabulary is handled correctly
Supported Languages
InstantAPI supports 100+ languages including: Spanish, French, German, Japanese, Korean, Chinese, Portuguese, Arabic, Hindi, Russian, Italian, Dutch, and many more.
Cost
At $0.50 per translation call, translating your app into 10 languages costs just $5 per string. A typical app with 200 UI strings across 10 languages = 2,000 calls = $1,000 — a one-time cost that would take a human translator weeks and cost 10x more.
Start translating today — 10 free credits included.Ready to try InstantAPI?
Sign up today and get 10 free credits to explore all 6 AI capabilities. No credit card required.
Get 10 Free Credits