mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 03:59:01 +08:00
docs: update DatePicker locale instruction (#48111)
This commit is contained in:
parent
18dc816e55
commit
268d6018a8
@ -65,19 +65,6 @@ The default locale is en-US, if you need to use other languages, recommend to us
|
||||
|
||||
If there are special needs (only modifying single component language), Please use the property: local. Example: [default](https://github.com/ant-design/ant-design/blob/master/components/date-picker/locale/example.json).
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
:::warning
|
||||
When use with Next.js App Router, make sure to add `'use client'` before import locale file of dayjs. It's because all components of Ant Design only works in client, importing locale in RSC will not work.
|
||||
:::
|
||||
|
||||
```jsx
|
||||
import locale from 'antd/es/date-picker/locale/zh_CN';
|
||||
|
||||
import 'dayjs/locale/zh-cn';
|
||||
|
||||
<DatePicker locale={locale} />;
|
||||
```
|
||||
|
||||
```jsx
|
||||
// The default locale is en-US, if you want to use other locale, just set locale in entry file globally.
|
||||
// Make sure you import the relevant dayjs file as well, otherwise the locale won't change for all texts (e.g. range picker months)
|
||||
@ -86,11 +73,18 @@ import dayjs from 'dayjs';
|
||||
|
||||
import 'dayjs/locale/zh-cn';
|
||||
|
||||
dayjs.locale('zh-cn');
|
||||
|
||||
<ConfigProvider locale={locale}>
|
||||
<DatePicker defaultValue={dayjs('2015-01-01', 'YYYY-MM-DD')} />
|
||||
</ConfigProvider>;
|
||||
```
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
:::warning
|
||||
When use with Next.js App Router, make sure to add `'use client'` before import locale file of dayjs. It's because all components of Ant Design only works in client, importing locale in RSC will not work.
|
||||
:::
|
||||
|
||||
### Common API
|
||||
|
||||
The following APIs are shared by DatePicker, RangePicker.
|
||||
|
@ -66,19 +66,6 @@ demo:
|
||||
|
||||
如有特殊需求(仅修改单一组件的语言),请使用 locale 参数,参考:[默认配置](https://github.com/ant-design/ant-design/blob/master/components/date-picker/locale/example.json)。
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
:::warning
|
||||
在搭配 Next.js 的 App Router 使用时,注意在引入 dayjs 的 locale 文件时加上 `'use client'`。这是由于 Ant Design 的组件都是客户端组件,在 RSC 中引入 dayjs 的 locale 文件将不会在客户端生效。
|
||||
:::
|
||||
|
||||
```jsx
|
||||
import locale from 'antd/es/date-picker/locale/zh_CN';
|
||||
|
||||
import 'dayjs/locale/zh-cn';
|
||||
|
||||
<DatePicker locale={locale} />;
|
||||
```
|
||||
|
||||
```jsx
|
||||
// 默认语言为 en-US,如果你需要设置其他语言,推荐在入口文件全局设置 locale
|
||||
// 确保还导入相关的 dayjs 文件,否则所有文本的区域设置都不会更改(例如范围选择器月份)
|
||||
@ -87,11 +74,18 @@ import dayjs from 'dayjs';
|
||||
|
||||
import 'dayjs/locale/zh-cn';
|
||||
|
||||
dayjs.locale('zh-cn');
|
||||
|
||||
<ConfigProvider locale={locale}>
|
||||
<DatePicker defaultValue={dayjs('2015-01-01', 'YYYY-MM-DD')} />
|
||||
</ConfigProvider>;
|
||||
```
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
:::warning
|
||||
在搭配 Next.js 的 App Router 使用时,注意在引入 dayjs 的 locale 文件时加上 `'use client'`。这是由于 Ant Design 的组件都是客户端组件,在 RSC 中引入 dayjs 的 locale 文件将不会在客户端生效。
|
||||
:::
|
||||
|
||||
### 共同的 API
|
||||
|
||||
以下 API 为 DatePicker、 RangePicker 共享的 API。
|
||||
|
@ -135,6 +135,8 @@ type InputRef = GetRef<typeof Input>;
|
||||
Please check whether you have imported dayjs locale correctly.
|
||||
|
||||
```jsx
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import 'dayjs/locale/zh-cn';
|
||||
|
||||
dayjs.locale('zh-cn');
|
||||
|
@ -163,6 +163,8 @@ type InputRef = GetRef<typeof Input>;
|
||||
请检查是否正确设置了 dayjs 语言包。
|
||||
|
||||
```js
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import 'dayjs/locale/zh-cn';
|
||||
|
||||
dayjs.locale('zh-cn');
|
||||
|
Loading…
Reference in New Issue
Block a user