---
title: "next-translate"
description: "The preset for next-translate. It reads useTranslation, getT, Trans and namespaces with a `:` separator."
canonical_url: "https://x18n.dev/presets/next-translate"
---
# next-translate

> The preset for next-translate. It reads useTranslation, getT, Trans and namespaces with a \`:\` separator.

The `next-translate` preset supports [next-translate](https://github.com/aralroca/next-translate).

## Detection

The preset applies when the project depends on `next-translate`.

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

export default defineConfig({
  presets: ['next-translate'],
})
```

## Locale files

If your config has no `resources`, the preset uses `locales/{locale}/{namespace}.json`. New files use nested keys.

## Namespaces

The preset sets the namespace separator to `:` and the default namespace to `common`, as next-translate does. A key without a namespace is in `common`.

## Supported syntax

```tsx [pages/index.tsx]
import Trans from 'next-translate/Trans'
import useTranslation from 'next-translate/useTranslation'

function Page() {
  const { t } = useTranslation('home')
  t('intro') // home:intro
  t('common:title') // common:title
  return <Trans i18nKey="title" ns="common" />
}
```

- `useTranslation(ns)` returns a `t` with the namespace `ns`.
- `getT(locale, ns)` returns a `t` with the namespace of its second argument.
- `<Trans i18nKey="..." ns="...">` is a usage of its `i18nKey`.
- `t` is a translate call, and so is the tagged template ``t`key```.

## Placeholders

Double braces: `{{name}}`.

## Extraction templates

| Kinds                      | Template                    |
| -------------------------- | --------------------------- |
| `jsx-text`                 | `{t('{key}'{args})}`        |
| `jsx-attribute`            | `{attr}={t('{key}'{args})}` |
| `js-string`, `js-template` | `t('{key}'{args})`          |


## Sitemap

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