Skip to content

sourceLocale not used for LOCALE_ID in angular 19 #59422

Closed

Description

@DaSchTour

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

Description

Documentation describes setting the LOCALE_ID with sourceLocale in angular.json. This doesn't work with angular19 and/or new application executor.

LOCALE_ID is always en-US

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

NX   Report complete - copy this into the issue template

Node           : 22.11.0
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.9.0

nx                     : 20.3.0
@nx/js                 : 20.3.0
@nx/jest               : 20.3.0
@nx/eslint             : 20.3.0
@nx/workspace          : 20.3.0
@nx/angular            : 20.3.0
@nx/cypress            : 20.3.0
@nx/devkit             : 20.3.0
@nx/eslint-plugin      : 20.3.0
@nx/module-federation  : 20.3.0
@nx/plugin             : 20.3.0
@nx/storybook          : 20.3.0
@nx/web                : 20.3.0
@nx/webpack            : 20.3.0
typescript             : 5.6.3
---------------------------------------
Registered Plugins:
@nx/eslint/plugin
---------------------------------------
Community plugins:
@ngneat/hot-toast     : 6.1.0
@ngneat/spectator     : 19.3.0
@ngrx/component       : 19.0.0
@ngrx/component-store : 19.0.0
@ngrx/effects         : 19.0.0
@ngrx/entity          : 19.0.0
@ngrx/eslint-plugin   : 19.0.0
@ngrx/operators       : 19.0.0
@ngrx/router-store    : 19.0.0
@ngrx/schematics      : 19.0.0
@ngrx/store           : 19.0.0
@ngrx/store-devtools  : 19.0.0
@storybook/angular    : 8.4.7
angular-eslint        : 19.0.2
apollo-angular        : 8.0.0
ng-mocks              : 14.13.1

Anything else?

The documentation about sourceLocale could be extended a bit more, as it may not be clear where to set sourceLocale.

Activity

  1. wartab commented on Jan 8, 2025

    @wartab
    Contributor

    Seems like it's similar to this (there's a solution in there that worked for the bug reporter):
    #59405

    I'm not sure if this needs to be fixed by Angular, though.

  2. DaSchTour commented on Jan 8, 2025

    @DaSchTour
    Author

    Well I have some places with import "@angular/localize/init";which is different from what the author describes. But without these imports I get compile errors with TS2304: Cannot find name '$localize'.

    I guess the many changes to $localize probably without any migration needs some refactoring. It's very strange behaviour.

    The documentation stating

    It adds types: ["@angular/localize"] in the TypeScript configuration files as well as the reference to the type definition of @angular/localize at the top of the main.ts file.

    Is not really helpful for migration. Localize was added before this was part of the generator. So it would really be helpful to have the actual outcome documented and not only what the generator should do which it didn't do in the past.

  3. alan-agius4 commented on Jan 8, 2025

    @alan-agius4
    Contributor

    import "@angular/localize/init"; should never be imported directly in the code as this can cause undefined behaviour. In that case you are getting TS2304: Cannot find name '$localize'. you need to add "@angular/localize" in the types array of your tsconfig.json.

  4. DaSchTour commented on Jan 8, 2025

    @DaSchTour
    Author

    Which was changed between Angular 14 and Angular 15?
    Well actually /// <reference types="@angular/localize" /> was missing in the main.ts to make it work. Had to create a new angular application and check this.

  5. wartab commented on Jan 8, 2025

    @wartab
    Contributor

    @alan-agius4 I'm not sure if there's a way for you guys to detect the wrong import in dev-mode and print a warning in the console for that?

  6. DaSchTour commented on Jan 8, 2025

    @DaSchTour
    Author

    Probably this message I get in my jest unit tests now is outdated as it tells to add import "@angular/localize/init";?

    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.)
    
  7. alan-agius4 commented on Jan 8, 2025

    @alan-agius4
    Contributor

    If you're not using the Angular CLI, you may need to add import "@angular/localize/init"; to your polyfills to resolve the error in this case or in your the testing setup.

    However, there is an ongoing issue regarding completely removing the exports, which can be tracked here: #48545.

  8. alan-agius4 commented on Jan 8, 2025

    @alan-agius4
    Contributor

    I'm not sure if there's a way for you guys to detect the wrong import in dev-mode and print a warning in the console for that?

    We could do that, although #48545 does seem like the preferred solution

  9. e-oz commented on Jan 10, 2025

    @e-oz

    If you're not using the Angular CLI, you may need to add import "@angular/localize/init"

    So if the export is completely removed, what will be the options for those who use Nx (for example)?

  10. alan-agius4 commented on Jan 10, 2025

    @alan-agius4
    Contributor

    With NX it's no different from using the Angular CLI, it needs to be added as a polyfill.

  11. e-oz commented on Jan 10, 2025

    @e-oz

    And you are correct!

    Nx generates tsconfig.lib.json and tsconfig.spec.json files without "@angular/localize" inside, so I replaced in tsconfig.spec.json:

    "types": ["jest", "node"]
    

    with

    "types": ["jest", "node", "@angular/localize"]
    

    and in tsconfig.lib.json:

    "types": []
    

    with

    "types": ["@angular/localize"]
    

    then removed import '@angular/localize/init'; and import { $localize } from '@angular/localize/init'; from everywhere, and everything works fine. And no more warnings :)

    Thank you, @alan-agius4 !

  12. angular-automatic-lock-bot commented on Feb 10, 2025

    @angular-automatic-lock-bot

    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.

  13. locked and limited conversation to collaborators on Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions