> ## 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).

```php Laravel wrap theme={"dark"}
use Fetchski\AttractCmsLaravel\Facades\Attract;

$result = Attract::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**

```php app/Http/Controllers/GetLocalesController.php theme={"dark"}
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Fetchski\AttractCmsLaravel\Data\LocalesResponseValue;
use Fetchski\AttractCmsLaravel\Facades\Attract;

final class GetLocalesController
{
    /** @return array<string, LocalesResponseValue> */
    public function __invoke(): array
    {
        return Attract::internationalization()->getLocales();
    }
}
```

**2. Add the route**

```php routes/web.php theme={"dark"}
use App\Http\Controllers\GetLocalesController;
use Illuminate\Support\Facades\Route;

Route::get('/i18n/locales', GetLocalesController::class);
```

**3. Call it**

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

With `php artisan serve` running, it prints its answer as JSON.

> [!TIP]
>
> To keep the call in an Action instead, this writes `app/Actions/Attract/GetLocales.php` (an invokable Action that calls `getLocales()`) and its test under `tests/Feature/Actions/Attract/` (Pest when your app has it):
>
> ```bash Terminal theme={"dark"}
> php artisan make:attract-action internationalization.getLocales
> ```

## Call it from the terminal

```bash Terminal theme={"dark"}
php artisan attract:call internationalization.getLocales
```

It calls `getLocales()` on your default site and prints its answer as JSON. See [Call any method from the terminal](https://docs.fetchski-attract.com/call-command.md) for every argument type.

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
>
> `array<string, LocalesResponseValue>`. The languages, keyed by code.
>
> **LocalesResponseValue (Fetchski\AttractCmsLaravel\Data\LocalesResponseValue)**
>
> **label** `?string`
>
> **Sometimes sent:** `null` when the site leaves it out. The language’s name, as its speakers write it.
>
> **prefix** `?string`
>
> **Sometimes sent:** `null` 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** `?bool`
>
> **Sometimes sent:** `null` 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** `Enums\\Direction|string|null`
>
> **Sometimes sent:** `null` 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 Laravel logs and renders the rest (see [Errors and testing](https://docs.fetchski-attract.com/laravel/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`
>
> `Attract::site('acme')` named a slug that isn’t under `sites` in `config/fetchski-attract.php`.
>
> **Retried first:** No: nothing was sent. **Read:** `getMessage()`, `$e->slug`.
>
> **SiteConfigurationError** `setup`
>
> The site’s config entry is wrong: no `url`, a malformed `api_key`, a key filed under another slug, or no default site.
>
> **Retried first:** No: nothing was sent. **Read:** `getMessage()` (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` in `config/fetchski-attract.php` for longer.

## Test it

It calls the route above with the SDK faked: the fake answers every call with a valid example, so nothing leaves your machine and no config or key is needed. Save it as `tests/Feature/GetLocalesTest.php`, then run your tests:

```php tests/Feature/GetLocalesTest.php theme={"dark"}
<?php

declare(strict_types=1);

namespace Tests\Feature;

use Fetchski\AttractCmsLaravel\Facades\Attract;
use Tests\TestCase;

final class GetLocalesTest extends TestCase
{
    public function test_get_locales(): void
    {
        Attract::fake();

        $this->getJson('/i18n/locales')->assertOk();

        Attract::assertCalled('internationalization.getLocales');
    }
}
```

```bash Terminal theme={"dark"}
php artisan test
```

## Related

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

> [card] [Check document existence in locale](https://docs.fetchski-attract.com/laravel/reference/internationalization/exist-in-locale.md)
>
> `Attract::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.