我在我的 Angular 应用程序 ( https://danielykpan.github.io/date-time-picker/ ) 中使用 NgPickDatetime,当我尝试翻译标签和消息时遇到问题。我按照文档中的说明操作,它工作正常,但问题是当我更改站点语言时,标签仍然使用以前的语言。
我的代码是:
日期时间-locale.module.ts:
import { NgModule } from '@angular/core';
import { OwlDateTimeModule, OwlNativeDateTimeModule, OwlDateTimeIntl} from 'ng-pick-datetime';
import { DefaultIntl } from './datepicker-locale.component';
@NgModule({
imports: [OwlDateTimeModule, OwlNativeDateTimeModule],
providers: [
{provide: OwlDateTimeIntl, useClass: DefaultIntl},
],
})
export class DateTimeLocaleModule {
}
Run Code Online (Sandbox Code Playgroud)
datepicker-locale.component.ts:
import { OwlDateTimeIntl } from 'ng-pick-datetime';
export class DefaultIntl extends OwlDateTimeIntl {
public cancelBtnLabel = 'Annuleren';
public setBtnLabel = 'Opslaan';
private currentLang;
constructor() {
super();
this.getLang();
}
public getLang() {
this.currentLang = JSON.parse(localStorage.getItem("language")); …Run Code Online (Sandbox Code Playgroud)