Angular 9 Locale data for 'en-US' cannot be found. No locale data will be included for this locale
Asked Answered
F

5

9

I am getting this strange warning

Locale data for 'en-US' cannot be found. No locale data will be included for this locale when running ng build --configuration=prod --localize

here is my angular.json

// omitted
"i18n": {
    "sourceLocale": "en-US",
    "locales": {
      "sr-Latn": {
        "translation": "src/locale/messages.sr.xlf",
        "baseHref": "/sr/"
      }
    }
  },
// omitted

The documentation clearly states en-US is imported by default. To make things worse, when i change sourceLocale to any other language (say 'de'), warning message goes away.
Manually registering en-US locale data doesnt help either

Fiji answered 28/12, 2019 at 20:41 Comment(1)
It is the same for hr-HRIbbie
E
5

It is working if you set sourceLocale to en.

  • But i cant figure out why the default value en-US dosnt work.
"i18n": {
    "sourceLocale": "en",
    "locales": {...}
}
Eudemon answered 9/2, 2020 at 14:52 Comment(0)
I
3

With the most recent version 9.0.2 you can specify the sourceLocale baseHref

"i18n": {
    "sourceLocale": {
      "baseHref": "/",
      "code": "en"
    },
    "locales": {
      "fr": "src/locale/messages.fr.xlf",
      "de": "src/locale/messages.de.xlf",
      "es": "src/locale/messages.es.xlf",
      "it": "src/locale/messages.it.xlf",
      "ja": "src/locale/messages.ja.xlf",
      "ko": "src/locale/messages.ko.xlf",
      "zh": {
        "translation": "src/locale/messages.cn.xlf",
        "baseHref": "/cn/"
      }
    }
Interpellant answered 3/3, 2020 at 18:13 Comment(0)
L
1

This is annoying indeed. The compiler expects to have en-US resource and even compiles the application using en-US and base-href.

This is how I solved this.

1) I just ignore the warning and en-US output directory.

2) I compile the application twice. First without --localized option. This compiles the original application, uses \ as base-href and does not used any translation files. Then I compile another time with --localized and that compiles all my languages with base-href matching the language codes.

ng build --prod --outputPath=dist/original
ng build --prod --outputPath=dist/localized --localize

3) I deploy the original build from dist/original and all the other builds from dist/localized except the en-US directory.

Laugh answered 2/1, 2020 at 22:8 Comment(1)
My problem is different. I actually do want to keep en-US build. Problem is missing locale data for en-US even though en-US data should be installed by defaultFiji
H
1

I have the same problem.

Like you said, the default for LOCALE_ID seems to be en-US, as this is what it represents when nothing is specified.

Further, looking at @angular/common/locales/* it seems like, the default for registerLocaleData is en. @angular/common/locales/en exists, @angular/common/locales/en-US does not exist! Same with de-DE: @angular/common/locales/de-DE does not exist, but @angular/common/locales/de does.

For now, I have switched everything to en/de and it works:


Example localising for English and German:

angular.json

[...]
      "i18n": {
        "sourceLocale": "en",
        "locales": {
          "de": "src/locale/messages.de.xlf"
        }
      }
[...]

app.module.ts

[...]
import { registerLocaleData } from '@angular/common';
import localeDe from '@angular/common/locales/de';
import localeEn from '@angular/common/locales/en';

registerLocaleData(localeDe, localeEn);
[...]
Haygood answered 10/3, 2020 at 14:9 Comment(0)
H
0

Maybe it has to do with that fact that the file is named en-US-POSIX as seen here https://github.com/angular/angular/blob/master/packages/common/locales/en-US-POSIX.ts

Trying to dynamically import('@angular/common/locales/en-US-POSIX') works.

So trying this might work

"i18n": {
    "sourceLocale": "en-US-POSIX",
    "locales": {...}
}
Heather answered 10/11, 2020 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.