6
6
*/
7
7
8
8
import App from './app' ;
9
- import { FunctionComponent , useMemo } from 'react' ;
9
+ import { FunctionComponent , PropsWithChildren , useMemo } from 'react' ;
10
10
import { CssBaseline , responsiveFontSizes , ThemeOptions } from '@mui/material' ;
11
11
import { createTheme , StyledEngineProvider , Theme , ThemeProvider } from '@mui/material/styles' ;
12
12
import { enUS as MuiCoreEnUS , frFR as MuiCoreFrFR } from '@mui/material/locale' ;
13
+ import { LocalizationProvider } from '@mui/x-date-pickers' ;
14
+ import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns' ;
15
+ import { enUS as MuiDatePickersEnUS , frFR as MuiDatePickersFrFR } from '@mui/x-date-pickers/locales' ;
16
+ import { enUS as dateFnsEnUS , fr as dateFnsFr } from 'date-fns/locale' ;
13
17
import {
14
18
cardErrorBoundaryEn ,
15
19
cardErrorBoundaryFr ,
@@ -26,7 +30,7 @@ import {
26
30
topBarFr ,
27
31
NotificationsProvider ,
28
32
} from '@gridsuite/commons-ui' ;
29
- import { IntlConfig , IntlProvider } from 'react-intl' ;
33
+ import { type IntlConfig , IntlProvider } from 'react-intl' ;
30
34
import { Provider , useSelector } from 'react-redux' ;
31
35
import messages_en from '../../translations/en.json' ;
32
36
import messages_fr from '../../translations/fr.json' ;
@@ -103,7 +107,8 @@ const getMuiTheme = (theme: GsTheme, locale: GsLangUser): Theme => {
103
107
return responsiveFontSizes (
104
108
createTheme (
105
109
theme === LIGHT_THEME ? lightTheme : darkTheme ,
106
- locale === LANG_FRENCH ? MuiCoreFrFR : MuiCoreEnUS // MUI core translations
110
+ locale === LANG_FRENCH ? MuiCoreFrFR : MuiCoreEnUS , // MUI core translations
111
+ locale === LANG_FRENCH ? MuiDatePickersFrFR : MuiDatePickersEnUS // MUI x-date-pickers translations
107
112
)
108
113
) ;
109
114
} ;
@@ -125,10 +130,21 @@ const messages: Record<GsLangUser, IntlConfig['messages']> = {
125
130
126
131
const basename = new URL ( document . baseURI ?? '' ) . pathname ;
127
132
133
+ function intlToDateFnsLocale ( lng : GsLangUser ) {
134
+ switch ( lng ) {
135
+ case LANG_FRENCH :
136
+ return dateFnsFr ;
137
+ case LANG_ENGLISH :
138
+ return dateFnsEnUS ;
139
+ default :
140
+ return undefined ;
141
+ }
142
+ }
143
+
128
144
/**
129
145
* Layer injecting Theme, Internationalization (i18n) and other tools (snackbar, error boundary, ...)
130
146
*/
131
- const AppWrapperRouterLayout : typeof App = ( props , context ) => {
147
+ const AppWrapperRouterLayout : typeof App = ( props : Readonly < PropsWithChildren < { } > > ) => {
132
148
const computedLanguage = useSelector ( ( state : AppState ) => state . computedLanguage ) ;
133
149
const theme = useSelector ( ( state : AppState ) => state [ PARAM_THEME ] ) ;
134
150
const themeCompiled = useMemo ( ( ) => getMuiTheme ( theme , computedLanguage ) , [ computedLanguage , theme ] ) ;
@@ -137,14 +153,19 @@ const AppWrapperRouterLayout: typeof App = (props, context) => {
137
153
< IntlProvider locale = { computedLanguage } defaultLocale = { LANG_ENGLISH } messages = { messages [ computedLanguage ] } >
138
154
< StyledEngineProvider injectFirst >
139
155
< ThemeProvider theme = { themeCompiled } >
140
- < SnackbarProvider hideIconVariant = { false } >
141
- < CssBaseline />
142
- < CardErrorBoundary >
143
- < NotificationsProvider urls = { urlMapper } >
144
- < App { ...props } > { props . children } </ App >
145
- </ NotificationsProvider >
146
- </ CardErrorBoundary >
147
- </ SnackbarProvider >
156
+ < LocalizationProvider
157
+ dateAdapter = { AdapterDateFns }
158
+ adapterLocale = { intlToDateFnsLocale ( computedLanguage ) }
159
+ >
160
+ < SnackbarProvider hideIconVariant = { false } >
161
+ < CssBaseline />
162
+ < CardErrorBoundary >
163
+ < NotificationsProvider urls = { urlMapper } >
164
+ < App { ...props } > { props . children } </ App >
165
+ </ NotificationsProvider >
166
+ </ CardErrorBoundary >
167
+ </ SnackbarProvider >
168
+ </ LocalizationProvider >
148
169
</ ThemeProvider >
149
170
</ StyledEngineProvider >
150
171
</ IntlProvider >
0 commit comments