Utilities for localized URLs in Sapper with built-in i18n support.
|slug|
s in Svelte files for i18nThere is no "right" way to do i18n in Sapper (see sveltejs/sapper#576). This package is a temporary utility that adds support for language prefixes in URLs and i18n helpers.
For example:
<p>|helloWorld|</p>
Is rendered to the English page http://example.com/en/hello:
<p>Hello, world!</p>
To do this, the main features are: (i) replacing |slug|
with translations, and (ii) generating components and routes.
To get started, install the package from npm:
npm install sapper-i18n-sync
To create a locales
directory from a remote git repository:
import { generateLocales } from "sapper-i18n-sync";
generateLocales({
gitRepo: "https://github.com/koj-co/i18n",
path: "locales",
})
Then, generate:
import { generateSvelte } from "sapper-i18n-sync";
generateSvelte();