next-translate
The preset for next-translate. It reads useTranslation, getT, Trans and namespaces with a `:` separator.
The next-translate preset supports next-translate.
Detection
The preset applies when the project depends on next-translate.
x18n.config.ts
import { nextTranslate } from '@x18n/cli/presets'
import { defineConfig } from '@x18n/core'
export default defineConfig({
presets: [nextTranslate()],
})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
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 atwith the namespacens.getT(locale, ns)returns atwith the namespace of its second argument.<Trans i18nKey="..." ns="...">is a usage of itsi18nKey.tis a translate call, and so is the tagged templatet`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}) |