Skip to content

SvelteKit: Load translation for non-active locale #189

Answered by ivanhofer
freeform99 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @freeform99,
you almost guesst the correct syntax ;)
The generated src/i18n.util.ts file, also includes a i18n object which you can use to create an L instance (it is not a svelte store, so you can't use the $ prefix).
on the L instance you then have access to all locales and their translations.

import { i18n } from '$i18n/i18n-util'
import { loadAllLocales } from '$i18n/i18n-util.sync'

loadAllLocales() // you need to load all locales into memory before initializing
const L = i18n() // create a `L` instance

L.de.blog_title()
L.en.blog_title()
L.fr.blog_title()

But keep in mind, that depending on where in your code you are doing that, it could potentially load the whole dictionary for…

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@freeform99
Comment options

Answer selected by freeform99
Comment options

You must be logged in to vote
5 replies
@ivanhofer
Comment options

@lukashass
Comment options

@ivanhofer
Comment options

@lukashass
Comment options

@ivanhofer
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants