简体   繁体   English

当我在反应本机中更改语言时如何重新启动应用程序

[英]How can i restart app when i change language in react native

I tried to create a picker that is used to change language.我试图创建一个用于更改语言的选择器。 But some texts remain untranslated even if user selects different language.但是即使用户选择了不同的语言,有些文本仍然没有被翻译。 i tried我试过了

import * as RNLocalize from 'react-native-localize';
import I18n from 'i18n-js';
import memoize from 'lodash.memoize'; 

import en from './en';
import am from './am';
import or from './or';
import tg from './tg';


const locales = RNLocalize.getLocales();
if (Array.isArray(locales)) {
  I18n.locale = locales[0].languageTag;
}

I18n.translations = {
  default: en,
  'en-US': en,
  en,
  am,
  or,
  tg,

};

I18n.fallbacks = true;
export default I18n;

the Code I use to switch language is我用来切换语言的代码是

onChangeLanguage(languageSelected){
  this.setState({
    languageSelected
  })
  I18n.locale = languageSelected 
}

and the react native picker is:反应原生选择器是:

<Picker
  mode="dropdown"
  iosHeader={''} 
  style={{ width: width,height:80,}}
  selectedValue={this.props.language}
  onValueChange={this.props.onChangeLanguage.bind(this)}
>
  {listLanguage.map((languageItem, i) => {
      return <Picker.Item key={i} value={languageItem.key} label= {languageItem.label} />
  })}
</Picker>

Does any one show me how to Restart app when language is changed(selected)?有没有人告诉我如何在语言更改(选择)时重新启动应用程序? Thanks谢谢

There is no need to restart your app after language change.语言更改后无需重新启动您的应用程序。 In React, the app re-renders if it is dependant on state or props changes.在 React 中,如果应用程序依赖于 state 或 props 更改,它会重新渲染。 You can check my answer here: React Native, how to update view after language change你可以在这里查看我的答案: React Native, how to update view after language change

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我重新启动应用程序时如何使反应本机应用程序保存所选语言 - How to make react native app save the selected language when i restart the app 使用 i18next 从应用程序更改时,如何使反应本机应用程序保存语言? - How to make react native app save the language when changed from the app with i18next? React Native 如何在 AsyncStorage 中存储语言并更改应用程序语言? - React native how to store language in AsyncStorage and change the app language? 我可以在 React Native 应用程序中以编程方式更改样式吗? - Can I programmatically change styling within react native app? 在React Native中如何访问本机相机应用程序? - In React Native how can I access the native camera app? react native:当我从另一个页面单击按钮时,如何更改视图? - react native: How can I change a view when i click a button from another page? 为什么我不能重新启动我的本地应用程序? - Why can't I restart my react-native application? 我如何在React Native的屏幕快照中更改应用程序的背景色(红色标记)? - How can i change App background color as mentioned (Red marker) in screen shot in react native? 如何使用 react-native 0.60 更改 ReactNative 项目的项目和应用程序名称 - How can I change the project and app name of ReactNative project with react-native 0.60 如何使用 react-native Appearance 和 useColorScheme 更改应用程序主题? - How can I change app theme with react-native Appearance and useColorScheme?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM