From fc1a8c16f844f58e26c13a5abcf0f605d2dedd88 Mon Sep 17 00:00:00 2001 From: mengxiong10 <15623530290@163.com> Date: Sun, 10 Nov 2019 22:35:32 +0800 Subject: [PATCH] docs: add i18n doc --- README.md | 37 +++++++++++++++++++++++++++++++++++++ README.zh-CN.md | 35 +++++++++++++++++++++++++++++++++++ locale.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 locale.md diff --git a/README.md b/README.md index 8faeddaf..06ed2d10 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,43 @@ $ npm install vue2-datepicker --save ``` +## Internationalization + +The default language of v3.x is English. If you need other locales. +You can import locale file. +Once you import a locale, it becomes the active locale. + +```js +import DatePicker from 'vue2-datepicker'; +import 'vue2-datepicker/index.css'; + +import 'vue2-datepicker/locale/zh-cn'; +``` + +You can override the default locale by `lang`. +[Full config](https://github.com/mengxiong10/vue2-datepicker/blob/master/locale.md) + +```html + + + +``` + ### Props | Prop | Description | Type | Default | diff --git a/README.zh-CN.md b/README.zh-CN.md index b1f29770..ed96bbf3 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -57,6 +57,41 @@ $ npm install vue2-datepicker --save ``` +## 国际化 + +v3.x 默认语言是英文. 可以引入语言包切换到中文. + +```js +import DatePicker from 'vue2-datepicker'; +import 'vue2-datepicker/index.css'; + +import 'vue2-datepicker/locale/zh-cn'; +``` + +还可以通过`lang`去覆盖默认语言选项. +[完整配置](https://github.com/mengxiong10/vue2-datepicker/blob/master/locale.md) + +```html + + + +``` + ### Props | 属性 | 描述 | 类型 | 默认值 | diff --git a/locale.md b/locale.md new file mode 100644 index 00000000..f2fd56fa --- /dev/null +++ b/locale.md @@ -0,0 +1,42 @@ +```js +{ + // the locale of formatting and parsing function + formatLocale: { + // MMMM + months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + // MMM + monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], + // dddd + weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], + // ddd + weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], + // dd + weekdaysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], + // first day of week + firstDayOfWeek: 0, + // first week contains January 1st. + firstWeekContainsDate: 1, + // format 'a', 'A' + meridiem: (h: number, _: number, isLowercase: boolean) { + const word = h < 12 ? 'AM' : 'PM'; + return isLowercase ? word.toLocaleLowerCase() : word; + }, + // parse ampm + meridiemParse: /[ap]\.?m?\.?/i; + // parse ampm + isPM: (input: string) { + return `${input}`.toLowerCase().charAt(0) === 'p'; + } + }, + // the calendar header, default formatLocale.weekdaysMin + days: [], + // the calendar months, default formatLocale.monthsShort + months: [], + // the calendar title of year + yearFormat: 'YYYY 年', + // the calendar title of month + monthFormat: 'MMM', + // the calendar title of month before year + monthBeforeYear: false, +} +```