Creation:2026-01-21Last update:2026-01-21
将此文档参考到您的 AI 助手ChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
使用您最喜欢的AI助手总结文档,并引用此页面和AI提供商
版本历史
- "统一了所有导出的文档"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
IntlayerProvider 组件文档
The IntlayerProvider is the root component that provides the internationalization context to your Solid application. It manages the current locale state and ensures that all child components can access translations.
用法
tsx
复制代码
复制代码到剪贴板
import { IntlayerProvider } from "solid-intlayer";const App = () => ( <IntlayerProvider> <MyComponent /> </IntlayerProvider>);描述
IntlayerProvider 扮演以下角色:
- 状态管理: 它使用 signals 初始化并存储当前的 locale,以实现响应性。
- Locale 解析: 它根据 cookies、浏览器偏好或默认配置确定初始的 locale。
- 上下文注入: 它通过像
useIntlayer或useLocale这样的 hooks 将 locale 和setLocale函数提供给任何组件。 - 持久化: 它会自动将 locale 更改与 cookies 或 localStorage 同步,以在会话间保持用户偏好。
属性
- locale (可选): 手动设置当前的 locale。
- defaultLocale (可选): 覆盖配置中的默认语言。
- setLocale (可选): 提供自定义的语言设置函数。
- disableEditor (可选): 禁用可视化编辑器集成。
- isCookieEnabled (可选): 启用或禁用 cookie 持久化。