我有一个非常基本的react应用程序,已启用i19next。
这是我的基本i18n配置的样子:
import i18next from 'i18next';
import { resources } from './resources'
import store from '../store'
i18next.init({
lng: 'en',
resources,
fallbackLng: "en",
debug: true,
});
export default i18next
这很好,如果我将lng
更改为de
,我会看到翻译效果很好
我遇到的问题是如何从按钮或下拉菜单动态更改它。
我已经创建了两个按钮,EN
,DE
,当我单击它们中的任何一个时,都可以像以下商店进行配送:
store.dispatch({type: 'TRANSLATION_CHANGE', locale})
``
The store is dispatched and EVERYTHING works, but I can't somehow get the store here:
```js
import store from '../store'
const state = store.getState();
console.log("getState", state) // works, I can see lang: 'DE' or 'EN'
i18next.init({
lng: state.lang, // NOT WORKING
resources,
fallbackLng: "en",
debug: true,
});
我有一个非常基本的react应用程序,已启用i19next。这是我的基本i18n配置的样子:从'i18next'导入i18next;从'./resources'导入{资源}从'../ store'...>导入存储
import RNRestart from 'react-native-restart';
_onSetLanguageToItalian() {
strings.setLanguage('it');
this.setState({});
RNRestart.Restart()
}