i18n

SveltePak includes support for i18n. You can use the i18n module to integrate i18n services and track custom events.

sveltekit-i18n is a tiny library with no external dependencies, built for Svelte and SvelteKit. It glues @sveltekit-i18n/base and @sveltekit-i18n/parser-default together to provide you the most straightforward sveltekit-i18n solution.

https://github.com/sveltekit-i18n/lib

Setup

The i18n module is already included in the SveltePak template. A component named <LanguageSwitcher /> is also included that you can use to switch between languages.

Registering new locales

To register new locales, you can use the register function from the svelte-i18n library. The translation files should be placed in the src/i18n/locales directory.

src/i18n/index.ts
import { init, register } from "svelte-i18n";

register("en", () => import("./locales/en.json"));
register("pt", () => import("./locales/pt.json"));

Usage

To use the i18n module, you can import the locale and _ functions from the svelte-i18n library.

src/routes/index.svelte
import { _, locale } from "svelte-i18n";
console.log(locale);

<a href="/">{$_("ACME")}</a>