Version 3 #163
ivanhofer
announced in
Announcements
Version 3
#163
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Version 3 is here 🎉
This release contains some breaking changes:
loadLocalesAsyncoption from generatormigrating from version
2.x.xif set, remove the
loadLocalesAsyncoption from your.typesafe-i18n.jsonconfig file:{ "$schema": "https://unpkg.com/[email protected]/schema/typesafe-i18n.json", - "loadLocalesAsync": true, "adapter": "svelte" }if you are using the asynchronous initializing of formatters inside
src/i18n/formatters.ts, you have to switch to synchronous initializing:manually load locales in places where you initialize
typesafe-i18nor change the locale:import { loadLocaleAsync } from './i18n/i18n-util.async' const switchLocale = async (locale) => { - await setLocale(locale) + await loadLocaleAsync(locale) + setLocale(locale) }if you are using the
svelteadapter and are using theLLstore outside of Svelte components, you need to make sure you are accessing the store correctly:see Version 3 and 4 broke loading data from LL in scripts #180
Previously it was also possible to access the translation directly on the
LLstore itself, but this function was removed to simplify the implementation.reasons for these changes:
These changes were made due to this issue.
In version
3.0.0it is now possible to switch locales with a synchronous function. In theSvelteKitexample it can be called before the first component renders, resulting in having a consistent locale state while rendering the page on the server for SSR.It always felt a bit strange to have to choose between loading the locales in a synchronous way or loading them asnchronously. You had to specify the flag
loadLocalesAsyncin the options and the generator then created a different code whether it was set totrueorfalse.Use-cases where you would need both variants (e.g. a shared dictionary for API and frontend) would require you to write some manual code. Beginning with version 3 the
generatornow exports code to handle both loading variants. You then can choose between both options.An advantage that also comes with splitting the loading and the initialization of the adapters is: you can now load a dictionary before initializing your application.
downside: developers have to manually call a function to load locales before using the locale. But it's just a single line to add to the code.
Beta Was this translation helpful? Give feedback.
All reactions