【问题标题】:How to translate title text of component?如何翻译组件的标题文本?
【发布时间】:2020-05-27 09:34:25
【问题描述】:

如何使用 i18next 等 i18n 工具动态翻译标题文本。

目前我正在传递这样的标题:

Settings.options = {
  topBar: {
    title: {
      text: 'Settings',
    },
  },
};

【问题讨论】:

  • 语言更改后是否要更新导航标题?或者在你的项目中使用 i18next ?
  • 应用程序的初始启动应正确翻译文本。这更像是一个普遍的问题。对于应用程序,我目前正在使用 i18next,但它实际上可以是任何翻译库。
  • 我将 react-native-localization 与 V3 一起使用,只是传递了对字符串的引用,它工作正常

标签: react-native internationalization translation react-native-navigation wix-react-native-navigation


【解决方案1】:
// get t function somewhere, i.e.
const t = i18next.t:

Settings.options = {
  topBar: {
    title: {
      text: t('settings.title'),
    },
  },
};

在更改语言时,请确保再次执行此代码部分...以便 t() 函数可以再次评估。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    • 2014-04-15
    • 2019-01-12
    • 1970-01-01
    • 2011-10-23
    • 2017-01-09
    • 1970-01-01
    相关资源
    最近更新 更多