缺少语言环境"XXX"的语言环境数据带角的 [英] Missing locale data for the locale "XXX" with angular
问题描述
我目前通过以下方式在"美国"上定义" LOCALE_ID ":
I currently define "LOCALE_ID" on "en-US" this way:
@NgModule({
providers: [{ provide: LOCALE_ID, useValue: "en-US" }, ...],
imports: [...],
bootstrap: [...]
})
,效果很好.但是,为了测试日期在法语中的显示方式,我将" en-US "替换为" fr-FR ",然后出现错误:
and it works pretty well. However, in order to test how dates look like in French, I replaced "en-US" by "fr-FR" and then I got the error:
缺少语言环境"fr-FR"的语言环境数据.
Missing locale data for the locale "fr-FR".
我做了一些研究,但没有发现任何与此相关的东西.默认程序包中是否包含法语的语言环境?是不同的包装吗?我必须自己创建它们吗?
I did some researches and I didn't find anything related to that. Are the locale for french included in the default package? Is it a different package? Do I have to create them by myself?
推荐答案
在文件 app.module.ts
...
import { NgModule, LOCALE_ID } from '@angular/core';
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
registerLocaleData(localeFr);
@NgModule({
imports: [...],
declarations: [...],
bootstrap: [...],
providers: [
{ provide: LOCALE_ID, useValue: 'fr-FR'},
]
})
export class AppModule {}
(来源: https://next.angular.io/guide/i18n )
和您的模板( *.component.html
)
DATE in FRENCH: {{ dateEvent | date: 'longDate'}}
结果:
DATE in FRENCH: 25 mars 2018
(来源: https://angular.io/api/common/DatePipe )
这篇关于缺少语言环境"XXX"的语言环境数据带角的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!