cibernox / svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
https://svelte-intl-precompile.com
ISC License
274 stars 13 forks source link

Intl formatters do not get updated on language change #15

Closed wgrabias closed 2 years ago

wgrabias commented 2 years ago

It seems that memoizing of i.e getTimeFormatter isn't working properly:

precompiled translations use __time that only passes the format:

export function __time(value, format = "short") {
    return formatTime(value, { format });
}

Formatter is later picked based on that options:

export const formatTime = (t, options) => getTimeFormatter(options).format(t);

No matter which language is selected the locale prop passed to the function is undefined, so after switching the language getTImeFormatter returns the one already memoized for the first language:

export const getTimeFormatter = monadicMemoize(({ locale, format, ...options } = {}) => {
    locale = locale || getCurrentLocale();
...
});

The above applies to other formatters as well

cibernox commented 2 years ago

Is this something you can provide a reproduction? I know for a fact that when changing the current locale from en-US to en-GB formatted dates go from 6:10PM to 18:10, so it seems to be working for dates.

Closing this for now, reopen it if it's still an issue.