element-plus / element-plus

🎉 A Vue.js 3 UI Library made by Element team
https://element-plus.org
MIT License
24.58k stars 16.66k forks source link

[Issue] el-date-picker change shortcuts language #3261

Open vadimt2 opened 3 years ago

vadimt2 commented 3 years ago

Vue file

<el-date-picker
          :clearable="false"
          v-model="currentScheduleDate"
          ref="datePicker"
          type="date"
          format="DD/MM/YYYY"
          :shortcuts="shortcuts"
          :disabledDate="disabledDate"
          @change="onScheduleDatepickerChanged"
        >
        </el-date-picker>

ts

inside watch:
 this.shortcuts = this.setShortcuts();
 const datePicker = this.$refs.datePicker;
 datePicker.shortcuts = this.setShortcuts();

// I have tried to do it with a computed property as well and it doesn't work datepicker doesn't change the language. How can I change shortcuts language when someone changes the language?

element-bot commented 3 years ago

Hello @vadimt2. Please provide an online reproduction demo by clicking this link or a minimal GitHub repository.

你好 @vadimt2, 请提供一个可复现问题的链接以便于我们帮你排查问题。可以通过点击 此处 创建或者提供一个最小化的 GitHub 仓库。

adaex commented 3 years ago

I was not able to reproduce the problem, can you describe it in detail?

vadimt2 commented 3 years ago

Sure. Set the :shortcuts="shortcuts"

data() ....

shortcuts: this.setShortcuts(),

method....

  setShortcuts() {
      debugger;
      const shortcuts = [
        {
          text: this.$t('Today'),
          value: new Date(),
        },
        {
          text: this.$t('LastInputDate'),
          onClick: (picker) => {
            let lastDate = GanttDataAnalizer.getLastInputDate();
            if (!lastDate) lastDate = (this as any).lastScheduleDate;
            this.currentScheduleDate = this.lastScheduleDate!;
            //     //  DateHelper.getDateWithoutTime(lastDate as Date)

            this.onScheduleDatepickerChanged(DateHelper.getDateWithoutTime(lastDate as Date));
          },
        },
      ];
      return shortcuts;
    },

The language will be in English. Then try to change the language to a different language.

shortcuts will stay in English they wouldn't change. It will change in the method but not in the UI.


Just create a select box with eng and ru options. when you are changing an option, the language of date picker on the right side should change. - I'm talking about Today and Last input date For testing you can just pass an array

  1. const array = ['Today','Last input date'];
  2. const array = ['MIKE','DJ']; // for the second time you

    setShortcuts(array) {
      debugger;
      const shortcuts = [
        {
          text: array[0]
          value: new Date(),
        },
        {
          text: array[1],
          onClick: (picker) => {
            let lastDate = GanttDataAnalizer.getLastInputDate();
            if (!lastDate) lastDate = (this as any).lastScheduleDate;
            this.currentScheduleDate = this.lastScheduleDate!;
            //     //  DateHelper.getDateWithoutTime(lastDate as Date)
    
            this.onScheduleDatepickerChanged(DateHelper.getDateWithoutTime(lastDate as Date));
          },
        },
      ];
      return shortcuts;
    },