angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.79k stars 11.98k forks source link

Default to `sourceLocale` when `--localize=false` #16950

Closed javiermarinros closed 11 months ago

javiermarinros commented 4 years ago

This looks like a regression to me in v9:

I couldn't find a way to tell the cli the default locale to inject in my app instead of the default en-US. The only method I found is using the localize flag, but enabling it changes the way the app is built and slows the process with the extra Generating localized bundles phase.

Shouldn't it inject the sourceLocale defined in the angular.json the way the --i18nLocale flag used to worked in pre v9 versions?

dgp1130 commented 4 years ago

Hi @javiermarinros, can you give some more details on what you're trying to do?

Are you trying to make users visiting your site use a different locale by default? Are you trying to make local builds use a different locale by default? Are you trying to change the default value of LOCALE_ID injected into your app?

javiermarinros commented 4 years ago

Hi @dgp1130, I would like to configure the default app locale (that is hardcoded to en-US) without using the localize flag (that adds extra overhead during builds with the Generating localized bundles phase)

I think this could be better explained with an example: Using this angular.json should create builds injecting the es locale instead of en-US:

 "projects": {
    "projectName": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "i18n": {
        **"sourceLocale": "es"**
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            **"localize": false,**
            ...
dgp1130 commented 4 years ago

Ok, I think I'm understanding now. This was more of a historical limitation in View Engine when we didn't track sourceLocale as a separate locale, so we always used en-US. Currently there is no way to set the default to another locale without using --localize. The closest you can get is:

"projects": {
  "my-project": {
    // ...
    "i18n": {
      "sourceLocale": "es",
      "locales": {
        // ...
      }
    },
    "architect": {
      "build": {
        "options": {
          // ...
          "localize": [ "es" ]
        }
      }
    }
  }
}

Then ng serve would serve This would localize only to the Spanish language in default builds, though it still has the overhead costs you mentioned (but only for one language).

As a feature request this is pretty reasonable. It makes sense that the sourceLocale should be the default when --localize=false. To make this happen, when --localize=false, we'll need to:

  1. Include locale data in the bundle for sourceLocale.
  2. Set LOCALE_ID to the sourceLocale value, so modules which inject it are accurate.

Neither of these take too long in the build process, so they should not impact build times too much. The slow part is dealing with translations, which we don't have to do here because we are using the sourceLocale. Once that happens, ng serve and ng build should use sourceLocale throughout the app by default.

MarcusRiemer commented 3 years ago

Is there any ETA on this or any way someone from the outside could help? I am currently contemplating to switch the main language of my application to english because this step is almost a twentyfold increase in the buildstep when making changes: The incremental build finishes almost instantly, and the following localized bundle generation takes 10 to 20 seconds.

angular-robot[bot] commented 2 years ago

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

angular-robot[bot] commented 2 years ago

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

clydin commented 11 months ago

A v17 application will now work as explained in the above comments and use the sourceLocale for both the application locale and the available locale data. If upgrading from an earlier version to v17, also convert the project to the new build system via https://angular.dev/tools/cli/esbuild

angular-automatic-lock-bot[bot] commented 10 months ago

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.