I18nManager
I18nManager 模块提供用于管理阿拉伯语、希伯来语等语言从右到左 (RTL) 布局支持的实用程序。它提供了控制 RTL 行为和检查当前布局方向的方法。
¥The I18nManager module provides utilities for managing Right-to-Left (RTL) layout support for languages like Arabic, Hebrew, and others. It provides methods to control RTL behavior and check the current layout direction.
示例
¥Examples
基于 RTL 更改位置和动画
¥Change positions and animations based on RTL
如果你将元素绝对定位以与其他 Flexbox 元素对齐,则它们在 RTL 语言中可能无法对齐。使用 isRTL 可用于调整对齐或动画。
¥If you absolutely position elements to align with other flexbox elements, they may not align in RTL languages. Using isRTL can be used to adjust alignment or animations.
开发过程中
¥During Development
参考
¥Reference
属性
¥Properties
isRTL
static isRTL: boolean;
一个布尔值,指示应用当前是否处于 RTL 布局模式。
¥A boolean value indicating whether the app is currently in RTL layout mode.
isRTL 的值由以下逻辑确定:
¥The value of isRTL is determined by the following logic:
-
如果
forceRTL等于true,则isRTL返回true¥If
forceRTListrue,isRTLreturnstrue -
如果
allowRTL等于false,则isRTL返回false¥If
allowRTLisfalse,isRTLreturnsfalse -
否则,在以下情况下,
isRTL将变为true:¥Otherwise,
isRTLwill betruegiven the following:-
iOS:
-
设备上用户首选的语言是 RTL 语言。
¥The user-preferred language on the device is an RTL language
-
应用定义的本地化包含用户选择的语言(如 Xcode 项目文件 (
knownRegions = (...)) 中所定义)¥The application-defined localizations include the user-chosen language (as defined in the Xcode project file (
knownRegions = (...))
-
-
安卓:
¥Android:
-
设备上用户首选的语言是 RTL 语言。
¥The user-preferred language on the device is an RTL language
-
应用的
AndroidManifest.xml在<application>元素上定义了android:supportsRTL="true"¥The application's
AndroidManifest.xmldefinesandroid:supportsRTL="true"on the<application>element
-
-
doLeftAndRightSwapInRTL
static doLeftAndRightSwapInRTL: boolean;
一个布尔值,指示在 RTL 模式下是否应自动交换左右样式属性。启用后,在 RTL 布局中,左侧将变为右侧,右侧将变为左侧。
¥A boolean value indicating whether left and right style properties should be automatically swapped when in RTL mode. When enabled, left becomes right and right becomes left in RTL layouts.
方法
¥Methods
allowRTL()
static allowRTL: (allowRTL: boolean) => void;
启用或禁用应用的 RTL 布局支持。
¥Enables or disables RTL layout support for the application.
参数:
¥Parameters:
-
allowRTL(布尔值):是否允许 RTL 布局¥
allowRTL(boolean): Whether to allow RTL layout
重要提示:
¥Important Notes:
-
更改将在下次应用启动时生效,而非立即生效
¥Changes take effect on the next application start, not immediately
-
此设置在应用重启后仍然有效。
¥This setting is persisted across app restarts
forceRTL()
static forceRTL: (forced: boolean) => void;
强制应用使用 RTL 布局,无论设备语言设置如何。这主要用于在开发过程中测试 RTL 布局。
¥Forces the app to use RTL layout regardless of the device language settings. This is primarily useful for testing RTL layouts during development.
避免在生产环境中强制使用 RTL,因为这需要完全重启应用才能生效,从而影响用户体验。
¥Avoid forcing RTL in production apps as it requires a full app restart to take effect, which makes for a poor user-experience.
参数:
¥Parameters:
-
forced(布尔值):是否强制 RTL 布局¥
forced(boolean): Whether to force RTL layout
重要提示:
¥Important Notes:
-
更改将在下次应用启动时完全生效,而非立即生效
¥Changes take full effect on the next application start, not immediately
-
此设置在应用重启后保持不变。
¥The setting is persisted across app restarts
-
仅用于开发和测试。在生产环境中,你应该完全禁用 RTL 或对其进行适当处理(参见
isRTL)。¥Only meant for development and testing. In production, you should either disallow RTL fully or handle it appropriately (see
isRTL)
swapLeftAndRightInRTL()
static swapLeftAndRightInRTL: (swapLeftAndRight: boolean) => void;
在 RTL 模式下交换左右样式属性。启用后,在 RTL 布局中,左侧将变为右侧,右侧将变为左侧。不影响 isRTL 的值。
¥Swap left and right style properties in RTL mode. When enabled, left becomes right and right becomes left in RTL layouts. Does not affect the value of isRTL.