Open carlitoplatanito opened 4 years ago
@carlosl But why do you need to explicitly specify the default language, if you can just provide the default language as a first one in the array? What is your use case?
I also want this feature though, I find a workaround like following.
export const supportedLocales = ['ja','en'];
export const I18nProvider: React.SFC<I18nProviderProps> = (
props: I18nProviderProps
) => {
const { children, i18n, locale } = props;
useEffect(() => {
i18n.changeLanguage(locale);
// When locale is changed, make its position to supportedLocales[0]
supportedLocales.sort((a, b) => {
if (a === locale) return -1;
if (b === locale) return 1;
return 0;
});
}, [i18n, locale]);
return <React.Suspense fallback={<Fragment />}>{children}</React.Suspense>;
};
addParameters({
i18n: {
provider: I18nProvider,
supportedLocales,
providerProps: {
i18n,
},
},
});
PR's are welcome! Also, this library is looking for maintainers!
Right now the language get's reset to the first locale in the
supportedLocales
array. Would like to request the possibility to set the default language, even if it's not the first one in the list.Also if it could save the language I had selected for when I switch stories that would be great.