简体   繁体   中英

Angular CLI 6: Unknown option: '--locale'

Running ng serve with a custom locale data as the docs explain ( https://next.angular.io/guide/i18n ) in the new Angular 6, I'm getting this error:

Unknown option: '--locale'

The same is happening with delete-output-path and named-chunks . How can we set this flags now?

As part of introducing CLI Workspaces , the developers have removed build-related command line switches in favor of configuring them inside the new angular.json file.
After some digging into the new schema (available at the link above), the easiest way to reintroduce your localization switches would be to add them under the following path inside angular.json : projects/your-project/architect/build/options .

Then serve your app without any switches: ng serve .

In the long term, I suppose you are encouraged to define yourself different configurations and set those options over there. Again, see the schema for more about this.

Here is an example of what I did:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "my-app": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "i18nFile": "src/locale/messages.some-lang.xlf",
            "i18nLocale": "some-lang",
            "i18nFormat": "xlf",
            "aot": true,
            "assets": [ ...
            ],
            "styles": [ ...
...

Update

Apparently there is a PR for the documentation update , which explains how to do it (pretty much how I wrote it here ;-) )

For the record, --locale was also removed from ng build but they introduced instead --i18n-locale as specified in angular documentation .

Eg, you can do:

ng build --prod --i18n-locale de --i18n-format xlf --i18n-file src/locale/messages.de.xlf

Unfortunately, this does not work with ng serve .

With Angular 9, none of the above answers work (for ng serve at least). Here's how to do it:

Open angular.json file, go to architect -> build -> options section. Add the option "i18nLocale": "pt" for pt locale. This sets the default local of your app to pt .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM