🐛 corrige le changement de langue

pull/993/head
Johan Girod 2020-04-23 15:59:43 +02:00
parent 8d8121844c
commit ad1ea05bf8
2 changed files with 14 additions and 18 deletions

View File

@ -15,7 +15,7 @@ import { applyMiddleware, compose, createStore, Middleware, Store } from 'redux'
import thunk from 'redux-thunk'
import Tracker from 'Tracker'
import { Rules } from './rules'
import { inIframe } from './utils'
import { inIframe, getSessionStorage } from './utils'
declare global {
interface Window {
@ -93,11 +93,11 @@ export default function Provider({
...(reduxMiddlewares ?? [])
)
)
useEffect(() => {
if (language) {
i18next.changeLanguage(language)
}
}, [])
if (language) {
getSessionStorage()?.setItem('lang', language)
i18next.changeLanguage(language)
}
if (language && initialStore) initialStore.lang = language
const store = createStore(reducers, initialStore, storeEnhancer)
onStoreCreated?.(store)

View File

@ -7,13 +7,13 @@ import {
import { SitePathsContext } from 'Components/utils/SitePathsContext'
import Engine from 'Engine'
import 'iframe-resizer'
import React, { useContext, useEffect, useMemo } from 'react'
import React, { useContext, useMemo } from 'react'
import { Helmet } from 'react-helmet'
import { useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'
import { Route, Switch } from 'react-router-dom'
import createSentryMiddleware from 'redux-sentry-middleware'
import { Rules } from 'Rules'
import rulesFr, { Rules } from 'Rules'
import {
configSituationSelector,
situationSelector
@ -29,7 +29,7 @@ import {
retrievePersistedSimulation
} from '../../storage/persistSimulation'
import Tracker, { devTracker } from '../../Tracker'
import { getSessionStorage, inIframe } from '../../utils'
import { inIframe } from '../../utils'
import './App.css'
import Footer from './layout/Footer/Footer'
import Header from './layout/Header'
@ -78,20 +78,16 @@ const middlewares = [
trackSimulatorActions(tracker)
]
type InFranceRouteProps = {
type RootProps = {
basename: ProviderProps['basename']
language: ProviderProps['language']
rules: Rules
}
function InFranceRoute({ basename, language, rules }: InFranceRouteProps) {
useEffect(() => {
getSessionStorage()?.setItem('lang', language)
}, [language])
function Root({ basename, language, rules }: RootProps) {
// Hot reload rules
if (process.env.NODE_ENV !== 'production' && language === 'fr') {
rules = rules
rules = rulesFr
}
const paths = constructLocalizedSitePath(language)
@ -199,11 +195,11 @@ const App = () => {
)
}
let ExportedApp = InFranceRoute
let ExportedApp = Root
if (process.env.NODE_ENV !== 'production') {
const { hot } = require('react-hot-loader')
ExportedApp = hot(module)(InFranceRoute)
ExportedApp = hot(module)(Root)
}
export default ExportedApp