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

# List the site’s languages

> The site’s languages, keyed by code: the main language (en, no prefix) and each further one with its URL prefix (/fr).

```ts AdonisJS wrap theme={"dark"}
import app from '@adonisjs/core/services/app'
import { SiteClient } from '@fetchski/attract-cms-sdk'

const site = await app.container.make(SiteClient)
const result = await site.internationalization().getLocales()
```

```json 200 wrap theme={"dark"}
{
  "en": {
    "label": "English",
    "direction": "ltr"
  },
  "fr": {
    "label": "Français",
    "prefix": "/fr",
    "direction": "ltr"
  },
  "de": {
    "label": "Deutsch",
    "prefix": "/de",
    "private": true,
    "direction": "ltr"
  }
}
```

## In your app

A controller answers a route on your app: it calls `getLocales()` and returns the answer.

**1. Add the controller**

```ts app/controllers/get_locales_controller.ts theme={"dark"}
import { inject } from '@adonisjs/core'
import { SiteClient } from '@fetchski/attract-cms-sdk'

@inject()
export default class GetLocalesController {
  constructor(protected site: SiteClient) {}

  async handle() {
    return this.site.internationalization().getLocales()
  }
}
```

**2. Add the route**

```ts start/routes.ts theme={"dark"}
import router from '@adonisjs/core/services/router'

const GetLocalesController = () => import('#controllers/get_locales_controller')

router.get('/i18n/locales', [GetLocalesController])
```

**3. Call it**

```bash Terminal theme={"dark"}
curl http://localhost:3333/i18n/locales
```

With `node ace serve` running, it prints its answer as JSON.

A visitor gets the public ones; a signed-in person, or an API key with `languages:read`, also gets the ones not yet public (`private: true`), so their pages can be translated before they go live. Translate a document into one with its type’s localize route.

> [accordion] Parameters
>
> None: call it with no arguments.

> [accordion] Returns
>
> `Readonly<Record<string, LocalesResponseValue>>`. The languages, keyed by code.
>
> **LocalesResponseValue**
>
> **label** `string`
>
> **Sometimes sent:** `undefined` when the site leaves it out. The language’s name, as its speakers write it.
>
> **prefix** `string`
>
> **Sometimes sent:** `undefined` when the site leaves it out. The start of every URL in this language (`/fr`, so `/fr/about`); absent for the main language, whose URLs have none.
>
> **private** `boolean`
>
> **Sometimes sent:** `undefined` when the site leaves it out. True for a language not yet public: visitors don’t see it; only signed-in people and API keys with `languages:read` get it. Absent once it is public.
>
> **direction** `Direction`
>
> **Sometimes sent:** `undefined` when the site leaves it out. The text direction. One of `ltr`, `rtl`; a newer site may send others, so keep a fallback.

> [accordion] Errors
>
> Nothing to catch: the SDK retries what is safe, and throws the rest as the classes below. Your exception handler turns them into your app’s own answers, once for every call (see [Map SDK errors to responses](https://docs.fetchski-attract.com/adonisjs/calling-the-api.md#map-sdk-errors-to-responses)); catch only what you want to react to here.
>
> **SiteError** `5xx`
>
> The site failed (or something in front of it did). Its logs say why.
>
> **Retried first:** A 502, 503 or 504: yes, after 0.5 s then 1 s. A 500: no. **Read:** `siteMessage`, `errorName`, `data`.
>
> **SiteUnreachable** `no answer`
>
> No answer: DNS, a refused connection, TLS, or the timeout (15 s per attempt by default).
>
> **Retried first:** Yes, after 0.5 s then 1 s. **Read:** `reason`, `neverConnected`.
>
> **RequestNotSent** `not sent`
>
> The client refused to send it (e.g. a path segment of `..`); the site never saw it.
>
> **Retried first:** No. **Read:** `reason` (what to change).
>
> **SiteRequestFailed** `any other`
>
> Any other status, or a success whose JSON doesn’t match this SDK version’s types (update the SDK).
>
> **Retried first:** No. **Read:** `reason`, `status`.
>
> **UnknownSite** `setup`
>
> `sites.forSite('acme')` named a slug `config/attract.ts` doesn’t list (with the keys in the database: no row in `attract_api_keys`).
>
> **Retried first:** No: nothing was sent. **Read:** `message`, `slug`.
>
> **SiteConfigurationError** `setup`
>
> The site’s entry is wrong: a malformed `baseUrl` or key, a key filed under another slug, or no default site. `node ace attract:check` names the fix.
>
> **Retried first:** No: nothing was sent. **Read:** `message` (what to fix).

## Behavior

* **Retries:** a read is safe to repeat: the client retries it on no answer, a 502/503/504 and a 429.
* **Timeout:** 15 s per attempt by default; raise `timeout` (milliseconds) in `config/attract.ts` for longer.

## Test it

It calls the controller above with the SDK faked: `fakeAttract()` puts the fake in the container for this one test, and it answers every call with a valid example, so nothing leaves your machine and no key is read. Save it as `tests/unit/internationalization_get_locales.spec.ts`, then run your tests:

```ts tests/unit/internationalization_get_locales.spec.ts theme={"dark"}
import { test } from '@japa/runner'
import app from '@adonisjs/core/services/app'
import { fakeAttract } from '@fetchski/attract-cms-adonis/testing'
import GetLocalesController from '#controllers/get_locales_controller'

test('internationalization.getLocales', async () => {
  const site = fakeAttract()

  const controller = await app.container.make(GetLocalesController)
  await controller.handle()

  site.assertCalled('internationalization.getLocales')
})
```

```bash Terminal theme={"dark"}
node ace test
```

## Related

> [card] [Get locale path and manage clipboard](https://docs.fetchski-attract.com/adonisjs/reference/internationalization/switch-locale.md)
>
> `site.internationalization().switchLocale()`

> [card] [Check document existence in locale](https://docs.fetchski-attract.com/adonisjs/reference/internationalization/exist-in-locale.md)
>
> `site.internationalization().existInLocale()`

> [card] [GET /@apostrophecms/i18n/locales](https://docs.fetchski-attract.com/api-reference/internationalization/list-the-site’s-languages.md)
>
> The endpoint this calls, in the API reference: the HTTP request and answer, and every rule the site checks.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.