Warm tip: This article is reproduced from serverfault.com, please click

reactjs-React Native,如何在语言更改后更新视图

(reactjs - React Native, how to update view after language change)

发布于 2018-03-01 17:29:12

我想支持语言更改(由用户手动)。为此,我正在使用react-native-i18n我找到了如何在运行时更改显示语言,但没有找到如何更新当前视图。

我的代码

在此处输入图片说明

环境

环境:

  • 节点:8.9.4
  • 纱线:1.3.2
  • npm:4.0.5

预期行为

当我使用I18n.locale ='en';not in function.. 时,文本将使用英语,而当我使用时I18n.locale ='he';,文本将使用希伯来语。但是我需要在运行时更改语言。所以我希望当我点击每个按钮时,语言会改变并显示出来。

实际行为

什么也没发生.. 我想我需要重新加载/重新渲染/更新视图,但我没有找到方法。

Questioner
Omri Attiya
Viewed
11
Mertcan Diken 2018-03-02 18:04:09

你可以试试这样的

<View style={styles.container}>
    <Button onPress={this.setLocale()} title={strings('test.b1')}> 
</View>

public setLocale() {
    this.setState({stateOfLocale: 'en'});
    I18n.locale = stateOfLocale;
}