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:
Mcat12
2018-05-15 16:24:54 -04:00
parent 164db8ce06
commit 23065fc27b
2 changed files with 36 additions and 37 deletions
+28 -28
View File
@@ -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
View File
@@ -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')
);