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