Ser*_*rge 0 internationalization angular-i18n angular angular6
我是Angular的初学者,阅读了Angular的文档,很难做到这一点……我希望应用程序中的日期和其他内容具有法语语言环境,而不是默认的“ en-US”。 ..
我开始阅读这份Angular 文档,似乎有些不完整,原因是我做了文档说明,但失败了:
>...\ClientApp>ng serve --configuration=fr
Configuration 'fr' could not be found in project 'ClientApp'.
Run Code Online (Sandbox Code Playgroud)
好的,现在我在日期管道上查看另一个文档页面。它指出:
{{ value_expression | date [ : format [ : timezone [ : locale ] ] ] }}
Run Code Online (Sandbox Code Playgroud)
但是关于如何使用的任何示例locale,因此,我尝试在测试应用程序链接中进行操作,像这样,{{myDate | date: 'medium': undefined : 'fr'}}但是它什么也没显示...我在控制台中有:
ERROR
Error: InvalidPipeArgument: 'Missing locale data for the locale "fr".' for pipe 'DatePipe'
Run Code Online (Sandbox Code Playgroud)
我还应该怎么做或安装以Angular格式显示日期的日期?
Angular CLI: 6.1.5
Node: 8.11.1
OS: win32 x64
Angular: 6.1.8
Run Code Online (Sandbox Code Playgroud)
尝试将以下代码添加到您的应用模块中
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
// the second parameter 'fr' is optional
registerLocaleData(localeFr, 'fr');
Run Code Online (Sandbox Code Playgroud)
https://angular.io/guide/i18n#i18n-pipes
编辑:然后,如果您要将此语言环境设置为默认语言,则需要将LOCALE_ID注入令牌设置为“ fr”,如下所示:
{provide: LOCALE_ID, useValue: 'fr' }
Run Code Online (Sandbox Code Playgroud)
在您的应用程序模块中
希望能帮助到你
答案取决于angular您使用的版本。您必须提供LOCALE您将使用的内容。默认LOCALE配置为en-US和所有其他人一样,您必须手动添加与providers. 只有providingfor 的方式LOCALES不同angular versions。检查以下内容:
角度 5 及以上:
在您的app.module.ts:
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
registerLocaleData(localeFr, 'fr');
Run Code Online (Sandbox Code Playgroud)低于 Angular 5:
在您的app.module.ts:
import { LOCALE_ID } from '@angular/core';
@NgModule({
imports : [],
providers: [ { provide: LOCALE_ID, useValue: "fr-FR" }]
//Your code
})
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
8178 次 |
| 最近记录: |