Skip to Content
文档

语言环境提供程序

用于全局设置语言环境

用法

¥Usage

LocaleProvider 组件设置应用的语言环境,格式化日期、数字和其他特定于语言环境的数据。

¥The LocaleProvider component sets the locale for your app, formatting dates, numbers, and other locale-specific data.

大多数 Chakra UI 组件读取 LocaleProvider 设置的语言环境。

import { LocaleProvider, useLocaleContext } from "@chakra-ui/react"
<LocaleProvider locale="...">{/* Your App */}</LocaleProvider>

示例

¥Examples

设置语言环境

¥Setting Locale

locale 属性设置为你想要使用的语言环境。

¥Set the locale prop to the locale you want to use.

<LocaleProvider locale="ar-BH">
  <Component />
</LocaleProvider>

阅读语言环境

¥Reading Locale

export const Usage = () => {
  const { locale, dir } = useLocaleContext()
  return <pre>{JSON.stringify({ locale, dir }, null, 2)}</pre>
}

属性

¥Props

PropDefaultType
locale *''en-US''
string

The locale to use for the application.

Previous

标签

Next

FormatNumber