Skip to content

application builder: LOCALE_ID is hardcoded in dist #26026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
zip-fa opened this issue Oct 12, 2023 · 6 comments · Fixed by #26045
Closed
1 task done

application builder: LOCALE_ID is hardcoded in dist #26026

zip-fa opened this issue Oct 12, 2023 · 6 comments · Fixed by #26045
Labels
angular/build:application needs: investigation Requires some digging to determine if action is needed

Comments

@zip-fa
Copy link

zip-fa commented Oct 12, 2023

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Hi.
After building project with ng build and application builder, LOCALE_ID is hardcoded to en-US

Minimal Reproduction

ng build

Exception or Error

No response

Your Environment

Angular CLI: 17.0.0-next.9
Node: 18.18.1
Package Manager: npm 9.8.1
OS: win32 x64

Angular: 17.0.0-next.8
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic
... platform-server, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.0-next.9
@angular-devkit/build-angular   17.0.0-next.9
@angular-devkit/core            17.0.0-next.8
@angular-devkit/schematics      17.0.0-next.8
@angular/cdk                    17.0.0-next.6
@angular/cli                    17.0.0-next.9
@angular/material               17.0.0-next.6
@angular/ssr                    17.0.0-next.9
@schematics/angular             16.2.5
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.0

Anything else relevant?

No response

@clydin
Copy link
Member

clydin commented Oct 12, 2023

The default locale of en-US for the framework is indeed hard coded within the @angular/core package.
However, the value can be changed by either configuring a provider within the application code or via the i18n.sourceLocale option within the project's configuration in angular.json.
Example:

  "projects": {
    "example-project": {
      "i18n": {
        "sourceLocale": "fr-CA"
      },
     ...

@zip-fa
Copy link
Author

zip-fa commented Oct 12, 2023

Here is my angular.json:

"i18n": {
    "sourceLocale": "ru",
    "locales": {
      "en": {
        "translation": "/src/locale/messages.en.xlf"
      },
      "pt-BR": {
        "translation": "/src/locale/messages.pt-BR.xlf"
      },
      "tr": {
        "translation": "/src/locale/messages.tr.xlf"
      },
      "uk": {
        "translation": "/src/locale/messages.uk.xlf"
      },
      "pl": {
        "translation": "/src/locale/messages.pl.xlf"
      },
      "zh-CN": {
        "translation": "/src/locale/messages.zh-CN.xlf"
      },
      "cs": {
        "translation": "/src/locale/messages.cs.xlf"
      },
      "fi": {
        "translation": "/src/locale/messages.fi.xlf"
      },
      "fr": {
        "translation": "/src/locale/messages.fr.xlf"
      },
      "de": {
        "translation": "/src/locale/messages.de.xlf"
      },
      "hu": {
        "translation": "/src/locale/messages.hu.xlf"
      },
      "it": {
        "translation": "/src/locale/messages.it.xlf"
      },
      "no": {
        "translation": "/src/locale/messages.no.xlf"
      },
      "pt": {
        "translation": "/src/locale/messages.pt.xlf"
      },
      "ro": {
        "translation": "/src/locale/messages.ro.xlf"
      },
      "sk": {
        "translation": "/src/locale/messages.sk.xlf"
      },
      "es": {
        "translation": "/src/locale/messages.es.xlf"
      },
      "sv": {
        "translation": "/src/locale/messages.sv.xlf"
      },
      "vi": {
        "translation": "/src/locale/messages.vi.xlf"
      }
    }
  },

every build's LOCALE_ID is set to en-US

@clydin
Copy link
Member

clydin commented Oct 12, 2023

The locale value is set via the $localize global within the polyfills output file and is read by the framework at runtime. The main output file will not contain the specified locale identifier (unless application code specifically contains it).

If the injected LOCALE_ID value is always the default of en-US at runtime, please provide a minimal reproduction demonstrating the problem as we are unfortunately unable to replicate the issue as described.

@alan-agius4 alan-agius4 added the needs: repro steps We cannot reproduce the issue with the information given label Oct 13, 2023
@zip-fa
Copy link
Author

zip-fa commented Oct 13, 2023

I don't really know what's going on here, but take a look at it:

https://github.com/zip-fa/angular-v17-bug

nx serve - fails with error:

It looks like your application or one of its dependencies is using i18n.
Angular 9 introduced a global `$localize()` function that needs to be loaded.
Please run `ng add @angular/localize` from the Angular CLI.
(For non-CLI projects, add `import '@angular/localize/init';` to your `polyfills.ts` file.
For server-side rendering applications add the import to your `main.server.ts` file.)

ng serve - ok

LOCALE_ID bug which i described can be reproduced with these steps:

  1. nx build
  2. node dist/test-project/server/en/server.mjs
  3. open http://localhost:4000 and look under Next Steps

This import in app.component.ts leads to fail:

import { test } from './core/common';

@clydin clydin removed the needs: repro steps We cannot reproduce the issue with the information given label Oct 13, 2023
@zip-fa
Copy link
Author

zip-fa commented Oct 17, 2023

Hi guys. Any news on this? Will this be fixed in rc?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
angular/build:application needs: investigation Requires some digging to determine if action is needed
Projects
None yet
3 participants