SEO focused library for multi-language SvelteKit sites.
Core features:
These features are provided by the <I18n>
component.
Advanced SEO features:
<link rel="alternate" hreflang="lang"...>
elements to pages to tell search engines about language variants.These features are provided by the <I18nPage>
component.
Run locally with npm run dev
or try it on StackBlitz.
First steps: Open http://localhost:5173/en/simple/ and modify the h1 element in the web browser. You'll notice that the content of src/routes/en/simple/i18n.json file got updated. This way you can manage and review your i18n easily.
The website of https://versiobit.com was built using this library. Switch from english to german in the footer. If you inspect the source HTML you see all i18n messages are embedded as raw strings and SEO friendly meta and link-alternate tags are present.
This library is in an early development stage and has some rough edges. Feedback is very welcome! Create an issue or comment on Reddit.
<I18n>
componentThis is the core component. Place it into a svelte component and it will insert the given I18n message, e.g.
<h1><I18n name="title"/></h1>
When running in dev mode, you can modify the message by clicking on the element in the web browser.
Notes:
<I18nPage>
componentThis component provides a more opinionated way of how to build a multi language site.
If a page should exist in multi languages, create the folders and +page.svelte files as you normally would, e.g. /en/about-us for the English variant and /de/ueber-uns for the German variant.
Create a shared about.svelte component (e.g. in src/routes/en/about-us/about.svelte) that can be re-used by each variant like this:
<I18nPage id="/en/about-us">
<h1><I18n name="title" /></h1>
<p><I18n name="description" /></p>
</I18nPage>
The id
should be the directory path of this component within 'src/routes'. Thus, the id stays the same for each language variant of the page.
You can pass defaults in the call to initI18nContext. For example, to change the default language do:
initI18nContext(serverI18nData, {defaultLanguage: 'de'});
npm install
npm run dev
To build/publish use:
npm run package
npm publish