Localize antd DatePicker to Chinese via ConfigProvider
Adds a Providers client component that wraps the app in ConfigProvider locale=zhCN and sets dayjs zh-cn locale, so the date-filter RangePicker shows Chinese weekdays/months (and other antd components localize too). Framework-native; no custom control. Not deployed. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
|
import { Providers } from "./providers";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Web Table - 压力表合同生产数据",
|
title: "Web Table - 压力表合同生产数据",
|
||||||
@@ -13,7 +14,9 @@ export default function RootLayout({
|
|||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<body>{children}</body>
|
<body>
|
||||||
|
<Providers>{children}</Providers>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/app/providers.tsx
Normal file
13
src/app/providers.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { ConfigProvider } from "antd";
|
||||||
|
import zhCN from "antd/locale/zh_CN";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import "dayjs/locale/zh-cn";
|
||||||
|
|
||||||
|
// antd v6 DatePicker 基于 dayjs;设置 dayjs 中文 locale 后,日期面板的月份/星期才会显示中文。
|
||||||
|
dayjs.locale("zh-cn");
|
||||||
|
|
||||||
|
export function Providers({ children }: { children: React.ReactNode }) {
|
||||||
|
return <ConfigProvider locale={zhCN}>{children}</ConfigProvider>;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user