next-international

The preset for next-international. It reads useI18n, useScopedI18n and their server versions, and TS locale files.

The next-international preset supports next-international.

Detection

The preset applies when the project depends on next-international.

x18n.config.ts
import { nextInternational } from '@x18n/cli/presets'
import { defineConfig } from '@x18n/core'

export default defineConfig({
  presets: [nextInternational()],
})

Locale files

If your config has no resources, the preset uses locales/{locale}.{ext} and src/locales/{locale}.{ext}.

next-international keeps messages in TS modules. The js format reads a module whose default export is an object literal, also with as const, and writes edits back into the literal:

locales/en.ts
export default {
  hello: 'Hello {name}',
  settings: { title: 'Settings' },
} as const

This file has the keys hello and settings.title.

Supported syntax

useI18n and getI18n return a translate function. useScopedI18n and getScopedI18n return one with a key prefix, from their first argument:

app/page.tsx
import { useI18n, useScopedI18n } from '../locales/client'

function Page({ name }: { name: string }) {
  const t = useI18n()
  const scopedT = useScopedI18n('settings')
  return (
    <>
      <h1>{t('hello', { name })}</h1>
      <p>{scopedT('title')}</p>
    </>
  )
}

scopedT('title') is a usage of settings.title.

Placeholders

Braces: {name}.

Extraction templates

KindsTemplate
jsx-text{t('{key}'{args})}
jsx-attribute{attr}={t('{key}'{args})}
js-string, js-templatet('{key}'{args})