> ## 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 TypeScript wrap theme={"dark"}
import { createSiteClient } from '@fetchski/attract-cms-sdk';

const site = createSiteClient();
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 function makes the call on the client it is given, so your code passes the real one and a test passes a fake.

**1. Add the function**

```ts src/attract/get-locales.ts theme={"dark"}
import type { SiteClient } from '@fetchski/attract-cms-sdk';

export async function getLocales(site: SiteClient) {
  return site.internationalization().getLocales();
}
```

**2. Call it**

A script makes the client once and calls the function:

```ts scripts/get-locales.ts theme={"dark"}
import { createSiteClient } from '@fetchski/attract-cms-sdk';
import { getLocales } from '../src/attract/get-locales.ts';

const site = createSiteClient();
console.log(await getLocales(site));
```

```bash Terminal theme={"dark"}
node --env-file=.env scripts/get-locales.ts
```

A route handler, a job or a queue worker calls it the same way.

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; catch only what you want to react to (see [Errors and testing](https://docs.fetchski-attract.com/typescript/errors.md)).
>
> **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 your sites (`createSiteClients()`) don’t have.
>
> **Retried first:** No: nothing was sent. **Read:** `message`, `slug`.
>
> **SiteConfigurationError** `setup`
>
> The client’s settings are wrong: no `FETCHSKI_ATTRACT_URL` (or `baseUrl`), or a malformed API key.
>
> **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) on the client for longer.

## Test it

It calls the function above with a fake client: the fake answers every call with a valid example, so nothing leaves your machine and no settings or key are needed. Run it with `node --test`.

```ts tests/internationalization-getLocales.test.ts theme={"dark"}
import { test } from 'node:test';
import { fakeSite } from '@fetchski/attract-cms-sdk/testing';
import { getLocales } from '../src/attract/get-locales.ts';

test('internationalization.getLocales', async () => {
  const site = fakeSite();
  await getLocales(site);
  site.assertCalled('internationalization.getLocales');
});
```

## Related

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

> [card] [Check document existence in locale](https://docs.fetchski-attract.com/typescript/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.