【问题标题】:Proper use of i18n in react native and impact on performance在 react native 中正确使用 i18n 并影响性能
【发布时间】:2022-06-17 12:29:44
【问题描述】:

我在我的 react 应用程序中使用 i18n,我想知道如何在我的屏幕上正确使用。我目前在我的 App.js 中设置了基础,如下所示:

import * as Localization from "expo-localization";
import i18n from "i18n-js";
import {de} from "./locales/de";
import {en} from "./locales/en";
import {fr} from "./locales/fr";


i18n.fallbacks = true;
i18n.translations = { en, de, fr };
i18n.locale = Localization.locale;

到目前为止一切顺利。在我的屏幕上,我像这样使用 i18n:

import i18n from "i18n-js";
import {de} from "../../../locales/de";
import {en} from "../../../locales/en";
import {fr} from "../../../locales/fr";

i18n.fallbacks = true;
i18n.translations = { en, de, fr };

...

<Text> {i18n.t("Welcome")} </Text>

这是正确的做法吗?我将拥有数百个屏幕和大量文本。所以在每个屏幕上以这种方式加载所有内容让我感觉......不舒服......它会对性能产生很大影响吗?使用 useContext 会更好吗?

另外:语言文件有多长?我应该为不同的内容创建几个英文文件吗?

我对你的想法很感兴趣!

谢谢

【问题讨论】:

  • 请去掉 i18next 标签,这与 i18next 无关
  • 我删除了它:-)

标签: react-native internationalization translation


【解决方案1】:

我正在使用与您相同的方法。 在IOS上一切都很好。 但在 Android 上,当我调度 redux 操作以修改 settingsScreen 中的语言时,我注意到了性能问题。

我在 TouchableOpacity 组件上尝试了 delayPressIn={0} 和 delayPressOut={0}。使用来自 react-native-paper 的 Button 和 TouchableRipple 没有成功。 请,

【讨论】:

    猜你喜欢
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 2021-03-17
    • 2020-05-16
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多