---
title: "adonisjs"
description: "The preset for AdonisJS i18n. It reads translate calls in code and Edge templates, and JSON or YAML language files with ICU messages."
canonical_url: "https://x18n.dev/presets/adonisjs"
---
# adonisjs

> The preset for AdonisJS i18n. It reads translate calls in code and Edge templates, and JSON or YAML language files with ICU messages.

The `adonisjs` preset supports [AdonisJS i18n](https://docs.adonisjs.com/guides/digging-deeper/i18n).

## Detection

The preset applies when the project depends on `@adonisjs/i18n`.

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

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

## Locale files

- `resources/lang/{locale}/{namespaces}.json`
- `resources/lang/{locale}/{namespaces}.yaml` and `.yml`

The file name is the key prefix, as in AdonisJS: `greeting` in `messages.json` is `messages.greeting`, and `title` in `pages/home.yaml` is `pages.home.title`.

`defaultLocale` and `fallbackLocales` come from `config/i18n.ts`. Keys under `validator.shared` count as used, since AdonisJS reads them itself.

## Supported syntax

In code, `i18n.t` and `ctx.i18n.t`, and `.t` on `i18nManager.locale(...)`, directly or through a variable:

```ts [app/controllers/home.ts]
i18n.t('messages.greeting', { name })
ctx.i18n.t('messages.title')
i18nManager.locale('fr').t('messages.title')
```

In Edge templates, the `t` helper:

<!-- eslint-skip -->

```html [resources/views/home.edge]
<h1>{{ t('messages.title') }}</h1>
<p>{{{ t('messages.intro', { name }) }}}</p>
```

## Placeholders

ICU messages: `{name}`, `{count, plural, one {# item} other {# items}}`.


## Sitemap

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