Angular 如何为日期管道使用ngx翻译?
我有一个应用程序,它运行在两种语言(我可以更改和选择我想要的语言,但使用i18n)英语/法语 目前,即使我选择了法语,我也只能用英语获得日期Angular 如何为日期管道使用ngx翻译?,angular,ionic-framework,ngx-translate,Angular,Ionic Framework,Ngx Translate,我有一个应用程序,它运行在两种语言(我可以更改和选择我想要的语言,但使用i18n)英语/法语 目前,即使我选择了法语,我也只能用英语获得日期 <div class="information"> {{ information.date | information:'EEEE'}} {{information.date | date:'d'}} {{ information.date | date:'MMMM'}} {{ information.date
<div class="information">
{{ information.date | information:'EEEE'}} {{information.date | date:'d'}} {{ information.date | date:'MMMM'}} {{ information.date |
date:'yyyy'}}
</div>
{{information.date}信息:'EEEE'}{{information.date}日期:'d'}{{{information.date}日期:'MMMM'}{{{information.date|
日期:'yyy'}
有没有办法根据我选择的语言更改日期 您可以使用类变量作为日期格式,如
{{information.date | date:dateFormat}
,并在语言更改时更改日期格式
@Component(...)
export class WhateverComponent {
dateFormat: string;
dateFormatSubscription: Subscription;
constructor(translateService: TranslateService) {
const langToDateFormat = lang => {/* map language to date format HERE */}
this.dateFormat = langToDateFormat(translateService.currentLang);
this.dateFormatSubscription = translateService.onLangChange().pipe(
map(langToDateFormat)
).subscribe(dateFormat => this.dateFormat = dateFormat);
}
ngOnDestroy() {
// don't forget to unsubscribe!!!
this.dateFormatSubscription.unsubscribe();
}
}
目前,我可以获得浏览器的语言,例如:8月17日星期一,我想获得Lundi17AOT