Localization provider for muix
This commit is contained in:
@@ -3,6 +3,8 @@ import { useTranslation } from "@refinedev/core";
|
||||
import { useTheme } from "@mui/material";
|
||||
import * as locales from '@mui/material/locale';
|
||||
import { createTheme, ThemeProvider } from "@mui/material/styles";
|
||||
import { LocalizationProvider } from "@mui/x-date-pickers";
|
||||
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
||||
|
||||
type SupportedLocales = keyof typeof locales;
|
||||
|
||||
@@ -10,11 +12,13 @@ export const I18nTheme: React.FC<PropsWithChildren> = ({ children }: PropsWithCh
|
||||
const { getLocale } = useTranslation();
|
||||
const theme = useTheme()
|
||||
|
||||
const themeWithLocale = createTheme(theme, locales[getLocale() as SupportedLocales])
|
||||
|
||||
const locale = getLocale() || "en"
|
||||
const themeWithLocale = createTheme(theme, locales[locale as SupportedLocales])
|
||||
return (
|
||||
<ThemeProvider theme={themeWithLocale}>
|
||||
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale={locale.slice(0,2)} >
|
||||
{ children }
|
||||
</LocalizationProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user