【问题标题】:Angular npm run build - Locale data for 'fr-FR' cannot be foundAngular npm run build - 找不到“fr-FR”的语言环境数据
【发布时间】:2021-11-23 19:44:05
【问题描述】:

在我添加 fr-Fr 语言环境的 angular.json 中,我看到一条消息 找不到“fr-FR”的语言环境数据。在运行命令 npm run build 时使用“fr”的语言环境数据

但是,我在 dist 文件夹中看到了正确的结构,并生成了 fr-FR。这是可以忽略的警告还是我的配置有问题。

"i18n": {
        "sourceLocale": "en",
        "locales": {
          "fr-BE": "src/locale/messages.fr-BE.xlf",
          "fr-CA": "src/locale/messages.fr-CA.xlf",
          "fr-FR": "src/locale/messages.fr-FR.xlf",                      
          "fr-LU": "src/locale/messages.fr-LU.xlf"          
        }
      },

PS:对于其他有效的语言环境,如 zh-HK 和其他,会看到相同的消息。

【问题讨论】:

    标签: angular localization angularbuild


    【解决方案1】:

    您必须在app.module 中提供语言环境

    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 {}
    

    【讨论】:

    • 将我的 angular.json 更改为 fr 而不是 fr-FR?根据 iso639 标准,fr-FR 是否不支持语言环境?
    猜你喜欢
    • 2016-02-22
    • 2020-04-18
    • 1970-01-01
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多