NishuGoel / svelte-i18next

Internationalization for svelte framework. Based on i18next ecosystem
https://npmjs.com/package/svelte-i18next
MIT License
51 stars 11 forks source link

Add sveltekit instructions #12

Closed Lobidu closed 1 year ago

Lobidu commented 1 year ago

This PR adds instructions for the use with sveltekit that avoids a tricky caveat regarding the way that Sveltekit uses stores on serverside:

On most SSR environments using the store directly – as you would in plain Svelte Apps – means localisation state is unintentionally shared between users.

For most smaller applications this doesn't have any visible effect because localisation state is set at the beginning of the request and the request is completed before another user's request is received.

But in high traffic environments and / or slow rendering pages the following could happen:

The Sveltekit docs explicitly state to avoid global stores for this reason: https://kit.svelte.dev/docs/state-management

Fortunately this library uses i18next's createInstance function, so the fix is as easy as just using getContext instead of using the store directly.

NishuGoel commented 1 year ago

Thanks for the PR @Lobidu LGTM ✅