如何用其他语言更改md-datepicker角图标的aria-label =“打开日历”?

时间:2019-12-20 05:43:29

标签: angular angular-material

Here I have created angular md-datepicker demo

  

我要更改/翻译下图所示的md-datepicker角图标的aria-label =“打开日历”文本。

enter image description here

1 个答案:

答案 0 :(得分:0)

创建服务。

import { MatDatepicker } from '@angular/material';
import { CustomTranslateService } from '@ngx-translate/core';
import { Injectable } from '@angular/core';

const OPEN_CALENDAR = 'Open Calendar';

@Injectable()
export class CustomMatDatePickerService extends MatDatepicker {
    public constructor(private translate: CustomTranslateService) {
    super();

    this.translate.onLangChange.subscribe((e: Event) => {
        this.getAndInitTranslations();
    });

    this.getAndInitTranslations();
    }
    openCalendarLabel = this.translate.translations[this.translate.store.currentLang][OPEN_CALENDAR];
    public getAndInitTranslations(): void {
        this.translate.get([
            OPEN_CALENDAR
        ])
        .subscribe((translation: any) => {
            this.openCalendarLabel = translation[OPEN_CALENDAR];
            this.changes.next();
        });
    }
}