Commit c15865ef authored by Viacheslav Pavlov's avatar Viacheslav Pavlov

fixed i18n upgrade

parent fb106104
......@@ -13,7 +13,7 @@ import {log} from 'utilities/debug';
import { I18nextProvider, withSSR } from 'react-i18next';
import routes from 'ui/routes';
import renderRoutes from 'ui/renderRoutes';
import i18nClient from '../i18n/i18n-client';
import { i18nClient } from '../i18n/i18n-client';
import detectLocaleFromPath from '../server/middleware/detectLocaleFromPath';
import getDir from '../server/middleware/detectDirection';
import { receiveLang } from 'actions/applicationConfig';
......@@ -52,17 +52,15 @@ if (__PRELOADED_STATE__ === undefined) {
document.getElementsByTagName('html')[0].setAttribute('dir', direction);
checkAccessTokens(store.dispatch, store.getState)
.then(() => store.dispatch(receiveLang(detectedLang)))
.then(async () => store.dispatch(receiveLang(detectedLang)))
.then(() => {
// no SSR
ReactDOM.render(
<Provider store={ store }>
<ConnectedRouter history={ history }>
<I18nextProvider i18n={ i18nClient }>
<I18nextProvider i18n={ await i18nClient }>
<MuiThemeProvider theme={ theme(direction) }>
<React.Suspense fallback="loading">
{ renderRoutes(routes) }
</React.Suspense>
</MuiThemeProvider>
</I18nextProvider>
</ConnectedRouter>
......
......@@ -4,7 +4,7 @@ import axios from 'axios';
import optionsBase from './options-base';
import langDetector from './langDetector';
const XHR = require('i18next-xhr-backend');
import XHR from 'i18next-xhr-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';
const lngDetector = new LanguageDetector();
......@@ -29,7 +29,7 @@ const backendKey = 'backend';
optionsBase[backendKey] = backend;
const i18nClient = i18n
i18n
.use(XHR)
.use(lngDetector)
.use(initReactI18next)
......@@ -42,8 +42,8 @@ const i18nClient = i18n
useSuspense: false,
},
...optionsBase,
}).then((res) => res);
});
export default i18nClient;
export { i18n as i18nClient };
import * as i18n from 'i18next';
// @ts-ignore
import i18n from 'i18next';
import * as path from 'path';
import optionsBase from './options-base';
const Backend = require('i18next-sync-fs-backend'); // has no proper import yet
import Backend from 'i18next-sync-fs-backend';
import { initReactI18next } from 'react-i18next';
const i18nextMiddleware = require('i18next-express-middleware'); // has no proper import yet
const backend = {
......@@ -14,15 +17,19 @@ const backendKey = 'backend';
optionsBase[backendKey] = backend;
const i18nServer = i18n
i18n
.use(Backend)
.use(i18nextMiddleware.LanguageDetector)
.use(initReactI18next)
.init({
detection: {
order: ['path'],
lookupFromPathIndex: 0,
},
react: {
useSuspense: false,
},
...optionsBase,
});
export default i18nServer;
export {i18n as i18nServer} ;
......@@ -5,6 +5,7 @@ const optionsBase = {
// have a common namespace used around the full app
ns: ['translations', 'common'],
defaultNS: 'translations',
nsSeparator: ':', // namespace separator
keySeparator: '.', // key separator
saveMissing: false,
......
......@@ -11,7 +11,7 @@ import config from './config';
import prerenderer from './middleware/prerenderer';
import robots from './robots';
import sitemap from './sitemap';
import i18nServer from '../i18n/i18n-server';
import { i18nServer } from '../i18n/i18n-server';
import httpProxy from './middleware/httpProxy';
import AccessionService from 'service/genesys/AccessionService';
import AccessionFilter from 'model/accession/AccessionFilter';
......
......@@ -293,4 +293,4 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
collapseSidebar,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(compose(withWidth(), withStyles(styles), withTranslation()(SidebarWrapper)));
export default connect(mapStateToProps, mapDispatchToProps)(compose(withWidth(), withStyles(styles), withTranslation())(SidebarWrapper));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment