refactor: locale files reference path (#38194)

* chore: add locale files to npm pkg

* docs: locale files reference path

* docs: fix locale path

* chore: bump @ant-design/tools

* refactor: default locale file

* chore: add site wepack alias

* chore: bump @ant-design/tools

* fix: site theme locale reference path

* chore: add locale files to eslint ignore

* fix: markdown demo unable to resolve path to module antd/locale
This commit is contained in:
Chuns Chen 2022-10-26 14:38:54 +08:00 committed by GitHub
parent ffc09a2a0d
commit cc5c4fed51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 170 additions and 167 deletions

View File

@ -22,6 +22,7 @@ site/theme/template/NotFound.jsx
typings
es/**/*
lib/**/*
locale
node_modules
_site
dist

View File

@ -20,6 +20,9 @@ module.exports = {
version: 'detect',
},
polyfills: ['Promise', 'URL'],
'import/resolver': {
typescript: {},
},
},
parser: '@typescript-eslint/parser',
plugins: ['react', 'babel', 'jest', '@typescript-eslint', 'react-hooks', 'unicorn', 'markdown'],

1
.gitignore vendored
View File

@ -28,6 +28,7 @@ dist
report.html
/lib
/es
/locale
elasticsearch-*
config/base.yaml
/.vscode/

View File

@ -31,8 +31,8 @@ import {
} from 'antd';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import enUS from 'antd/es/locale/en_US';
import zhCN from 'antd/es/locale/zh_CN';
import enUS from 'antd/locale/en_US';
import zhCN from 'antd/locale/zh_CN';
import React, { useState } from 'react';
dayjs.locale('en');

View File

@ -49,7 +49,7 @@ Some components use dynamic style to support wave effect. You can config `csp` p
| getTargetContainer | Config Affix, Anchor scroll target container | () => HTMLElement | () => window | 4.2.0 |
| iconPrefixCls | Set icon prefix className (cooperated with [@iconfont-css-prefix](https://github.com/ant-design/ant-design/blob/d943b85a523bdf181dabc12c928226f3b4b893de/components/style/themes/default.less#L106)) | string | `anticon` | 4.11.0 |
| input | Set Input common props | { autoComplete?: string } | - | 4.2.0 |
| locale | Language package setting, you can find the packages in [antd/es/locale](http://unpkg.com/antd/es/locale/) | object | - | |
| locale | Language package setting, you can find the packages in [antd/locale](http://unpkg.com/antd/locale/) | object | - | |
| pageHeader | Unify the ghost of PageHeader, ref [PageHeader](/components/page-header) | { ghost: boolean } | true | |
| prefixCls | Set prefix className (cooperated with [@ant-prefix](https://github.com/ant-design/ant-design/blob/2c6c789e3a9356f96c47aea0083f5a15538315cf/components/style/themes/default.less#L7)) | string | `ant` | |
| renderEmpty | Set empty content of components. Ref [Empty](/components/empty/) | function(componentName: string): ReactNode | - | |

View File

@ -8,7 +8,7 @@ import type { RequiredMark } from '../form/Form';
import type { Locale } from '../locale-provider';
import LocaleProvider, { ANT_MARK } from '../locale-provider';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale/default';
import defaultLocale from '../locale/en_US';
import { DesignTokenContext } from '../theme';
import defaultSeedToken from '../theme/themes/seed';
import type { ConfigConsumerProps, CSPConfig, DirectionType, Theme, ThemeConfig } from './context';

View File

@ -50,7 +50,7 @@ export default () => (
| getTargetContainer | 配置 Affix、Anchor 滚动监听容器。 | () => HTMLElement | () => window | 4.2.0 |
| iconPrefixCls | 设置图标统一样式前缀。注意:需要配合 `less` 变量 [@iconfont-css-prefix](https://github.com/ant-design/ant-design/blob/d943b85a523bdf181dabc12c928226f3b4b893de/components/style/themes/default.less#L106) 使用 | string | `anticon` | 4.11.0 |
| input | 设置 Input 组件的通用属性 | { autoComplete?: string } | - | 4.2.0 |
| locale | 语言包配置,语言包可到 [antd/es/locale](http://unpkg.com/antd/es/locale/) 目录下寻找 | object | - | |
| locale | 语言包配置,语言包可到 [antd/locale](http://unpkg.com/antd/locale/) 目录下寻找 | object | - | |
| pageHeader | 统一设置 PageHeader 的 ghost参考 [PageHeader](/components/page-header) | { ghost: boolean } | true | |
| prefixCls | 设置统一样式前缀。注意:需要配合 `less` 变量 [@ant-prefix](https://github.com/ant-design/ant-design/blob/2c6c789e3a9356f96c47aea0083f5a15538315cf/components/style/themes/default.less#L7) 使用 | string | `ant` | |
| renderEmpty | 自定义组件空状态。参考 [空状态](/components/empty/) | function(componentName: string): ReactNode | - | |

View File

@ -39,7 +39,7 @@ import locale from 'antd/es/date-picker/locale/zh_CN';
// The default locale is en-US, if you want to use other locale, just set locale in entry file globally.
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import locale from 'antd/es/locale/zh_CN';
import locale from 'antd/locale/zh_CN';
<ConfigProvider locale={locale}>
<DatePicker defaultValue={dayjs('2015-01-01', 'YYYY-MM-DD')} />

View File

@ -40,7 +40,7 @@ import locale from 'antd/es/date-picker/locale/zh_CN';
// 默认语言为 en-US如果你需要设置其他语言推荐在入口文件全局设置 locale
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import locale from 'antd/es/locale/zh_CN';
import locale from 'antd/locale/zh_CN';
<ConfigProvider locale={locale}>
<DatePicker defaultValue={dayjs('2015-01-01', 'YYYY-MM-DD')} />

View File

@ -4,7 +4,7 @@ import * as React from 'react';
import type { ColProps } from '../grid/col';
import Col from '../grid/col';
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale/default';
import defaultLocale from '../locale/en_US';
import type { TooltipProps } from '../tooltip';
import Tooltip from '../tooltip';
import type { FormContextProps } from './context';

View File

@ -2,7 +2,7 @@ import * as React from 'react';
import type { Locale } from '.';
import type { LocaleContextProps } from './context';
import LocaleContext from './context';
import defaultLocaleData from './default';
import defaultLocaleData from '../locale/en_US';
export type LocaleComponentName = Exclude<keyof Locale, 'locale'>;

View File

@ -1,3 +0,0 @@
import locale from '../locale/default';
export default locale;

View File

@ -1,136 +0,0 @@
/* eslint-disable no-template-curly-in-string */
import Pagination from 'rc-pagination/lib/locale/en_US';
import Calendar from '../calendar/locale/en_US';
import DatePicker from '../date-picker/locale/en_US';
import type { Locale } from '../locale-provider';
import TimePicker from '../time-picker/locale/en_US';
const typeTemplate = '${label} is not a valid ${type}';
const localeValues: Locale = {
locale: 'en',
Pagination,
DatePicker,
TimePicker,
Calendar,
global: {
placeholder: 'Please select',
},
Table: {
filterTitle: 'Filter menu',
filterConfirm: 'OK',
filterReset: 'Reset',
filterEmptyText: 'No filters',
filterCheckall: 'Select all items',
filterSearchPlaceholder: 'Search in filters',
emptyText: 'No data',
selectAll: 'Select current page',
selectInvert: 'Invert current page',
selectNone: 'Clear all data',
selectionAll: 'Select all data',
sortTitle: 'Sort',
expand: 'Expand row',
collapse: 'Collapse row',
triggerDesc: 'Click to sort descending',
triggerAsc: 'Click to sort ascending',
cancelSort: 'Click to cancel sorting',
},
Modal: {
okText: 'OK',
cancelText: 'Cancel',
justOkText: 'OK',
},
Popconfirm: {
okText: 'OK',
cancelText: 'Cancel',
},
Transfer: {
titles: ['', ''],
searchPlaceholder: 'Search here',
itemUnit: 'item',
itemsUnit: 'items',
remove: 'Remove',
selectCurrent: 'Select current page',
removeCurrent: 'Remove current page',
selectAll: 'Select all data',
removeAll: 'Remove all data',
selectInvert: 'Invert current page',
},
Upload: {
uploading: 'Uploading...',
removeFile: 'Remove file',
uploadError: 'Upload error',
previewFile: 'Preview file',
downloadFile: 'Download file',
},
Empty: {
description: 'No Data',
},
Icon: {
icon: 'icon',
},
Text: {
edit: 'Edit',
copy: 'Copy',
copied: 'Copied',
expand: 'Expand',
},
PageHeader: {
back: 'Back',
},
Form: {
optional: '(optional)',
defaultValidateMessages: {
default: 'Field validation error for ${label}',
required: 'Please enter ${label}',
enum: '${label} must be one of [${enum}]',
whitespace: '${label} cannot be a blank character',
date: {
format: '${label} date format is invalid',
parse: '${label} cannot be converted to a date',
invalid: '${label} is an invalid date',
},
types: {
string: typeTemplate,
method: typeTemplate,
array: typeTemplate,
object: typeTemplate,
number: typeTemplate,
date: typeTemplate,
boolean: typeTemplate,
integer: typeTemplate,
float: typeTemplate,
regexp: typeTemplate,
email: typeTemplate,
url: typeTemplate,
hex: typeTemplate,
},
string: {
len: '${label} must be ${len} characters',
min: '${label} must be at least ${min} characters',
max: '${label} must be up to ${max} characters',
range: '${label} must be between ${min}-${max} characters',
},
number: {
len: '${label} must be equal to ${len}',
min: '${label} must be minimum ${min}',
max: '${label} must be maximum ${max}',
range: '${label} must be between ${min}-${max}',
},
array: {
len: 'Must be ${len} ${label}',
min: 'At least ${min} ${label}',
max: 'At most ${max} ${label}',
range: 'The amount of ${label} must be between ${min}-${max}',
},
pattern: {
mismatch: '${label} does not match the pattern ${pattern}',
},
},
},
Image: {
preview: 'Preview',
},
};
export default localeValues;

View File

@ -1,3 +1,136 @@
import defaultLocale from './default';
/* eslint-disable no-template-curly-in-string */
import Pagination from 'rc-pagination/lib/locale/en_US';
import Calendar from '../calendar/locale/en_US';
import DatePicker from '../date-picker/locale/en_US';
import type { Locale } from '../locale-provider';
import TimePicker from '../time-picker/locale/en_US';
export default defaultLocale;
const typeTemplate = '${label} is not a valid ${type}';
const localeValues: Locale = {
locale: 'en',
Pagination,
DatePicker,
TimePicker,
Calendar,
global: {
placeholder: 'Please select',
},
Table: {
filterTitle: 'Filter menu',
filterConfirm: 'OK',
filterReset: 'Reset',
filterEmptyText: 'No filters',
filterCheckall: 'Select all items',
filterSearchPlaceholder: 'Search in filters',
emptyText: 'No data',
selectAll: 'Select current page',
selectInvert: 'Invert current page',
selectNone: 'Clear all data',
selectionAll: 'Select all data',
sortTitle: 'Sort',
expand: 'Expand row',
collapse: 'Collapse row',
triggerDesc: 'Click to sort descending',
triggerAsc: 'Click to sort ascending',
cancelSort: 'Click to cancel sorting',
},
Modal: {
okText: 'OK',
cancelText: 'Cancel',
justOkText: 'OK',
},
Popconfirm: {
okText: 'OK',
cancelText: 'Cancel',
},
Transfer: {
titles: ['', ''],
searchPlaceholder: 'Search here',
itemUnit: 'item',
itemsUnit: 'items',
remove: 'Remove',
selectCurrent: 'Select current page',
removeCurrent: 'Remove current page',
selectAll: 'Select all data',
removeAll: 'Remove all data',
selectInvert: 'Invert current page',
},
Upload: {
uploading: 'Uploading...',
removeFile: 'Remove file',
uploadError: 'Upload error',
previewFile: 'Preview file',
downloadFile: 'Download file',
},
Empty: {
description: 'No Data',
},
Icon: {
icon: 'icon',
},
Text: {
edit: 'Edit',
copy: 'Copy',
copied: 'Copied',
expand: 'Expand',
},
PageHeader: {
back: 'Back',
},
Form: {
optional: '(optional)',
defaultValidateMessages: {
default: 'Field validation error for ${label}',
required: 'Please enter ${label}',
enum: '${label} must be one of [${enum}]',
whitespace: '${label} cannot be a blank character',
date: {
format: '${label} date format is invalid',
parse: '${label} cannot be converted to a date',
invalid: '${label} is an invalid date',
},
types: {
string: typeTemplate,
method: typeTemplate,
array: typeTemplate,
object: typeTemplate,
number: typeTemplate,
date: typeTemplate,
boolean: typeTemplate,
integer: typeTemplate,
float: typeTemplate,
regexp: typeTemplate,
email: typeTemplate,
url: typeTemplate,
hex: typeTemplate,
},
string: {
len: '${label} must be ${len} characters',
min: '${label} must be at least ${min} characters',
max: '${label} must be up to ${max} characters',
range: '${label} must be between ${min}-${max} characters',
},
number: {
len: '${label} must be equal to ${len}',
min: '${label} must be minimum ${min}',
max: '${label} must be maximum ${max}',
range: '${label} must be between ${min}-${max}',
},
array: {
len: 'Must be ${len} ${label}',
min: 'At least ${min} ${label}',
max: 'At most ${max} ${label}',
range: 'The amount of ${label} must be between ${min}-${max}',
},
pattern: {
mismatch: '${label} does not match the pattern ${pattern}',
},
},
},
Image: {
preview: 'Preview',
},
};
export default localeValues;

View File

@ -4,7 +4,7 @@ import DatePicker from '../date-picker/locale/kmr_IQ';
import type { Locale } from '../locale-provider';
import TimePicker from '../time-picker/locale/kmr_IQ';
// please use antd/lib/locale/kmr_IQ instead
// please use antd/locale/kmr_IQ instead
// keep this file for compatibility
// https://github.com/ant-design/ant-design/issues/25778

View File

@ -1,4 +1,4 @@
import defaultLocale from '../locale/default';
import defaultLocale from '../locale/en_US';
export interface ModalLocale {
okText: string;

View File

@ -1,7 +1,7 @@
import * as React from 'react';
import { ConfigContext } from '../../config-provider';
import LocaleReceiver from '../../locale-provider/LocaleReceiver';
import defaultLocale from '../../locale/default';
import defaultLocale from '../../locale/en_US';
import ConfirmDialog from '../ConfirmDialog';
import type { ModalFuncProps } from '../Modal';

View File

@ -6,7 +6,7 @@ import Button from '../button';
import { convertLegacyProps } from '../button/button';
import ActionButton from '../_util/ActionButton';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale/default';
import defaultLocale from '../locale/en_US';
import { getRenderPropValue } from '../_util/getRenderPropValue';
import { ConfigContext } from '../config-provider';
import PopoverPurePanel from '../popover/PurePanel';

View File

@ -74,7 +74,7 @@ const columns = [
| footer | Table footer renderer | function(currentPageData) | - | |
| getPopupContainer | The render container of dropdowns in table | (triggerNode) => HTMLElement | () => TableHtmlElement | |
| loading | Loading status of table | boolean \| [Spin Props](/components/spin/#API) | false | |
| locale | The i18n text including filter, sort, empty text, etc | object | [Default Value](https://github.com/ant-design/ant-design/blob/6dae4a7e18ad1ba193aedd5ab6867e1d823e2aa4/components/locale/default.tsx#L19-L37) | |
| locale | The i18n text including filter, sort, empty text, etc | object | [Default Value](https://github.com/ant-design/ant-design/blob/6dae4a7e18ad1ba193aedd5ab6867e1d823e2aa4/components/locale/en_US.tsx#L19-L37) | |
| pagination | Config of pagination. You can ref table pagination [config](#pagination) or full [`pagination`](/components/pagination/) document, hide it by setting it to `false` | object | - | |
| rowClassName | Row's className | function(record, index): string | - | |
| rowKey | Row's unique key, could be a string or function that returns a string | string \| function(record): string | `key` | |

View File

@ -4,7 +4,7 @@ import * as React from 'react';
import type { KeyWiseTransferItem } from '.';
import Checkbox from '../checkbox';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale/default';
import defaultLocale from '../locale/en_US';
import TransButton from '../_util/transButton';
type ListItemProps<RecordType> = {

View File

@ -5,7 +5,7 @@ import { ConfigConsumer } from '../config-provider';
import defaultRenderEmpty from '../config-provider/defaultRenderEmpty';
import { FormItemInputContext } from '../form/context';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale/default';
import defaultLocale from '../locale/en_US';
import type { InputStatus } from '../_util/statusUtils';
import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
import warning from '../_util/warning';

View File

@ -7,7 +7,7 @@ import { flushSync } from 'react-dom';
import { ConfigContext } from '../config-provider';
import DisabledContext from '../config-provider/DisabledContext';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale/default';
import defaultLocale from '../locale/en_US';
import warning from '../_util/warning';
import type { RcFile, ShowUploadListInterface, UploadChangeParam, UploadFile } from './interface';
import { UploadProps } from './interface';

View File

@ -36,7 +36,7 @@ import { ConfigProvider, DatePicker, message } from 'antd';
// 由于 antd 组件的默认文案是英文,所以需要修改为中文
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import zhCN from 'antd/es/locale/zh_CN';
import zhCN from 'antd/locale/zh_CN';
import 'antd/dist/antd.css';
import './index.css';

View File

@ -11,7 +11,7 @@ The default language of `antd@2.x` is currently English. If you wish to use othe
```jsx
import { ConfigProvider } from 'antd';
import frFR from 'antd/es/locale/fr_FR';
import frFR from 'antd/locale/fr_FR';
return (
<ConfigProvider locale={frFR}>

View File

@ -10,7 +10,7 @@ title: 国际化
antd 提供了一个 React 组件 [ConfigProvider](/components/config-provider) 用于全局配置国际化文案。
```jsx
import zhCN from 'antd/es/locale/zh_CN';
import zhCN from 'antd/locale/zh_CN';
return (
<ConfigProvider locale={zhCN}>

View File

@ -24,7 +24,7 @@ This document will help you upgrade from antd `4.x` version to antd `5.x` versio
- All less files are removed, and less variables are no longer exported.
- Css files are no longer included in package. Since CSS-in-JS supports importing on demand, the original `antd/dist/antd.css` has also been abandoned. If you need to reset some basic styles, please import `antd/dist/reset.css`.
- Remove css variables and dynamic theme built on top of them.
- Remove `lib`, only provide `dist` and `es` in package.
- Remove `lib`, only provide `dist` and `es` in package, the original `antd/es/locale` has also been abandoned, you can find the packages in `antd/locale`.
- Replace built-in Moment.js with Dayjs. For more: [Use custom date library](/docs/react/use-custom-date-library/).
- `babel-plugin-import` is no longer supported. CSS-in-JS itself has the ability to import on demand, and plugin support is no longer required. Umi users can remove related configurations.

View File

@ -25,7 +25,7 @@ title: 从 v4 到 v5
- 所有 less 文件全部移除less 变量不再支持透出。
- 产物中不再包含 css 文件。由于 CSS-in-JS 支持按需引入,原本的 `antd/dist/antd.css` 也已经移除,如果需要重置一些基本样式请引入 `antd/dist/reset.css`
- 移除 css variables 以及在此之上构筑的动态主题方案。
- 移除 `lib` 产物,只提供 `dist``es` 产物。
- 移除 `lib` 产物,只提供 `dist``es` 产物,原本的 `antd/es/locale` 目录也已经移除,语言包可到 `antd/locale` 目录下寻找
- 内置的时间库使用 Dayjs 替代 Moment.js具体请查看 [使用自定义日期库](/docs/react/use-custom-date-library-cn/)。
- 不再支持 `babel-plugin-import`CSS-in-JS 本身具有按需加载的能力不再需要插件支持。Umi 用户可以移除相关配置。

View File

@ -32,7 +32,8 @@
},
"files": [
"dist",
"es"
"es",
"locale"
],
"sideEffects": [
"*.less"
@ -157,7 +158,7 @@
"devDependencies": {
"@ant-design/bisheng-plugin": "^3.3.0-alpha.4",
"@ant-design/hitu": "^0.0.0-alpha.13",
"@ant-design/tools": "^15.1.2",
"@ant-design/tools": "^15.2.0-alpha.1",
"@docsearch/css": "^3.0.0",
"@qixian.cs/github-contributors-list": "^1.0.3",
"@size-limit/file": "^8.0.0",
@ -209,6 +210,7 @@
"eslint": "^8.0.0",
"eslint-config-airbnb": "^19.0.0",
"eslint-config-prettier": "^8.0.0",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-compat": "^4.0.0",
"eslint-plugin-import": "^2.21.1",

View File

@ -69,6 +69,7 @@ module.exports = {
config.resolve.alias = {
'antd/lib': path.join(process.cwd(), 'components'),
'antd/es': path.join(process.cwd(), 'components'),
'antd/locale': path.join(process.cwd(), 'components/locale'),
// Change antd from `index.js` to `site/antd.js` to remove deps of root style
antd: path.join(process.cwd(), 'site', 'antd'),
site: path.join(process.cwd(), 'site'),

View File

@ -12,7 +12,7 @@ import { createCache, StyleProvider } from '@ant-design/cssinjs';
import type { SeedToken } from 'antd/es/theme';
import classNames from 'classnames';
import { presetDarkPalettes, presetPalettes } from '@ant-design/colors';
import zhCN from 'antd/lib/locale/zh_CN';
import zhCN from 'antd/locale/zh_CN';
import type { DirectionType } from 'antd/es/config-provider';
import enLocale from '../../en-US';
import cnLocale from '../../zh-CN';

View File

@ -4,7 +4,8 @@
"paths": {
"antd": ["components/index.tsx"],
"antd/es/*": ["components/*"],
"antd/lib/*": ["components/*"]
"antd/lib/*": ["components/*"],
"antd/locale/*": ["components/locale/*"]
},
"strictNullChecks": true,
"module": "esnext",