Skip to navigation

Translation

Translate text and identify its language, across 232 languages.
View as Markdown

Translating

GET /v1/translation/translate?text={text}&to={code}
const result = await aegis.translation.translate({
text: 'good morning',
to: 'fr',
})
result.translatedText // 'bonjour'
result.originalText
result.sourceLanguage // 'en'
result.targetLanguage // 'fr'

from is optional and defaults to auto, so Aegis detects the source language itself. Pass it when you already know it:

await aegis.translation.translate({ text: 'bonjour', from: 'fr', to: 'en' })

An empty text or an unknown to answers 400.

Detecting

GET /v1/translation/detect?text={text}
const result = await aegis.translation.detect({ text: 'bonjour' })
result.language // 'fr'

When detection cannot settle on a language, it returns unknown rather than failing.

Listing languages

GET /v1/translation/languages
const { languages } = await aegis.translation.languages()
languages // [{ code: 'en', name: 'English' }, ...] — 232 of them

Use code for to and from. This is a static list served from the cheap class, so fetching it on startup costs you almost nothing.

Cost

Translate and detect are in the fetch class because they call an upstream service; the language list is cheap. See rate limits.