This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo 本土化 iconExpo 本土化

为原生用户本地化信息提供接口的库。

Android
iOS
tvOS
Web
Included in Expo Go
Recommended version:
~58.0.4

expo-localization 让你可以本地化你的应用,为特定地区、语言或文化定制体验。它还提供了访问本地设备上区域信息的功能。使用像 lingui-js、react-i18next、react-intl、i18n-js 或 react-native-intlayer 这样的本地化库配合 expo-localization,你就能为用户打造非常便利的使用体验。

安装

🌐 Installation

Terminal
- npx expo install expo-localization
- yarn expo install expo-localization
- pnpm expo install expo-localization
- bun expo install expo-localization

If you are installing this in an existing React Native app, make sure to install expo in your project.

应用配置中的配置

🌐 Configuration in app config

如果你在项目中使用配置插件(连续原生生成 (CNG)),可以使用其内置的 配置插件 来配置 expo-localization。该插件允许你配置无法在运行时设置并且需要构建新的应用二进制文件才能生效的各种属性。如果你的应用不使用 CNG,那么你需要手动配置该库。

🌐 You can configure expo-localization using its built-in config plugin if you use config plugins in your project (Continuous Native Generation (CNG)). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect. If your app does not use CNG, then you'll need to manually configure the library.

Example app.json with config plugin

app.json
{ "expo": { "plugins": [ [ "expo-localization", { "supportsRTL": true, "forcesRTL": false, "supportedLocales": ["en", "ja"] } ] ] } }

Configurable properties

NameDefaultDescription
supportsRTLtrue

Whether the app allows RTL layout. When enabled, the app renders in RTL for RTL device languages, following React Native's I18nManager.

forcesRTLfalse

Whether to force RTL layout regardless of the device language. Useful for testing or for apps localized only for RTL locales.

supportedLocalesundefined

The locales your app supports, used to enable per-app language selection in the system settings. Provide a single array shared by both platforms, or platform-specific ios and android arrays.

用法

🌐 Usage

在本地化指南中查找有关使用 expo-localization 以及添加对从右到左语言支持的更多信息。

🌐 Find more information about using expo-localization and adding support for right-to-left languages in the Localization guide.

应用接口

🌐 API

import { getLocales, getCalendars } from 'expo-localization';

行为

🌐 Behavior

你可以使用同步的 getLocales() 和 getCalendars() 方法获取用户设备的区域设置。在 iOS 上,应用运行期间结果将保持不变。

🌐 You can use synchronous getLocales() and getCalendars() methods to get the locale settings of the user device. On iOS, the results will remain the same while the app is running.

在 Android 上,用户可以在设置中更改区域设置偏好,而无需重启应用。为了保持本地化的最新状态,每次应用返回前台时,都可以重新运行 getLocales() 和 getCalendars() 方法。使用 AppState 来检测这一情况。

🌐 On Android, the user can change locale preferences in Settings without restarting apps. To keep the localization current, you can rerun the getLocales() and getCalendars() methods every time the app returns to the foreground. Use AppState to detect this.

No API data file found, sorry!