Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 217
Javier Marín Avatar asked May 04 '18 14:05

Javier Marín


2 Answers

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 ;-) )

like image 128
Jony Adamit Avatar answered Oct 19 '22 08:10

Jony Adamit


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

E.g, 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.

like image 21
Starscream Avatar answered Oct 19 '22 07:10

Starscream