Angular npm run build - 找不到 'fr-FR' 的区域设置数据

标签 angular localization angularbuild

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

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

"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 和其他语言环境)会看到相同的消息。

最佳答案

您必须在 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 npm run build - 找不到 'fr-FR' 的区域设置数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70086941/

相关文章:

orm - 类/对象 View 中的本地化表

java - 默认区域设置和数字格式

angular - 为什么 Angular 5 中的错误为 : has no exported member 'OpaqueToken' . ?

html - 需要根据打开和关闭的括号为数组元素应用边框

javascript - 从多个 HTTP 请求加载 RxJs/Angular 并从每个请求更新模型

javascript - Angular9:构建有额外的编译步骤

javascript - 具有树摇动依赖项的 Rollup Angular 2 应用程序

ios - 无法本地化 iOS info.plist 文件中的字符串

angular - 使用 Angular 构建在浏览器中加载包时,为什么估计传输大小没有反射(reflect)?