Prompt
How do I add translation to my app with a REST API?
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
To add translation to your app using a REST API, the usual pattern is:
- Store source text in your app
- Send text + target language to a translation API
- Cache/store the translated result
- Render the translated text in the UI
1) Pick a translation API
Common options:
- Google Cloud Translation API
- DeepL API
- Microsoft Translator Text API
- AWS Translate
- Or a self-hosted/open-source service if needed
Most of these expose simple REST endpoints like:
POST /translate
with a JSON body containing:
- the text to translate
- source language
- target language
2) Example request
A typical REST call looks like this:
POST https://api.example.com/translate
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY
{
"text": "Hello, world!",
"source": "en",
"target": "es"
}
Example response:
{
"translatedText": "¡Hola, mundo!"
}
3) Implement it in your app
Frontend flow
- User selects a language
- App calls your backend or the translation API
- UI updates with translated strings
Recommended: call translation from your backend
Don’t put API keys in the frontend. Instead:
- Frontend → your backend
- Backend → translation provider
- Backend → frontend with translated text
4) Example backend endpoint
Example in Node.js/Express:
import express from "express";
const app = express();
app.use(express.json());
app.post("/api/translate", async (req, res) => {
const { text, target } = req.body;
const response = await fetch("https://api.example.com/translate", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${process.env.TRANSLATION_API_KEY}`
},
body: JSON.stringify({
text,
source: "auto",
target
})
});
const data = await response.json();
res.json({ translatedText: data.translatedText });
});
app.listen(3000);
5) Cache translations
If the same text is translated often, cache it to reduce cost and latency.
Cache key example:
translation:en:es:Hello, world!
Store in:
- Redis
- database
- memory cache
6) Handle localization, not just translation
For a full multilingual app, you often need:
- UI strings in multiple languages
- date/time formatting
- number/currency formatting
- pluralization rules
- right-to-left support
So translation APIs are great for:
- user-generated content
- dynamic text
- quick multilingual support
But for app UI, it’s usually better to use localization files such as:
- JSON translation files
- i18next
- React Intl
- Vue I18n
- .NET resource files
- Android/iOS localization systems
7) Best practices
- Keep API keys on the server
- Cache aggressively
- Detect language automatically when useful
- Batch requests if the API supports it
- Handle errors and rate limits
- Don’t translate brand names or code-like strings blindly
- Review machine translations for important content
8) Simple architecture
User selects language
↓
Frontend calls your backend
↓
Backend calls translation API
↓
Translation API returns translated text
↓
Backend caches and returns result
↓
Frontend displays translated text
If you want, I can give you:
- a complete example in Node.js, Python, or PHP
- an example using Google Translate / DeepL / Microsoft Translator
- or a full i18n setup for your frontend framework