svelte-i18n

The preset for svelte-i18n. It reads the $_ store and its aliases in Svelte components and scripts.

The svelte-i18n preset supports svelte-i18n and sveltekit-i18n.

Detection

The preset applies when the project depends on svelte-i18n, sveltekit-i18n or @sveltekit-i18n/base.

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

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

Supported syntax

These names count as translate calls: $_, $t, $format, _, t, format, $json and json.

src/App.svelte
<script>
  import { _ } from 'svelte-i18n'
</script>

<h1>{$_('app.title')}</h1>
<p>{$_('app.greeting', { values: { name: 'Ada' } })}</p>

The Svelte scanner reads the <script> blocks and the template expressions of .svelte files. It runs in Node only.

Placeholders

ICU MessageFormat, as for next-intl.

Extraction templates

KindsTemplateImports
svelte-text{$_('{key}'{args})}import { _ } from 'svelte-i18n'
svelte-attribute{attr}={$_('{key}'{args})}import { _ } from 'svelte-i18n'