浏览代码

fix: datepicker 组件英文环境下时分秒显示的中文 #337

Drjingfubo 4 年之前
父节点
当前提交
0f2090a3d9
共有 3 个文件被更改,包括 39 次插入11 次删除
  1. 9 1
      src/locales/lang/en-US.js
  2. 9 1
      src/locales/lang/zn-CH.js
  3. 21 9
      src/packages/datepicker/datepicker.vue

+ 9 - 1
src/locales/lang/en-US.js

@@ -9,7 +9,15 @@ const lang = {
       end: 'End',
       title: 'Select date',
       week: 'Sun,Mon,Tue,Wed,Thu,Fri,Sat',
-      monthTitle: '{year}/{month}'
+      monthTitle: '{year}/{month}',
+      year: 'year',
+      month: 'month',
+      day: 'day',
+      hour: 'hour',
+      minute: 'minute',
+      second: 'second',
+      morning: 'morning',
+      afternoon: 'afternoon'
     },
     menu: {
       resetBtnTxt: 'Reset'

+ 9 - 1
src/locales/lang/zn-CH.js

@@ -11,7 +11,15 @@ const lang = {
       end: '结束',
       title: '选择日期',
       week: '日,一,二,三,四,五,六',
-      monthTitle: '{year}年{month}月'
+      monthTitle: '{year}年{month}月',
+      year: '年',
+      month: '月',
+      day: '日',
+      hour: '时',
+      minute: '分',
+      second: '秒',
+      morning: '上午',
+      afternoon: '下午'
     },
     menu: {
       resetBtnTxt: '重置'

+ 21 - 9
src/packages/datepicker/datepicker.vue

@@ -16,9 +16,11 @@
 import nutpicker from '../picker/picker.vue';
 import '../picker/picker.scss';
 import Utils from '../../utils/date.js';
+import locale from '../../mixins/locale';
 
 export default {
   name: 'nut-datepicker',
+  mixins: [locale],
   props: {
     type: {
       type: String,
@@ -91,14 +93,8 @@ export default {
       updateMonth: null,
       updateDay: null,
       updateHour: null,
-      use12Hours: ['上午', '下午'],
-      chinese: !this.isShowChinese
-        ? new Array(6).fill('')
-        : this.type == 'time'
-        ? this.isUse12Hours
-          ? ['时', '分', '']
-          : ['时', '分', '秒']
-        : ['年', '月', '日', '时', '分']
+      use12Hours: [],
+      chinese: []
     };
   },
   components: {
@@ -106,6 +102,7 @@ export default {
   },
   created() {
     this.init();
+    console.log(this.nutTranslate('lang.calendar.year'));
   },
   computed: {
     dateRange() {
@@ -137,7 +134,22 @@ export default {
       }
       // this.startDateArr = this.startDate.replace(/-/g, '/').split('/');
       // this.endDateArr = this.endDate.replace(/-/g, '/').split('/');
-      this.initListData();
+      // 国际化
+      (this.use12Hours = [this.nutTranslate('lang.calendar.morning'), this.nutTranslate('lang.calendar.afternoon')]),
+        (this.chinese = !this.isShowChinese
+          ? new Array(6).fill('')
+          : this.type == 'time'
+          ? this.isUse12Hours
+            ? [this.nutTranslate('lang.calendar.hour'), this.nutTranslate('lang.calendar.minute'), '']
+            : [this.nutTranslate('lang.calendar.hour'), this.nutTranslate('lang.calendar.minute'), this.nutTranslate('lang.calendar.second')]
+          : [
+              this.nutTranslate('lang.calendar.year'),
+              this.nutTranslate('lang.calendar.month'),
+              this.nutTranslate('lang.calendar.day'),
+              this.nutTranslate('lang.calendar.hour'),
+              this.nutTranslate('lang.calendar.minute')
+            ]),
+        this.initListData();
     },
 
     initListData() {