These examples demonstrate how to integrate sveltekit-i18n into your app. Currently, these setups are present:
- loads all translations for all language mutations during
i18ninitialization - usually this is not what you are looking for, but it can be useful if you need all your translations in place.
- this approach is useful for one-page apps
- translations are loaded dynamically according to locale
- this is the most frequent use-case – application with multiple routes
- translations are loaded not only according to the locale, but given routes as well
- it prevents duplicit (server and client) translation load on app enter
- this
multi-pageapp demonstrates lang routing based on URL parameter (e.g.https://example.com/?lang=en)
- this
multi-pageapp demonstrates locale-based routing (e.g.https://example.com/en/about) - this approach is great if you care about SEO
- optimized for
@sveltejs/adapter-static
- this
multi-pageapp demonstrates locale-based routing (e.g.https://example.com/en/about) - this approach is great if you care about SEO
- optimized for non-static adapters (e.g.
@sveltejs/adapter-node)
- this
multi-pageapp demonstrates locale-based routing (e.g.https://example.com/en/about) - this approach is great if you care about SEO
- optimized for non-static adapters (e.g.
@sveltejs/adapter-node) - default locale routes do not have any lang prefix in path
- this is the most complex approach, which allows you to scope your translations to components, so they can have their own lexicons
- app translations are loaded the same way as for
multi-page(SSR) - component's translations are loaded in component promise (CSR - SvelteKit does not provide server side load method for components, so translation loaders are triggered on client side only)
- SvelteKit does not provide server side load method for components.
- component's
loadis replaced by exported init method. This method initializes related language mutation within parent page'sloadmethod. - after the load, appropriate props are delegated back to the component instance.
- this app demonstrates features of the @sveltekit-i18n/parser-default
- this app demonstrates features of the @sveltekit-i18n/parser-icu
- this app demonstrates different
config.loadersconfigurations
- this app demonstrates different
config.preprocessconfigurations
- this app demonstrates
config.fallbackLocale
- Clone or download the example you want to use
- Navigate to the downloaded folder using Terminal (e.g.
cd ./your/example/destination/) - Install dependencies using your preferred package manager:
npm i sveltekit-i18n@latest(ornpm i @sveltekit-i18n/PACKAGE_NAME@latestfor parser examples - see related dependencies)pnpm i sveltekit-i18n@latestyarn add sveltekit-i18n@latest- Or any other package manager you prefer
- Run the dev server to preview:
npm run dev -- --openpnpm run dev -- --openyarn dev --open- Or the equivalent command for your package manager