How to use dynamic locales coming from the backend? #3071
Unanswered
martinszeltins
asked this question in
General
Replies: 2 comments
-
|
Hello, how that's can be returned? I speak about you're locales from your API. Do you have a list of all the possibilities? |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
You can dynamic import the locale something like this ( v2 ): import { setDefaultOptions } from 'date-fns';
...
export const loadDateFnsLocale = async (locale: Locale) => {
return await import(
`date-fns/locale/${localeToDateFnsLocale[locale]}/index.js`
);
};
export const useDateFnsLocale = () => {
const {data} = loadDateFnsLocale('en-US'); // Example
if (data) {
setDefaultOptions({ locale: data.default });
}
...
}; |
Beta Was this translation helpful? Give feedback.
0 replies
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.
-
My locale is coming from the backend and I do not know what it will be in advance. So I cannot statically import a specific locale from
date-fnsand I don't want to import them all either. Is there a workaround for this?For example, from the backend server I receive this locale as string
How can I now use this
localevariable fordate-fns?Beta Was this translation helpful? Give feedback.
All reactions