diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 9755fe098d..255b796d55 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -2012,7 +2012,7 @@ timeline: true ```javascript import { LocaleProvider } from 'antd'; - import zhCN from 'antd/lib/locale-provider/zh_CN'; + import zhCN from 'antd/lib/locale/zh_CN'; ReactDOM.render( diff --git a/components/_util/warning.tsx b/components/_util/warning.tsx index 0fdb0b0f27..dd84912745 100644 --- a/components/_util/warning.tsx +++ b/components/_util/warning.tsx @@ -1,6 +1,11 @@ import warning from 'warning'; -const warned: Record = {}; +let warned: Record = {}; + +export function resetWarned() { + warned = {}; +} + export default (valid: boolean, component: string, message: string): void => { if (!valid && !warned[message]) { warning(false, `[antd: ${component}] ${message}`); diff --git a/components/config-provider/demo/locale.md b/components/config-provider/demo/locale.md new file mode 100644 index 0000000000..9cf053f276 --- /dev/null +++ b/components/config-provider/demo/locale.md @@ -0,0 +1,187 @@ +--- +order: 1 +title: + zh-CN: 国际化 + en-US: Locale +--- + +## zh-CN + +此处列出 Ant Design 中需要国际化支持的组件,你可以在演示里切换语言。 + +## en-US + +Components which need localization support are listed here, you can toggle the language in the demo. + +```jsx +import { + ConfigProvider, + Pagination, + DatePicker, + TimePicker, + Calendar, + Popconfirm, + Table, + Modal, + Button, + Select, + Transfer, + Radio, +} from 'antd'; +import zhCN from 'antd/lib/locale/zh_CN'; +import moment from 'moment'; +import 'moment/locale/zh-cn'; + +moment.locale('en'); + +const { Option } = Select; +const { RangePicker } = DatePicker; + +const columns = [ + { + title: 'Name', + dataIndex: 'name', + filters: [ + { + text: 'filter1', + value: 'filter1', + }, + ], + }, + { + title: 'Age', + dataIndex: 'age', + }, +]; + +class Page extends React.Component { + state = { + visible: false, + }; + + showModal = () => { + this.setState({ visible: true }); + }; + + hideModal = () => { + this.setState({ visible: false }); + }; + + render() { + const info = () => { + Modal.info({ + title: 'some info', + content: 'some info', + }); + }; + const confirm = () => { + Modal.confirm({ + title: 'some info', + content: 'some info', + }); + }; + return ( + + + + + + + jack + lucy + + + + + + + + Show Modal + + Show info + Show confirm + + Click to confirm + + + + item.title} /> + + + + + + + + + Locale Modal + + + ); + } +} + +class App extends React.Component { + constructor() { + super(); + this.state = { + locale: null, + }; + } + + changeLocale = e => { + const localeValue = e.target.value; + this.setState({ locale: localeValue }); + if (!localeValue) { + moment.locale('en'); + } else { + moment.locale('zh-cn'); + } + }; + + render() { + const { locale } = this.state; + return ( + + + Change locale of components: + + + English + + + 中文 + + + + + + + + ); + } +} + +ReactDOM.render(, mountNode); +``` + +```css +.locale-components { + border-top: 1px solid #d9d9d9; + padding-top: 16px; +} + +.example { + margin: 16px 0; +} + +.example > * { + margin-right: 8px; +} + +.change-locale { + margin-bottom: 16px; +} +``` diff --git a/components/config-provider/index.en-US.md b/components/config-provider/index.en-US.md index ef7c7528c6..8dc6fcb5eb 100644 --- a/components/config-provider/index.en-US.md +++ b/components/config-provider/index.en-US.md @@ -41,4 +41,5 @@ Some component use dynamic style to support wave effect. You can config `csp` pr | csp | Set [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) config | { nonce: string } | - | 3.13.1 | | renderEmpty | set empty content of components. Ref [Empty](/components/empty/) | Function(componentName: string): ReactNode | - | 3.12.2 | | getPopupContainer | to set the container of the popup element. The default is to create a `div` element in `body`. | Function(triggerNode) | `() => document.body` | 3.11.0 | +| locale | language package setting, you can find the packages in [antd/es/locale](http://unpkg.com/antd/es/locale/) | object | 3.21.0 | | prefixCls | set prefix class | string | ant | 3.12.0 | diff --git a/components/config-provider/index.tsx b/components/config-provider/index.tsx index ca9e600782..024b82b9c9 100644 --- a/components/config-provider/index.tsx +++ b/components/config-provider/index.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import createReactContext from '@ant-design/create-react-context'; import defaultRenderEmpty, { RenderEmptyHandler } from './renderEmpty'; +import LocaleProvider, { Locale, ANT_MARK } from '../locale-provider'; export { RenderEmptyHandler }; @@ -16,6 +17,7 @@ export interface ConfigConsumerProps { renderEmpty: RenderEmptyHandler; csp?: CSPConfig; autoInsertSpaceInButton?: boolean; + locale?: Locale; } export const configConsumerProps = [ @@ -25,6 +27,7 @@ export const configConsumerProps = [ 'renderEmpty', 'csp', 'autoInsertSpaceInButton', + 'locale', ]; export interface ConfigProviderProps { @@ -34,6 +37,7 @@ export interface ConfigProviderProps { renderEmpty?: RenderEmptyHandler; csp?: CSPConfig; autoInsertSpaceInButton?: boolean; + locale?: Locale; } const ConfigContext = createReactContext({ @@ -59,7 +63,14 @@ class ConfigProvider extends React.Component { }; renderProvider = (context: ConfigConsumerProps) => { - const { children, getPopupContainer, renderEmpty, csp, autoInsertSpaceInButton } = this.props; + const { + children, + getPopupContainer, + renderEmpty, + csp, + autoInsertSpaceInButton, + locale, + } = this.props; const config: ConfigConsumerProps = { ...context, @@ -75,7 +86,13 @@ class ConfigProvider extends React.Component { config.renderEmpty = renderEmpty; } - return {children}; + return ( + + + {children} + + + ); }; render() { diff --git a/components/config-provider/index.zh-CN.md b/components/config-provider/index.zh-CN.md index 4db52ca872..f8e1936f1d 100644 --- a/components/config-provider/index.zh-CN.md +++ b/components/config-provider/index.zh-CN.md @@ -42,4 +42,5 @@ return ( | csp | 设置 [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) 配置 | { nonce: string } | - | 3.13.1 | | renderEmpty | 自定义组件空状态。参考 [空状态](/components/empty/) | Function(componentName: string): ReactNode | - | 3.12.2 | | getPopupContainer | 弹出框(Select, Tooltip, Menu 等等)渲染父节点,默认渲染到 body 上。 | Function(triggerNode) | () => document.body | 3.11.0 | +| locale | 语言包配置,语言包可到 [antd/es/locale](http://unpkg.com/antd/es/locale/) 目录下寻找 | object | - | 3.21.0 | | prefixCls | 设置统一样式前缀 | string | ant | 3.12.0 | diff --git a/components/date-picker/index.en-US.md b/components/date-picker/index.en-US.md index 5e1e8614c7..2edc4f2682 100644 --- a/components/date-picker/index.en-US.md +++ b/components/date-picker/index.en-US.md @@ -21,7 +21,7 @@ There are four kinds of picker: ### Localization -The default locale is en-US, if you need to use other languages, recommend to use internationalized components provided by us at the entrance. Look at: [LocaleProvider](http://ant.design/components/locale-provider/). +The default locale is en-US, if you need to use other languages, recommend to use internationalized components provided by us at the entrance. Look at: [ConfigProvider](http://ant.design/components/config-provider/). 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). diff --git a/components/date-picker/index.zh-CN.md b/components/date-picker/index.zh-CN.md index d9576ec652..a171c452b5 100644 --- a/components/date-picker/index.zh-CN.md +++ b/components/date-picker/index.zh-CN.md @@ -22,7 +22,7 @@ subtitle: 日期选择框 ### 国际化配置 -默认配置为 en-US,如果你需要设置其他语言,推荐在入口处使用我们提供的国际化组件,详见:[LocaleProvider 国际化](http://ant.design/components/locale-provider-cn/)。 +默认配置为 en-US,如果你需要设置其他语言,推荐在入口处使用我们提供的国际化组件,详见:[ConfigProvider 国际化](http://ant.design/components/config-provider-cn/)。 如有特殊需求(仅修改单一组件的语言),请使用 locale 参数,参考:[默认配置](https://github.com/ant-design/ant-design/blob/master/components/date-picker/locale/example.json)。 diff --git a/components/locale-provider/__tests__/index.test.js b/components/locale-provider/__tests__/index.test.js index b96b049059..dd7e9de3e9 100644 --- a/components/locale-provider/__tests__/index.test.js +++ b/components/locale-provider/__tests__/index.test.js @@ -3,6 +3,7 @@ import React from 'react'; import { mount } from 'enzyme'; import moment from 'moment'; import MockDate from 'mockdate'; +import { resetWarned } from '../../_util/warning'; import { LocaleProvider, Pagination, @@ -231,4 +232,20 @@ describe('Locale Provider', () => { wrapper.setState({ locale: null }); expect(wrapper.render()).toMatchSnapshot(); }); + + it('warning if use LocaleProvider', () => { + const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + resetWarned(); + + mount( + + + , + ); + expect(errorSpy).toHaveBeenCalledWith( + 'Warning: [antd: LocaleProvider] `LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead: http://u.ant.design/locale', + ); + + errorSpy.mockRestore(); + }); }); diff --git a/components/locale-provider/ar_EG.tsx b/components/locale-provider/ar_EG.tsx index cda0de3d8b..55b7906d95 100644 --- a/components/locale-provider/ar_EG.tsx +++ b/components/locale-provider/ar_EG.tsx @@ -1,42 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/ar_EG'; -import DatePicker from '../date-picker/locale/ar_EG'; -import TimePicker from '../time-picker/locale/ar_EG'; -import Calendar from '../calendar/locale/ar_EG'; +import locale from '../locale/ar_EG'; -export default { - locale: 'ar', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'الفلاتر', - filterConfirm: 'تأكيد', - filterReset: 'إعادة ضبط', - selectAll: 'اختيار الكل', - selectInvert: 'إلغاء الاختيار', - }, - Modal: { - okText: 'تأكيد', - cancelText: 'إلغاء', - justOkText: 'تأكيد', - }, - Popconfirm: { - okText: 'تأكيد', - cancelText: 'إلغاء', - }, - Transfer: { - searchPlaceholder: 'ابحث هنا', - itemUnit: 'عنصر', - itemsUnit: 'عناصر', - }, - Upload: { - uploading: 'جاري الرفع...', - removeFile: 'احذف الملف', - uploadError: 'مشكلة فى الرفع', - previewFile: 'استعرض الملف', - }, - Empty: { - description: 'لا توجد بيانات', - }, -}; +export default locale; diff --git a/components/locale-provider/bg_BG.tsx b/components/locale-provider/bg_BG.tsx index da7b281532..2cf89f06a4 100644 --- a/components/locale-provider/bg_BG.tsx +++ b/components/locale-provider/bg_BG.tsx @@ -1,42 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/bg_BG'; -import DatePicker from '../date-picker/locale/bg_BG'; -import TimePicker from '../time-picker/locale/bg_BG'; -import Calendar from '../calendar/locale/bg_BG'; +import locale from '../locale/bg_BG'; -export default { - locale: 'bg', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Филтриране', - filterConfirm: 'Добре', - filterReset: 'Нулриане', - selectAll: 'Избор на текуща страница', - selectInvert: 'Обръщане', - }, - Modal: { - okText: 'Добре', - cancelText: 'Отказ', - justOkText: 'Добре', - }, - Popconfirm: { - okText: 'Добре', - cancelText: 'Отказ', - }, - Transfer: { - searchPlaceholder: 'Търсене', - itemUnit: 'избор', - itemsUnit: 'избори', - }, - Upload: { - uploading: 'Качване...', - removeFile: 'Премахване', - uploadError: 'Грешка при качването', - previewFile: 'Преглед', - }, - Empty: { - description: 'Няма данни', - }, -}; +export default locale; diff --git a/components/locale-provider/ca_ES.tsx b/components/locale-provider/ca_ES.tsx index 24f7897978..bfca168429 100644 --- a/components/locale-provider/ca_ES.tsx +++ b/components/locale-provider/ca_ES.tsx @@ -1,34 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/ca_ES'; -import DatePicker from '../date-picker/locale/ca_ES'; -import TimePicker from '../time-picker/locale/ca_ES'; -import Calendar from '../calendar/locale/ca_ES'; +import locale from '../locale/ca_ES'; -export default { - locale: 'ca', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Filtrar Menu', - filterConfirm: 'OK', - filterReset: 'Restablir', - }, - Modal: { - okText: 'OK', - cancelText: 'Cancel·lar', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Cancel·lar', - }, - Transfer: { - searchPlaceholder: 'Cercar aquí', - itemUnit: 'item', - itemsUnit: 'items', - }, - Empty: { - description: 'Sense dades', - }, -}; +export default locale; diff --git a/components/locale-provider/cs_CZ.tsx b/components/locale-provider/cs_CZ.tsx index c9431a1073..a14aefebda 100644 --- a/components/locale-provider/cs_CZ.tsx +++ b/components/locale-provider/cs_CZ.tsx @@ -1,40 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/cs_CZ'; -import DatePicker from '../date-picker/locale/cs_CZ'; -import TimePicker from '../time-picker/locale/cs_CZ'; -import Calendar from '../calendar/locale/cs_CZ'; +import locale from '../locale/cs_CZ'; -export default { - locale: 'cs', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Filtr', - filterConfirm: 'Potvrdit', - filterReset: 'Obnovit', - }, - Modal: { - okText: 'Ok', - cancelText: 'Storno', - justOkText: 'Ok', - }, - Popconfirm: { - okText: 'Ok', - cancelText: 'Storno', - }, - Transfer: { - searchPlaceholder: 'Vyhledávání', - itemUnit: 'položka', - itemsUnit: 'položek', - }, - Upload: { - uploading: 'Nahrávání...', - removeFile: 'Odstranit soubor', - uploadError: 'Chyba při nahrávání', - previewFile: 'Zobrazit soubor', - }, - Empty: { - description: 'Žádná data', - }, -}; +export default locale; diff --git a/components/locale-provider/da_DK.tsx b/components/locale-provider/da_DK.tsx index b27ad06034..92a83f169b 100644 --- a/components/locale-provider/da_DK.tsx +++ b/components/locale-provider/da_DK.tsx @@ -1,42 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/da_DK'; -import DatePicker from '../date-picker/locale/da_DK'; -import TimePicker from '../time-picker/locale/da_DK'; -import Calendar from '../calendar/locale/da_DK'; +import locale from '../locale/da_DK'; -export default { - locale: 'da', - DatePicker, - TimePicker, - Calendar, - Pagination, - Table: { - filterTitle: 'Filtermenu', - filterConfirm: 'OK', - filterReset: 'Nulstil', - selectAll: 'Vælg alle', - selectInvert: 'Inverter valg', - }, - Modal: { - okText: 'OK', - cancelText: 'Afbryd', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Afbryd', - }, - Transfer: { - searchPlaceholder: 'Søg her', - itemUnit: 'element', - itemsUnit: 'elementer', - }, - Upload: { - uploading: 'Uploader...', - removeFile: 'Fjern fil', - uploadError: 'Fejl ved upload', - previewFile: 'Forhåndsvisning', - }, - Empty: { - description: 'Ingen data', - }, -}; +export default locale; diff --git a/components/locale-provider/de_DE.tsx b/components/locale-provider/de_DE.tsx index f0a72aed95..f804a836e5 100644 --- a/components/locale-provider/de_DE.tsx +++ b/components/locale-provider/de_DE.tsx @@ -1,42 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/de_DE'; -import DatePicker from '../date-picker/locale/de_DE'; -import TimePicker from '../time-picker/locale/de_DE'; -import Calendar from '../calendar/locale/de_DE'; +import locale from '../locale/de_DE'; -export default { - locale: 'de', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Filter-Menü', - filterConfirm: 'OK', - filterReset: 'Zurücksetzen', - selectAll: 'Selektiere Alle', - selectInvert: 'Selektion Invertieren', - }, - Modal: { - okText: 'OK', - cancelText: 'Abbrechen', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Abbrechen', - }, - Transfer: { - searchPlaceholder: 'Suchen', - itemUnit: 'Eintrag', - itemsUnit: 'Einträge', - }, - Upload: { - uploading: 'Hochladen...', - removeFile: 'Datei entfernen', - uploadError: 'Fehler beim Hochladen', - previewFile: 'Dateivorschau', - }, - Empty: { - description: 'Keine Daten', - }, -}; +export default locale; diff --git a/components/locale-provider/default.tsx b/components/locale-provider/default.tsx index 9ed202190d..4740550189 100644 --- a/components/locale-provider/default.tsx +++ b/components/locale-provider/default.tsx @@ -1,61 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/en_US'; -import DatePicker from '../date-picker/locale/en_US'; -import TimePicker from '../time-picker/locale/en_US'; -import Calendar from '../calendar/locale/en_US'; +import locale from '../locale/default'; -export default { - locale: 'en', - Pagination, - DatePicker, - TimePicker, - Calendar, - global: { - placeholder: 'Please select', - }, - Table: { - filterTitle: 'Filter menu', - filterConfirm: 'OK', - filterReset: 'Reset', - selectAll: 'Select current page', - selectInvert: 'Invert current page', - sortTitle: 'Sort', - expand: 'Expand row', - collapse: 'Collapse row', - }, - Modal: { - okText: 'OK', - cancelText: 'Cancel', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Cancel', - }, - Transfer: { - titles: ['', ''], - searchPlaceholder: 'Search here', - itemUnit: 'item', - itemsUnit: 'items', - }, - Upload: { - uploading: 'Uploading...', - removeFile: 'Remove file', - uploadError: 'Upload error', - previewFile: 'Preview file', - }, - Empty: { - description: 'No Data', - }, - Icon: { - icon: 'icon', - }, - Text: { - edit: 'edit', - copy: 'copy', - copied: 'copy success', - expand: 'expand', - }, - PageHeader: { - back: 'back', - }, -}; +export default locale; diff --git a/components/locale-provider/el_GR.tsx b/components/locale-provider/el_GR.tsx index 0f38eb337e..0934a503f3 100644 --- a/components/locale-provider/el_GR.tsx +++ b/components/locale-provider/el_GR.tsx @@ -1,42 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/el_GR'; -import DatePicker from '../date-picker/locale/el_GR'; -import TimePicker from '../time-picker/locale/el_GR'; -import Calendar from '../calendar/locale/el_GR'; +import locale from '../locale/el_GR'; -export default { - locale: 'el', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Μενού φίλτρων', - filterConfirm: 'ΟΚ', - filterReset: 'Επαναφορά', - selectAll: 'Επιλογή τρέχουσας σελίδας', - selectInvert: 'Αντιστροφή τρέχουσας σελίδας', - }, - Modal: { - okText: 'ΟΚ', - cancelText: 'Άκυρο', - justOkText: 'ΟΚ', - }, - Popconfirm: { - okText: 'ΟΚ', - cancelText: 'Άκυρο', - }, - Transfer: { - searchPlaceholder: 'Αναζήτηση', - itemUnit: 'αντικείμενο', - itemsUnit: 'αντικείμενα', - }, - Upload: { - uploading: 'Μεταφόρτωση...', - removeFile: 'Αφαίρεση αρχείου', - uploadError: 'Σφάλμα μεταφόρτωσης', - previewFile: 'Προεπισκόπηση αρχείου', - }, - Empty: { - description: 'Δεν υπάρχουν δεδομένα', - }, -}; +export default locale; diff --git a/components/locale-provider/en_GB.tsx b/components/locale-provider/en_GB.tsx index 8e490001e9..73926d57b6 100644 --- a/components/locale-provider/en_GB.tsx +++ b/components/locale-provider/en_GB.tsx @@ -1,42 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/en_GB'; -import DatePicker from '../date-picker/locale/en_GB'; -import TimePicker from '../time-picker/locale/en_GB'; -import Calendar from '../calendar/locale/en_GB'; +import locale from '../locale/en_GB'; -export default { - locale: 'en-gb', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Filter menu', - filterConfirm: 'OK', - filterReset: 'Reset', - selectAll: 'Select current page', - selectInvert: 'Invert current page', - }, - Modal: { - okText: 'OK', - cancelText: 'Cancel', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Cancel', - }, - Transfer: { - searchPlaceholder: 'Search here', - itemUnit: 'item', - itemsUnit: 'items', - }, - Upload: { - uploading: 'Uploading...', - removeFile: 'Remove file', - uploadError: 'Upload error', - previewFile: 'Preview file', - }, - Empty: { - description: 'No data', - }, -}; +export default locale; diff --git a/components/locale-provider/en_US.tsx b/components/locale-provider/en_US.tsx index 5d08924d7f..c1a1995e17 100644 --- a/components/locale-provider/en_US.tsx +++ b/components/locale-provider/en_US.tsx @@ -1,3 +1,3 @@ -import defaultLocale from './default'; +import locale from '../locale/en_US'; -export default defaultLocale; +export default locale; diff --git a/components/locale-provider/es_ES.tsx b/components/locale-provider/es_ES.tsx index 2932e4d8bb..2ad9715e12 100644 --- a/components/locale-provider/es_ES.tsx +++ b/components/locale-provider/es_ES.tsx @@ -1,58 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/es_ES'; -import DatePicker from '../date-picker/locale/es_ES'; -import TimePicker from '../time-picker/locale/es_ES'; -import Calendar from '../calendar/locale/es_ES'; +import locale from '../locale/es_ES'; -export default { - locale: 'es', - Pagination, - DatePicker, - TimePicker, - Calendar, - global: { - placeholder: 'Seleccione', - }, - Table: { - filterTitle: 'Filtrar menú', - filterConfirm: 'Aceptar', - filterReset: 'Reiniciar', - selectAll: 'Seleccionar todo', - selectInvert: 'Invertir selección', - sortTitle: 'Ordenar', - }, - Modal: { - okText: 'Aceptar', - cancelText: 'Cancelar', - justOkText: 'Aceptar', - }, - Popconfirm: { - okText: 'Aceptar', - cancelText: 'Cancelar', - }, - Transfer: { - searchPlaceholder: 'Buscar aquí', - itemUnit: 'elemento', - itemsUnit: 'elementos', - }, - Upload: { - uploading: 'Subiendo...', - removeFile: 'Eliminar archivo', - uploadError: 'Error al subir el archivo', - previewFile: 'Vista previa', - }, - Empty: { - description: 'No hay datos', - }, - Icon: { - icon: 'ícono', - }, - Text: { - edit: 'editar', - copy: 'copiar', - copied: 'copiado', - expand: 'expandir', - }, - PageHeader: { - back: 'volver', - }, -}; +export default locale; diff --git a/components/locale-provider/et_EE.tsx b/components/locale-provider/et_EE.tsx index 1e6da377e0..0b6a19b02f 100644 --- a/components/locale-provider/et_EE.tsx +++ b/components/locale-provider/et_EE.tsx @@ -1,42 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/et_EE'; -import DatePicker from '../date-picker/locale/et_EE'; -import TimePicker from '../time-picker/locale/et_EE'; -import Calendar from '../calendar/locale/et_EE'; +import locale from '../locale/et_EE'; -export default { - locale: 'et', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Filtri menüü', - filterConfirm: 'OK', - filterReset: 'Nulli', - selectAll: 'Vali kõik', - selectInvert: 'Inverteeri valik', - }, - Modal: { - okText: 'OK', - cancelText: 'Tühista', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Tühista', - }, - Transfer: { - searchPlaceholder: 'Otsi siit', - itemUnit: 'kogus', - itemsUnit: 'kogus', - }, - Upload: { - uploading: 'Üleslaadimine...', - removeFile: 'Eemalda fail', - uploadError: 'Üleslaadimise tõrge', - previewFile: 'Faili eelvaade', - }, - Empty: { - description: 'Andmed puuduvad', - }, -}; +export default locale; diff --git a/components/locale-provider/fa_IR.tsx b/components/locale-provider/fa_IR.tsx index f0a217ceed..a1d65051fd 100644 --- a/components/locale-provider/fa_IR.tsx +++ b/components/locale-provider/fa_IR.tsx @@ -1,42 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/fa_IR'; -import DatePicker from '../date-picker/locale/fa_IR'; -import TimePicker from '../time-picker/locale/fa_IR'; -import Calendar from '../calendar/locale/fa_IR'; +import locale from '../locale/fa_IR'; -export default { - locale: 'fa', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'منوی فیلتر', - filterConfirm: 'تایید', - filterReset: 'پاک کردن', - selectAll: 'انتخاب صفحهی کنونی', - selectInvert: 'معکوس کردن انتخابها در صفحه ی کنونی', - }, - Modal: { - okText: 'تایید', - cancelText: 'لغو', - justOkText: 'تایید', - }, - Popconfirm: { - okText: 'تایید', - cancelText: 'لغو', - }, - Transfer: { - searchPlaceholder: 'جستجو', - itemUnit: '', - itemsUnit: '', - }, - Upload: { - uploading: 'در حال آپلود...', - removeFile: 'حذف فایل', - uploadError: 'خطا در آپلود', - previewFile: 'مشاهدهی فایل', - }, - Empty: { - description: 'دادهای موجود نیست', - }, -}; +export default locale; diff --git a/components/locale-provider/fi_FI.tsx b/components/locale-provider/fi_FI.tsx index 5202eac08e..59c506f6bc 100644 --- a/components/locale-provider/fi_FI.tsx +++ b/components/locale-provider/fi_FI.tsx @@ -1,43 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/fi_FI'; -import DatePicker from '../date-picker/locale/fi_FI'; -import TimePicker from '../time-picker/locale/fi_FI'; -import Calendar from '../calendar/locale/fi_FI'; +import locale from '../locale/fi_FI'; -export default { - locale: 'fi', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Suodatus valikko', - filterConfirm: 'OK', - filterReset: 'Tyhjennä', - selectAll: 'Valitse kaikki', - selectInvert: 'Valitse päinvastoin', - sortTitle: 'Lajittele', - }, - Modal: { - okText: 'OK', - cancelText: 'Peruuta', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Peruuta', - }, - Transfer: { - searchPlaceholder: 'Etsi täältä', - itemUnit: 'kohde', - itemsUnit: 'kohdetta', - }, - Upload: { - uploading: 'Lähetetään...', - removeFile: 'Poista tiedosto', - uploadError: 'Virhe lähetyksessä', - previewFile: 'Esikatsele tiedostoa', - }, - Empty: { - description: 'Ei kohteita', - }, -}; +export default locale; diff --git a/components/locale-provider/fr_BE.tsx b/components/locale-provider/fr_BE.tsx index 5b154e86ca..b93758edce 100644 --- a/components/locale-provider/fr_BE.tsx +++ b/components/locale-provider/fr_BE.tsx @@ -1,40 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/fr_BE'; -import DatePicker from '../date-picker/locale/fr_BE'; -import TimePicker from '../time-picker/locale/fr_BE'; -import Calendar from '../calendar/locale/fr_BE'; +import locale from '../locale/fr_BE'; -export default { - locale: 'fr', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Filtrer', - filterConfirm: 'OK', - filterReset: 'Réinitialiser', - }, - Modal: { - okText: 'OK', - cancelText: 'Annuler', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Annuler', - }, - Transfer: { - searchPlaceholder: 'Recherche', - itemUnit: 'élément', - itemsUnit: 'éléments', - }, - Empty: { - description: 'Aucune donnée', - }, - Text: { - edit: 'éditer', - copy: 'copier', - copied: 'copie effectuée', - expand: 'développer', - }, -}; +export default locale; diff --git a/components/locale-provider/fr_FR.tsx b/components/locale-provider/fr_FR.tsx index 3fa5fcd0ce..97184887b2 100644 --- a/components/locale-provider/fr_FR.tsx +++ b/components/locale-provider/fr_FR.tsx @@ -1,40 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/fr_FR'; -import DatePicker from '../date-picker/locale/fr_FR'; -import TimePicker from '../time-picker/locale/fr_FR'; -import Calendar from '../calendar/locale/fr_FR'; +import locale from '../locale/fr_FR'; -export default { - locale: 'fr', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Filtrer', - filterConfirm: 'OK', - filterReset: 'Réinitialiser', - }, - Modal: { - okText: 'OK', - cancelText: 'Annuler', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Annuler', - }, - Transfer: { - searchPlaceholder: 'Recherche', - itemUnit: 'élément', - itemsUnit: 'éléments', - }, - Empty: { - description: 'Aucune donnée', - }, - Text: { - edit: 'éditer', - copy: 'copier', - copied: 'copie effectuée', - expand: 'développer', - }, -}; +export default locale; diff --git a/components/locale-provider/he_IL.tsx b/components/locale-provider/he_IL.tsx index 53a6768d58..225fc31cb3 100644 --- a/components/locale-provider/he_IL.tsx +++ b/components/locale-provider/he_IL.tsx @@ -1,42 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/he_IL'; -import DatePicker from '../date-picker/locale/he_IL'; -import TimePicker from '../time-picker/locale/he_IL'; -import Calendar from '../calendar/locale/he_IL'; +import locale from '../locale/he_IL'; -export default { - locale: 'he', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'תפריט סינון', - filterConfirm: 'אישור', - filterReset: 'איפוס', - selectAll: 'בחר הכל', - selectInvert: 'הפוך בחירה', - }, - Modal: { - okText: 'אישור', - cancelText: 'ביטול', - justOkText: 'אישור', - }, - Popconfirm: { - okText: 'אישור', - cancelText: 'ביטול', - }, - Transfer: { - searchPlaceholder: 'חפש כאן', - itemUnit: 'פריט', - itemsUnit: 'פריטים', - }, - Upload: { - uploading: 'מעלה...', - removeFile: 'הסר קובץ', - uploadError: 'שגיאת העלאה', - previewFile: 'הצג קובץ', - }, - Empty: { - description: 'אין מידע', - }, -}; +export default locale; diff --git a/components/locale-provider/hi_IN.tsx b/components/locale-provider/hi_IN.tsx index 37a9261bdc..fb1b0bda4f 100644 --- a/components/locale-provider/hi_IN.tsx +++ b/components/locale-provider/hi_IN.tsx @@ -1,50 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/hi_IN'; -import DatePicker from '../date-picker/locale/hi_IN'; -import TimePicker from '../time-picker/locale/hi_IN'; -import Calendar from '../calendar/locale/hi_IN'; +import locale from '../locale/hi_IN'; -export default { - locale: 'hi', - Pagination, - DatePicker, - TimePicker, - Calendar, - // locales for all comoponents - global: { - placeholder: 'कृपया चुनें', - }, - Table: { - filterTitle: 'सूची बंद करें', - filterConfirm: 'अच्छी तरह से', - filterReset: 'रीसेट', - emptyText: 'कोई जानकारी नहीं', - selectAll: 'वर्तमान पृष्ठ का चयन करें', - selectInvert: 'वर्तमान पृष्ठ घुमाएं', - sortTitle: 'द्वारा क्रमबद्ध करें', - }, - Modal: { - okText: 'अच्छी तरह से', - cancelText: 'रद्द करना', - justOkText: 'अच्छी तरह से', - }, - Popconfirm: { - okText: 'अच्छी तरह से', - cancelText: 'रद्द करना', - }, - Transfer: { - titles: ['', ''], - notFoundContent: 'नहीं मिला', - searchPlaceholder: 'यहां खोजें', - itemUnit: 'तत्त्व', - itemsUnit: 'विषय-वस्तु', - }, - Select: { - notFoundContent: 'नहीं मिला', - }, - Upload: { - uploading: 'अपलोडिंग...', - removeFile: 'फ़ाइल निकालें', - uploadError: 'अपलोड में त्रुटि', - previewFile: 'फ़ाइल पूर्वावलोकन', - }, -}; +export default locale; diff --git a/components/locale-provider/hr_HR.tsx b/components/locale-provider/hr_HR.tsx index 91a47165c9..d021e11019 100644 --- a/components/locale-provider/hr_HR.tsx +++ b/components/locale-provider/hr_HR.tsx @@ -1,56 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/hr_HR'; -import DatePicker from '../date-picker/locale/hr_HR'; -import TimePicker from '../time-picker/locale/hr_HR'; -import Calendar from '../calendar/locale/hr_HR'; +import locale from '../locale/hr_HR'; -export default { - locale: 'hr', - Pagination, - DatePicker, - TimePicker, - Calendar, - global: { - placeholder: 'Molimo označite', - }, - Table: { - filterTitle: 'Filter meni', - filterConfirm: 'OK', - filterReset: 'Reset', - selectAll: 'Označi trenutnu stranicu', - selectInvert: 'Invertiraj trenutnu stranicu', - sortTitle: 'Sortiraj', - }, - Modal: { - okText: 'OK', - cancelText: 'Odustani', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Odustani', - }, - Transfer: { - titles: ['', ''], - searchPlaceholder: 'Pretraži ovdje', - itemUnit: 'stavka', - itemsUnit: 'stavke', - }, - Upload: { - uploading: 'Upload u tijeku...', - removeFile: 'Makni datoteku', - uploadError: 'Greška kod uploada', - previewFile: 'Pogledaj datoteku', - }, - Empty: { - description: 'Nema podataka', - }, - Icon: { - icon: 'ikona', - }, - Text: { - edit: 'uredi', - copy: 'kopiraj', - copied: 'kopiranje uspješno', - expand: 'proširi', - }, -}; +export default locale; diff --git a/components/locale-provider/hu_HU.tsx b/components/locale-provider/hu_HU.tsx index 5df42d9188..6087d3fd30 100644 --- a/components/locale-provider/hu_HU.tsx +++ b/components/locale-provider/hu_HU.tsx @@ -1,43 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/hu_HU'; -import DatePicker from '../date-picker/locale/hu_HU'; -import TimePicker from '../time-picker/locale/hu_HU'; -import Calendar from '../calendar/locale/hu_HU'; +import locale from '../locale/hu_HU'; -export default { - locale: 'hu', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Szűrők', - filterConfirm: 'Alkalmazás', - filterReset: 'Visszaállítás', - selectAll: 'Jelenlegi oldal kiválasztása', - selectInvert: 'Jelenlegi oldal inverze', - sortTitle: 'Rendezés', - }, - Modal: { - okText: 'Alkalmazás', - cancelText: 'Visszavonás', - justOkText: 'Alkalmazás', - }, - Popconfirm: { - okText: 'Alkalmazás', - cancelText: 'Visszavonás', - }, - Transfer: { - searchPlaceholder: 'Keresés', - itemUnit: 'elem', - itemsUnit: 'elemek', - }, - Upload: { - uploading: 'Feltöltés...', - removeFile: 'Fájl eltávolítása', - uploadError: 'Feltöltési hiba', - previewFile: 'Fájl előnézet', - }, - Empty: { - description: 'Nincs adat', - }, -}; +export default locale; diff --git a/components/locale-provider/id_ID.tsx b/components/locale-provider/id_ID.tsx index 511a898174..59b6761330 100644 --- a/components/locale-provider/id_ID.tsx +++ b/components/locale-provider/id_ID.tsx @@ -1,44 +1,3 @@ -import Pagination from 'rc-pagination/lib/locale/id_ID'; -import DatePicker from '../date-picker/locale/id_ID'; -import TimePicker from '../time-picker/locale/id_ID'; -import Calendar from '../calendar/locale/id_ID'; +import locale from '../locale/id_ID'; -export default { - locale: 'id', - Pagination, - DatePicker, - TimePicker, - Calendar, - Table: { - filterTitle: 'Saring', - filterConfirm: 'OK', - filterReset: 'Hapus', - selectAll: 'Pilih semua di halaman ini', - selectInvert: 'Balikkan pilihan di halaman ini', - sortTitle: 'Urutkan', - }, - Modal: { - okText: 'OK', - cancelText: 'Batal', - justOkText: 'OK', - }, - Popconfirm: { - okText: 'OK', - cancelText: 'Batal', - }, - Transfer: { - titles: ['', ''], - searchPlaceholder: 'Cari', - itemUnit: 'item', - itemsUnit: 'item', - }, - Upload: { - uploading: 'Mengunggah...', - removeFile: 'Hapus file', - uploadError: 'Kesalahan pengunggahan', - previewFile: 'File pratinjau', - }, - Empty: { - description: 'Tidak ada data', - }, -}; +export default locale; diff --git a/components/locale-provider/index.en-US.md b/components/locale-provider/index.en-US.md index a05220c0a2..ba54eb78c1 100644 --- a/components/locale-provider/index.en-US.md +++ b/components/locale-provider/index.en-US.md @@ -1,11 +1,11 @@ --- category: Components -type: Other +type: Deprecated cols: 1 -title: LocaleProvider +title: LocaleProvider (Deprecated) --- -`LocaleProvider` provides a uniform localization support for built-in text of components. +`LocaleProvider` component. Deprecated, please use [ConfigProvider](/components/config-provider) instead. ## Usage diff --git a/components/locale-provider/index.tsx b/components/locale-provider/index.tsx index 3a0ba28bb0..9f31c48aa2 100644 --- a/components/locale-provider/index.tsx +++ b/components/locale-provider/index.tsx @@ -3,6 +3,9 @@ import * as PropTypes from 'prop-types'; import * as moment from 'moment'; import interopDefault from '../_util/interopDefault'; import { ModalLocale, changeConfirmLocale } from '../modal/locale'; +import warning from '../_util/warning'; + +export const ANT_MARK = 'internalMark'; export interface Locale { locale: string; @@ -21,6 +24,7 @@ export interface Locale { export interface LocaleProviderProps { locale: Locale; children?: React.ReactNode; + _ANT_MARK__?: string; } function setMomentLocale(locale: Locale) { @@ -48,6 +52,12 @@ export default class LocaleProvider extends React.Component + 当前日期:{date ? date.format('YYYY-MM-DD') : '未选择'} - + ); } } diff --git a/docs/react/i18n.en-US.md b/docs/react/i18n.en-US.md index fb6d6627cb..072603774e 100644 --- a/docs/react/i18n.en-US.md +++ b/docs/react/i18n.en-US.md @@ -5,22 +5,22 @@ title: Internationalization The default language of `antd@2.x` is English as of yet. If you want to use other languages, you can follow the instructions below. -## LocaleProvider +## ConfigProvider -antd provides a React Component [LocaleProvider](/components/locale-provider) for configuring antd locale text globally. +antd provides a React Component [ConfigProvider](/components/config-provider) for configuring antd locale text globally. ```jsx -import { LocaleProvider } from 'antd'; -import frFR from 'antd/es/locale-provider/fr_FR'; +import { ConfigProvider } from 'antd'; +import frFR from 'antd/es/locale/fr_FR'; return ( - + - + ); ``` -You can see complete config at: [LocaleProvider](/components/locale-provider). +You can see complete config at: [ConfigProvider](/components/config-provider). Note: `fr_FR` is the filename, follow below. @@ -71,8 +71,8 @@ Supported languages: | Chinese (Simplified) | zh_CN | | Chinese (Traditional) | zh_TW | -See usage and ways to contribute a new locale package at [LocaleProvider](/components/locale-provider). +See usage and ways to contribute a new locale package at [ConfigProvider](/components/config-provider). ## i18n sample -We also provide you a complete sample of internationalization usage, which is using [react-intl](https://github.com/yahoo/react-intl) and LocaleProvider: [ant-design/intl-example](https://github.com/ant-design/intl-example). +We also provide you a complete sample of internationalization usage, which is using [react-intl](https://github.com/yahoo/react-intl) and ConfigProvider: [ant-design/intl-example](https://github.com/ant-design/intl-example). diff --git a/docs/react/i18n.zh-CN.md b/docs/react/i18n.zh-CN.md index b337837f46..1b7368134d 100644 --- a/docs/react/i18n.zh-CN.md +++ b/docs/react/i18n.zh-CN.md @@ -5,21 +5,21 @@ title: 国际化 `antd` 目前的默认文案是英文,如果需要使用其他语言,可以参考下面的方案。 -## LocaleProvider +## ConfigProvider -antd 提供了一个 React 组件 [LocaleProvider](/components/locale-provider) 用于全局配置国际化文案。 +antd 提供了一个 React 组件 [ConfigProvider](/components/config-provider) 用于全局配置国际化文案。 ```jsx -import zhCN from 'antd/es/locale-provider/zh_CN'; +import zhCN from 'antd/es/locale/zh_CN'; return ( - + - + ); ``` -详细配置见:[LocaleProvider](/components/locale-provider)。 +详细配置见:[ConfigProvider](/components/config-provider)。 注意:`zh_CN` 是文件名,以下表格也遵循同样的规则。 @@ -70,7 +70,7 @@ return ( | 简体中文 | zh_CN | | 繁体中文 | zh_TW | -具体的使用方法和新语言包贡献方式请参考 [LocaleProvider 文档](/components/locale-provider)。 +具体的使用方法和新语言包贡献方式请参考 [ConfigProvider 文档](/components/config-provider)。 ## i18n 项目示例 diff --git a/index-with-locales.js b/index-with-locales.js index 0ceeb320f6..3cb8b9f7dc 100644 --- a/index-with-locales.js +++ b/index-with-locales.js @@ -1,6 +1,6 @@ const antd = require('./components'); -const req = require.context('./components', true, /^\.\/locale-provider\/.+_.+\.tsx$/); +const req = require.context('./components', true, /^\.\/locale\/.+_.+\.tsx$/); antd.locales = {}; diff --git a/package.json b/package.json index 00128328ff..93a9be6261 100644 --- a/package.json +++ b/package.json @@ -197,7 +197,7 @@ "lint:ts": "npm run tsc && antd-tools run ts-lint", "lint:es": "eslint tests site scripts components ./.*.js ./webpack.config.js --ext '.js,.jsx'", "lint:md": "remark components/", - "lint:demo": "cross-env RUN_ENV=DEMO eslint components/*/demo/*.md --ext '.md'", + "lint:demo": "cross-env RUN_ENV=DEMO eslint components/*/demo/*.md --ext '.md' --rule 'import/no-unresolved: 0'", "lint:style": "stylelint '{site,components}/**/*.less' --syntax less", "lint-fix:ts": "npm run tsc && antd-tools run ts-lint-fix", "lint-fix": "npm run lint-fix:code && npm run lint-fix:demo && npm run lint-fix:style", diff --git a/scripts/generateLegacyLocale.js b/scripts/generateLegacyLocale.js new file mode 100644 index 0000000000..693081c107 --- /dev/null +++ b/scripts/generateLegacyLocale.js @@ -0,0 +1,25 @@ +/* eslint-disable no-console */ +/** + * Generate legacy locale file as shadow of `/locale` to `/locale-provider`. + */ + +const glob = require('glob'); +const fs = require('fs'); +const chalk = require('chalk'); + +glob('components/locale/@(*_*|default).tsx', (er, files) => { + files.forEach(filePath => { + const modulePath = filePath.replace(/^components/, '..').replace('.tsx', ''); + const legacyModulePath = filePath.replace('locale', 'locale-provider'); + + const template = `import locale from '${modulePath}'; + +export default locale; +`.trim(); + + console.log(modulePath, '=>', legacyModulePath); + fs.writeFileSync(legacyModulePath, template, 'utf8'); + }); + + console.log(chalk.green('✨ Locale generate success!')); +}); diff --git a/site/theme/template/Layout/index.jsx b/site/theme/template/Layout/index.jsx index 255c2b79f4..b0ccd83746 100644 --- a/site/theme/template/Layout/index.jsx +++ b/site/theme/template/Layout/index.jsx @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; import { enquireScreen } from 'enquire-js'; import { addLocaleData, IntlProvider } from 'react-intl'; import 'moment/locale/zh-cn'; -import { LocaleProvider } from 'antd'; +import { ConfigProvider } from 'antd'; import LogRocket from 'logrocket'; import setupLogRocketReact from 'logrocket-react'; import zhCN from 'antd/lib/locale-provider/zh_CN'; @@ -113,12 +113,12 @@ export default class Layout extends React.Component { // Temp remove SentryBoundary return ( - + {children} - + ); } diff --git a/tests/dekko/lib.test.js b/tests/dekko/lib.test.js index ac97e03e92..d99078e649 100644 --- a/tests/dekko/lib.test.js +++ b/tests/dekko/lib.test.js @@ -1,5 +1,10 @@ const $ = require('dekko'); const chalk = require('chalk'); +const path = require('path'); + +function getFileName(filePath) { + return filePath.slice(filePath.lastIndexOf(path.sep) + 1); +} $('lib') .isDirectory() @@ -14,7 +19,10 @@ $('lib/*') !filename.endsWith('.map'), ) .isDirectory() - .filter(filename => !filename.endsWith('style') && !filename.endsWith('_util')) + .filter( + filename => + !filename.endsWith('style') && !filename.endsWith('_util') && !filename.endsWith('locale'), + ) .hasFile('index.js') .hasFile('index.d.ts') .hasDirectory('style'); @@ -25,5 +33,34 @@ $('lib/*/style') $('lib/style').hasFile('v2-compatible-reset.css'); +// locale +const filterLocaleFile = filePath => { + const fileName = getFileName(filePath); + return ( + !fileName.endsWith('index.js') && + !fileName.endsWith('.d.ts') && + !fileName.endsWith('.map') && + !fileName.endsWith('style') && + !fileName.includes('-') && + !fileName.endsWith('LocaleReceiver.js') + ); +}; +const localeFiles = $('lib/locale/*').filter(filterLocaleFile); +const localeProviderFiles = $('lib/locale-provider/*').filter(filterLocaleFile); + +function compare(originFiles, targetFiles, targetPath) { + originFiles.assert( + `not exist in '${targetPath}'. Please use 'scripts/generateLegacyLocale.js' to refresh locale files.`, + filePath => { + const fileName = getFileName(filePath); + + return targetFiles.filenames.some(targetFilePath => getFileName(targetFilePath) === fileName); + }, + ); +} + +compare(localeFiles, localeProviderFiles, '/locale-provider'); +compare(localeProviderFiles, localeFiles, '/locale'); + // eslint-disable-next-line console.log(chalk.green('✨ `lib` directory is valid.'));
Locale Modal