mirror of https://github.com/ElemeFE/element
feat(translation): date/time picker translation possibility if using vue-i18n
parent
30003ec594
commit
d60133cf09
|
@ -24,7 +24,7 @@
|
||||||
<td
|
<td
|
||||||
v-for="cell in row"
|
v-for="cell in row"
|
||||||
:class="getCellClasses(cell)"
|
:class="getCellClasses(cell)"
|
||||||
v-text="cell.type === 'today' ? '今天' : cell.text"></td>
|
v-text="cell.type === 'today' ? $t('datepicker.today') : cell.text"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -214,7 +214,9 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
$t: $t,
|
$t(...args) {
|
||||||
|
return $t.apply(this, args);
|
||||||
|
},
|
||||||
|
|
||||||
getCellClasses(cell) {
|
getCellClasses(cell) {
|
||||||
const selectionMode = this.selectionMode;
|
const selectionMode = this.selectionMode;
|
||||||
|
|
|
@ -58,7 +58,9 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
$t: $t,
|
$t(...args) {
|
||||||
|
return $t.apply(this, args);
|
||||||
|
},
|
||||||
|
|
||||||
handleMonthTableClick(event) {
|
handleMonthTableClick(event) {
|
||||||
const target = event.target;
|
const target = event.target;
|
||||||
|
|
|
@ -119,12 +119,12 @@
|
||||||
<div class="el-picker-panel__footer" v-if="showTime">
|
<div class="el-picker-panel__footer" v-if="showTime">
|
||||||
<!-- <a
|
<!-- <a
|
||||||
class="el-picker-panel__link-btn"
|
class="el-picker-panel__link-btn"
|
||||||
@click="changeToToday">{{ $t('datepicker.today') }}</a> -->
|
@click="changeToToday">{{ $t('datepicker.now') }}</a> -->
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="el-picker-panel__btn"
|
class="el-picker-panel__btn"
|
||||||
@click="handleConfirm"
|
@click="handleConfirm"
|
||||||
:disabled="btnDisabled">确定</button>
|
:disabled="btnDisabled">{{ $t('datepicker.confirm') }}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
|
@ -140,11 +140,11 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
leftLabel() {
|
leftLabel() {
|
||||||
return this.date.getFullYear() + '年 ' + (this.date.getMonth() + 1) + '月';
|
return this.date.getFullYear() + ' ' + this.$t('datepicker.month') + ' ' + (this.date.getMonth() + 1) + ' ' + this.$t('datepicker.month');
|
||||||
},
|
},
|
||||||
|
|
||||||
rightLabel() {
|
rightLabel() {
|
||||||
return this.rightDate.getFullYear() + '年 ' + (this.rightDate.getMonth() + 1) + '月';
|
return this.rightDate.getFullYear() + ' ' + this.$t('datepicker.month') + ' ' + (this.rightDate.getMonth() + 1) + ' ' + this.$t('datepicker.month');
|
||||||
},
|
},
|
||||||
|
|
||||||
leftYear() {
|
leftYear() {
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<div class="el-picker-panel__body">
|
<div class="el-picker-panel__body">
|
||||||
<div class="el-date-picker__time-header" v-if="showTime">
|
<div class="el-date-picker__time-header" v-if="showTime">
|
||||||
<input
|
<input
|
||||||
placehoder="选择日期"
|
:placehoder="$t('datepicker.selectDate')"
|
||||||
type="text"
|
type="text"
|
||||||
v-model="visibleDate"
|
v-model="visibleDate"
|
||||||
class="el-date-picker__editor">
|
class="el-date-picker__editor">
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
<input
|
<input
|
||||||
@focus="timePickerVisible = true"
|
@focus="timePickerVisible = true"
|
||||||
v-model="visibleTime"
|
v-model="visibleTime"
|
||||||
placehoder="选择时间"
|
:placehoder="$t('datepicker.selectTime')"
|
||||||
type="text"
|
type="text"
|
||||||
class="el-date-picker__editor">
|
class="el-date-picker__editor">
|
||||||
<time-picker
|
<time-picker
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
@click="showMonthPicker"
|
@click="showMonthPicker"
|
||||||
v-show="currentView === 'date'"
|
v-show="currentView === 'date'"
|
||||||
class="el-date-picker__header-label"
|
class="el-date-picker__header-label"
|
||||||
:class="{ active: currentView === 'month' }">{{ month + 1 }}月</span>
|
:class="{ active: currentView === 'month' }">{{ month + 1 }} {{$t('datepicker.month')}}</span>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@click="nextYear"
|
@click="nextYear"
|
||||||
|
@ -100,7 +100,7 @@
|
||||||
<a
|
<a
|
||||||
href="JavaScript:"
|
href="JavaScript:"
|
||||||
class="el-picker-panel__link-btn"
|
class="el-picker-panel__link-btn"
|
||||||
@click="changeToToday">{{ $t('datepicker.today') }}</a>
|
@click="changeToToday">{{ $t('datepicker.now') }}</a>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="el-picker-panel__btn"
|
class="el-picker-panel__btn"
|
||||||
|
@ -148,7 +148,9 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
$t: $t,
|
$t(...args) {
|
||||||
|
return $t.apply(this, args);
|
||||||
|
},
|
||||||
|
|
||||||
resetDate() {
|
resetDate() {
|
||||||
this.date = new Date(this.date);
|
this.date = new Date(this.date);
|
||||||
|
@ -383,11 +385,12 @@
|
||||||
yearLabel() {
|
yearLabel() {
|
||||||
const year = this.year;
|
const year = this.year;
|
||||||
if (!year) return '';
|
if (!year) return '';
|
||||||
|
const yearTranslation = this.$t('datepicker.year');
|
||||||
if (this.currentView === 'year') {
|
if (this.currentView === 'year') {
|
||||||
const startYear = Math.floor(year / 10) * 10;
|
const startYear = Math.floor(year / 10) * 10;
|
||||||
return startYear + '年' + '-' + (startYear + 9) + '年';
|
return startYear + ' ' + yearTranslation + '-' + (startYear + 9) + ' ' + yearTranslation;
|
||||||
}
|
}
|
||||||
return this.year + '年';
|
return this.year + ' ' + yearTranslation;
|
||||||
},
|
},
|
||||||
|
|
||||||
hours: {
|
hours: {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
class="el-time-range-picker el-picker-panel">
|
class="el-time-range-picker el-picker-panel">
|
||||||
<div class="el-time-range-picker__content">
|
<div class="el-time-range-picker__content">
|
||||||
<div class="el-time-range-picker__cell">
|
<div class="el-time-range-picker__cell">
|
||||||
<div class="el-time-range-picker__header">开始时间</div>
|
<div class="el-time-range-picker__header">{{ $t('datepicker.startTime') }}</div>
|
||||||
<div class="el-time-range-picker__body el-time-panel__content">
|
<div class="el-time-range-picker__body el-time-panel__content">
|
||||||
<time-spinner
|
<time-spinner
|
||||||
ref="minSpinner"
|
ref="minSpinner"
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="el-time-range-picker__cell">
|
<div class="el-time-range-picker__cell">
|
||||||
<div class="el-time-range-picker__header">结束时间</div>
|
<div class="el-time-range-picker__header">{{ $t('datepicker.endTime') }}</div>
|
||||||
<div class="el-time-range-picker__body el-time-panel__content">
|
<div class="el-time-range-picker__body el-time-panel__content">
|
||||||
<time-spinner
|
<time-spinner
|
||||||
ref="maxSpinner"
|
ref="maxSpinner"
|
||||||
|
@ -37,12 +37,12 @@
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="el-time-panel__btn cancel"
|
class="el-time-panel__btn cancel"
|
||||||
@click="handleCancel()">取消</button>
|
@click="handleCancel()">{{ $t('datepicker.cancel') }}</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="el-time-panel__btn confirm"
|
class="el-time-panel__btn confirm"
|
||||||
@click="handleConfirm()"
|
@click="handleConfirm()"
|
||||||
:disabled="btnDisabled">确定</button>
|
:disabled="btnDisabled">{{ $t('datepicker.confirm') }}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="el-time-panel__btn cancel"
|
class="el-time-panel__btn cancel"
|
||||||
@click="handleCancel()">取消</button>
|
@click="handleCancel()">{{ $t('datepicker.cancel') }}</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="el-time-panel__btn confirm"
|
class="el-time-panel__btn confirm"
|
||||||
@click="handleConfirm()">确定</button>
|
@click="handleConfirm()">{{ $t('datepicker.confirm') }}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</transition>
|
</transition>
|
||||||
|
|
|
@ -1,8 +1,16 @@
|
||||||
export default {
|
export default {
|
||||||
datepicker: {
|
datepicker: {
|
||||||
today: '此刻',
|
now: '此刻',
|
||||||
|
today: '今天',
|
||||||
|
cancel: '取消',
|
||||||
clear: '清空',
|
clear: '清空',
|
||||||
confirm: '确定',
|
confirm: '确定',
|
||||||
|
selectDate: '选择日期',
|
||||||
|
selectTime: '选择时间',
|
||||||
|
startTime: '开始时间',
|
||||||
|
endTime: '结束时间',
|
||||||
|
year: '年',
|
||||||
|
month: '月',
|
||||||
week: '周次',
|
week: '周次',
|
||||||
weeks: {
|
weeks: {
|
||||||
sun: '日',
|
sun: '日',
|
||||||
|
|
|
@ -176,7 +176,11 @@ export const limitRange = function(date, ranges) {
|
||||||
|
|
||||||
import i18n from './i18n';
|
import i18n from './i18n';
|
||||||
|
|
||||||
export const $t = function(path) {
|
export const $t = function(path, options) {
|
||||||
|
const vuei18n = Object.getPrototypeOf(this).$t;
|
||||||
|
if (typeof vuei18n === 'function') {
|
||||||
|
return vuei18n.apply(this, [path, options]);
|
||||||
|
}
|
||||||
const array = path.split('.');
|
const array = path.split('.');
|
||||||
let current = i18n;
|
let current = i18n;
|
||||||
for (var i = 0, j = array.length; i < j; i++) {
|
for (var i = 0, j = array.length; i < j; i++) {
|
||||||
|
|
Loading…
Reference in New Issue