Creation:2026-01-21Last update:2026-06-25
将此文档参考到您的 AI 助手ChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
使用您最喜欢的AI助手总结文档,并引用此页面和AI提供商
版本历史
- "重新导出完整的 react-intlayer API(hook、工具、format/html/markdown 子路径),使 React Native 应用只需依赖 react-native-intlayer"v9.0.02026/6/25
- "统一所有导出的文档"v8.0.02026/1/21
此页面的内容已使用 AI 翻译。
查看英文原文的最新版本Edit this doc
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy
Copy doc Markdown to clipboard
react-native-intlayer 包
react-native-intlayer 包提供将 Intlayer 集成到 React Native 应用中所需的工具。它重新导出完整的 react-intlayer API(hook 和工具),并提供适用于 React Native 的 IntlayerProvider,以及 React Native 所需的 polyfill 和 Metro 配置。
在 React Native 应用中,请从react-native-intlayer导入所有内容。您无需直接安装或导入react-intlayer。
安装
bash
复制代码
复制代码到剪贴板
npm install react-native-intlayer导出
Provider 组件
显示表格的所有内容
在弹窗中打开表格以清晰地查看所有数据
| 组件 | 说明 |
|---|---|
IntlayerProvider | 包裹应用并提供 Intlayer 上下文的 Provider 组件。自动应用所需的 polyfill。 |
tsx
复制代码
复制代码到剪贴板
import { IntlayerProvider } from "react-native-intlayer";Hook 和工具
这些内容从 react-intlayer 重新导出,因此您可以直接从 react-native-intlayer 导入:
显示表格的所有内容
在弹窗中打开表格以清晰地查看所有数据
| 导出 | 说明 |
|---|---|
useIntlayer | 访问字典键的本地化内容。 |
useLocale | 读取和更改当前语言环境。 |
useDictionary, useDictionaryAsync, useDictionaryDynamic, useLoadDynamic | 以多种方式加载字典内容。 |
useI18n | 兼容 i18next 的 hook。 |
t | 内联翻译助手。 |
getIntlayer, getDictionary | 命令式内容获取器。 |
localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage | 语言环境持久化助手。 |
tsx
复制代码
复制代码到剪贴板
import { useIntlayer, useLocale, t } from "react-native-intlayer";Polyfill
显示表格的所有内容
在弹窗中打开表格以清晰地查看所有数据
| 函数 | 说明 |
|---|---|
intlayerPolyfill | 为 React Native 应用启用 Intlayer 所需的 polyfill 的函数。 |
tsx
复制代码
复制代码到剪贴板
import { intlayerPolyfill } from "react-native-intlayer";当您导入IntlayerProvider时,polyfill 会自动应用。仅当您需要在 provider 挂载之前使用 polyfill 时,才需要手动调用intlayerPolyfill。
格式化工具
数字、日期及其他基于 Intl 的格式化 hook 可从 /format 子路径获取:
tsx
复制代码
复制代码到剪贴板
import { useNumber, useDate } from "react-native-intlayer/format";Markdown 和 HTML 渲染
tsx
复制代码
复制代码到剪贴板
import { MarkdownProvider } from "react-native-intlayer/markdown";import { HTMLProvider } from "react-native-intlayer/html";Metro 配置
react-native-intlayer 包提供 Metro 配置工具,以确保 Intlayer 在 React Native 中正常工作。
显示表格的所有内容
在弹窗中打开表格以清晰地查看所有数据
| 函数 | 描述 |
|---|---|
configMetroIntlayer | 异步函数,准备 Intlayer 并合并 Metro 配置。 |
configMetroIntlayerSync | 同步函数,合并 Metro 配置但不准备 Intlayer 资源。 |
exclusionList | 为 Metro 的 blockList 创建一个 RegExp 模式,以在打包时排除内容文件。 |
tsx
复制代码
复制代码到剪贴板
import { configMetroIntlayer } from "react-native-intlayer/metro";