在反应中使用redux更改语言环境

问题描述 投票:0回答:1

我有一个非常基本的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,我会看到翻译效果很好

我遇到的问题是如何从按钮或下拉菜单动态更改它。

我已经创建了两个按钮,ENDE,当我单击它们中的任何一个时,都可以像以下商店进行配送:

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() }
reactjs redux react-redux i18next
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.