---
title: "laravel"
description: "The preset for Laravel. It reads PHP translation arrays and JSON strings, __ and trans calls, and :name placeholders."
canonical_url: "https://x18n.dev/presets/laravel"
---
# laravel

> The preset for Laravel. It reads PHP translation arrays and JSON strings, \_\_ and trans calls, and \:name placeholders.

The `laravel` preset supports the [localization of Laravel](https://laravel.com/docs/localization).

## Detection

The preset applies when `composer.json` requires `laravel/framework`. The preset is exclusive: when it applies, x18n tests no preset after it.

```ts [x18n.config.ts]
import { defineConfig } from '@x18n/core'

export default defineConfig({
  presets: ['laravel'],
})
```

## Locale files

If your config has no `resources`, the preset uses these patterns:

- `lang/{locale}/{namespaces}.php`
- `resources/lang/{locale}/{namespaces}.php`
- `lang/{locale}.json`
- `resources/lang/{locale}.json`

The `php` format reads a file that returns an array literal, and writes edits back into the array. The path of a PHP file is the first part of its keys:

```php [lang/en/auth.php]
<?php

return [
    'failed' => 'These credentials do not match.',
];
```

This file has the key `auth.failed`. A file in a subdirectory, such as `lang/en/admin/users.php`, gives keys such as `admin.users.title`. In a JSON file, such as `lang/en.json`, each key is a whole sentence: `Welcome back!`. The JSON patterns set `keySeparator: false`, so a sentence such as `Welcome back.` is one key and x18n writes it as one property, while the PHP files keep `.` as the key separator.

## Supported syntax

In PHP and Blade files, the preset reads `__`, `trans`, `trans_choice`, `@lang`, `Lang::get` and `Lang::choice`. Laravel writes the keys of a nested file with a slash. The preset turns each slash into a dot:

```blade [resources/views/a.blade.php]
{{ __('auth.failed') }}
@lang('admin/users.title')
{{ __('Welcome back!') }}
```

These usages are `auth.failed`, `admin.users.title` and `Welcome back!`.

## Placeholders

Colon: `:name`, as in `'title' => 'Users :count'`.

## Extraction templates

| Kinds | Template      |
| ----- | ------------- |
| any   | `__('{key}')` |


## Sitemap

See the full [sitemap](https://x18n.dev/sitemap.md) for all pages.
