mirror of
https://github.com/gosticks/web.git
synced 2026-12-03 17:51:39 +00:00
Simplify and fix i18next configuration
The `namespaces` config was supposed to be `ns`. This made it default to loading the default namespace of `translation`, which didn't exist. The I18nextProvider was removed and the i18n setup was moved into a function. Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
+28
-28
@@ -4,31 +4,31 @@ import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
import { reactI18nextModule } from 'react-i18next';
|
||||
import config from './config';
|
||||
|
||||
i18n
|
||||
.use(XHR)
|
||||
.use(LanguageDetector)
|
||||
.use(reactI18nextModule)
|
||||
.init({
|
||||
fallbackLng: "en",
|
||||
// Only attempt to load the base language, for example only attempt en and not en-US
|
||||
load: "languageOnly",
|
||||
namespaces: ['common', 'dashboard', 'footer', 'lists', 'location', 'login', 'query-log'],
|
||||
defaultNS: "common",
|
||||
fallbackNS: ['dashboard', 'footer', 'lists', 'location', 'login', 'query-log'],
|
||||
nsSeparator: false,
|
||||
keySeparator: false,
|
||||
debug: config.developmentMode,
|
||||
interpolation: {
|
||||
// Handled by React
|
||||
escapeValue: false
|
||||
},
|
||||
backend: {
|
||||
loadPath: process.env.PUBLIC_URL + "/i18n/{{lng}}/{{ns}}.json"
|
||||
},
|
||||
react: {
|
||||
// Wait until translations are loaded before rendering
|
||||
wait: true
|
||||
}
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
export function setupI18n() {
|
||||
i18n
|
||||
.use(XHR)
|
||||
.use(LanguageDetector)
|
||||
.use(reactI18nextModule)
|
||||
.init({
|
||||
fallbackLng: "en",
|
||||
// Only attempt to load the base language, for example only attempt en and not en-US
|
||||
load: "languageOnly",
|
||||
ns: ['common', 'dashboard', 'footer', 'lists', 'location', 'login', 'query-log'],
|
||||
defaultNS: "common",
|
||||
fallbackNS: ['dashboard', 'footer', 'lists', 'location', 'login', 'query-log'],
|
||||
nsSeparator: false,
|
||||
keySeparator: false,
|
||||
debug: config.developmentMode,
|
||||
interpolation: {
|
||||
// Handled by React
|
||||
escapeValue: false
|
||||
},
|
||||
backend: {
|
||||
loadPath: process.env.PUBLIC_URL + "/i18n/{{lng}}/{{ns}}.json"
|
||||
},
|
||||
react: {
|
||||
// Wait until translations are loaded before rendering
|
||||
wait: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+8
-9
@@ -13,18 +13,17 @@ import ReactDOM from 'react-dom';
|
||||
import { HashRouter, Route, Switch } from 'react-router-dom'
|
||||
import 'ionicons/dist/css/ionicons.min.css';
|
||||
import Full from './containers/Full'
|
||||
import i18n from './i18n';
|
||||
import { I18nextProvider } from 'react-i18next'
|
||||
import { setupI18n } from './i18n';
|
||||
|
||||
setupI18n();
|
||||
|
||||
ReactDOM.render(
|
||||
(
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<HashRouter>
|
||||
<Switch>
|
||||
<Route path="/" name="Home" component={Full}/>
|
||||
</Switch>
|
||||
</HashRouter>
|
||||
</I18nextProvider>
|
||||
<HashRouter>
|
||||
<Switch>
|
||||
<Route path="/" name="Home" component={Full}/>
|
||||
</Switch>
|
||||
</HashRouter>
|
||||
),
|
||||
document.getElementById('root')
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user