> ## Documentation Index
> Fetch the complete documentation index at: https://docs.credentialsportal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Translation

> Translate text into 70+ languages and list supported languages via the API.

The translation endpoints let you translate text using AI (powered by Meta's M2M-100 model via Workers AI). Translations are cached to avoid redundant processing.

## Translate text

```bash theme={null}
POST /api/translate
```

Translates one or more strings into a target language.

**Request body:**

<ParamField body="text" type="string">
  A single string to translate. Use `texts` instead for batch mode.
</ParamField>

<ParamField body="texts" type="array">
  An array of strings to translate. Maximum 200 strings per request. Use this for batch mode instead of `text`.
</ParamField>

<ParamField body="to" type="string" required>
  BCP 47 language code of the target language (e.g., `"es"`, `"fr"`, `"pt"`)
</ParamField>

<ParamField body="from" type="string">
  BCP 47 language code of the source language. Defaults to `"en"` if omitted.
</ParamField>

**Example — translate a single string:**

```bash theme={null}
curl -X POST https://app.credentialsportal.com/api/translate \
  -H "Authorization: Bearer ck_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Welcome to Credentials Portal",
    "to": "es"
  }'
```

**Response:**

```json theme={null}
{
  "translated": "Bienvenido al Portal de Credenciales",
  "from": "en",
  "to": "es"
}
```

**Example — translate multiple strings:**

```bash theme={null}
curl -X POST https://app.credentialsportal.com/api/translate \
  -H "Authorization: Bearer ck_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "texts": ["Hello", "Goodbye", "Thank you"],
    "to": "fr"
  }'
```

**Response:**

```json theme={null}
{
  "translated": ["Bonjour", "Au revoir", "Merci"],
  "from": "en",
  "to": "fr"
}
```

***

## List supported languages

```bash theme={null}
GET /api/translate/languages
```

Returns all supported languages with their BCP 47 codes and display names (in both English and the native script).

**Example:**

```bash theme={null}
curl https://app.credentialsportal.com/api/translate/languages \
  -H "Authorization: Bearer ck_your_api_key"
```

**Response:**

```json theme={null}
{
  "languages": {
    "en": ["English", "English"],
    "es": ["Spanish", "Español"],
    "fr": ["French", "Français"],
    "pt": ["Portuguese", "Português"],
    "de": ["German", "Deutsch"],
    "zh": ["Chinese", "中文"]
  }
}
```

Each entry is an array of `[englishName, nativeName]`. 70+ languages are supported.

***

## Translation in messages

Message translation happens automatically — when a user reads a conversation, each message is translated into their language on the fly. You don't need to call the translation endpoint yourself for messaging.

The `POST /api/translate` endpoint is useful for translating other content — such as custom field values, course names, or external data you're importing.
