首页 > 解决方案 > 如何在 iOS 中使用 EXPO/react-native 实现 RTL

问题描述

我在我的反应原生应用程序文件名中添加了两个本地化文件(阿拉伯语和英语),如ar.jsonen.json

我的en.json文件看起来像

"fieldNames": {
    "enterEmail" : "Enter the email address"
  },

我的ar.json文件看起来像

"fieldNames": {
    "enterEmail" : "أدخل عنوان البريد الإلكتروني"
  },

我的string/index.js文件如下所示:

import * as Localization from 'expo-localization';
import i18n from 'i18n-js';

import en from './en.json';
import ar from './ar.json';

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

export const string = value => i18n.t(value);

export default i18n;

我使用的文件之一如下

<Text>{string('fieldNames.enterEmail')}</Text>

本地化适用于两种语言。

但是当我选择阿拉伯语时,它不会与 iOS 中的右侧对齐。

在我的 android 设备中,它工作正常。此问题仅出现在 iOS 中。

你能帮我解决这个问题吗

标签: androidiosreactjsreact-nativeexpo

解决方案


RTL 与 Localization(l10n) 无关。相反,Internalization(i18n) 确实如此。

如果您使用startandright前缀而不是leftand right,那么您的 RTL 将被实现。

例如,您可以使用marginStart代替marginLeftRTL


推荐阅读