我想支持语言更改(由用户手动)。为此,我正在使用react-native-i18n。我找到了如何在运行时更改显示语言,但没有找到如何更新当前视图。
环境:
当我使用I18n.locale ='en';
not in function.. 时,文本将使用英语,而当我使用时I18n.locale ='he';
,文本将使用希伯来语。但是我需要在运行时更改语言。所以我希望当我点击每个按钮时,语言会改变并显示出来。
什么也没发生.. 我想我需要重新加载/重新渲染/更新视图,但我没有找到方法。
你可以试试这样的
<View style={styles.container}>
<Button onPress={this.setLocale()} title={strings('test.b1')}>
</View>
public setLocale() {
this.setState({stateOfLocale: 'en'});
I18n.locale = stateOfLocale;
}
完全工作!谢谢,而且现在我更了解 react native 的工作原理了
很高兴听到!