angulartypescriptlocalizationangular-cliangular-builder

No projects support the 'extract-i18n' target


I'm trying to add a new label on an old project which already have an existing internalization with Angular xi18n

how can I regenerate an xlf file? or can I just insert my own trans-unit manually into the xlf file? if yes can I make my own trans-unit id and line number?

because when I tried ng xi18n with the same path I use serve it returns the following error: An unhandled exception occurred: No projects support the 'extract-i18n' target. [error] Error: No projects support the 'extract-i18n' target.

at Xi18nCommand.initialize (C:\Project\src\webadmin\node_modules\@angular\cli\models\architect-command.js:53:19)
at async Xi18nCommand.validateAndRun (C:\Project\src\webadmin\node_modules\@angular\cli\models\command.js:124:9)
at async Object.runCommand (C:\Project\src\webadmin\node_modules\@angular\cli\models\command-runner.js:201:24)
at async default_1 (C:\Project\src\webadmin\node_modules\@angular\cli\lib\cli\index.js:62:31)

Here's my angular.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "webadmin": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "i18n": {
        "sourceLocale": "en",
        "locales": {
          "fr": "src/locale/messages.fr.xlf",
          "de": "src/locale/messages.de.xlf"
        }
      },
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/webadmin",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets/"
              },
              {
                "glob": "favicon.ico", 
                "input": "src",
                "output": "/" 
              }
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "node_modules/ngx-toastr/toastr.css",
              "src/styles.scss"
            ],
            "scripts": [],
            "es5BrowserSupport": true
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            },
            "int": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.int.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            },
            "test": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.test.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            },
            "dev": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            },
            "local": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.local.ts"
                }
              ]
            },
            "fr": {
              "localize": [
                "fr"
              ],
              "aot": true,
              "i18nFile": "src/locale/messages.fr.xlf",
              "i18nFormat": "xlf",
              "i18nLocale": "fr"
            },
            "de": {
              "localize": [
                "de"
              ],
              "aot": true,
              "i18nFile": "src/locale/messages.de.xlf",
              "i18nFormat": "xlf",
              "i18nLocale": "de"
            },
            "de-int": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.int.ts"
                }
              ],
              "localize": [
                "de"
              ],
              "aot": true,
              "i18nFile": "src/locale/messages.de.xlf",
              "i18nFormat": "xlf",
              "i18nLocale": "de"
            },
            "de-test": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.test.ts"
                }
              ],
              "localize": [
                "de"
              ],
              "aot": true,
              "i18nFile": "src/locale/messages.de.xlf",
              "i18nFormat": "xlf",
              "i18nLocale": "de"
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "webadmin:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "webadmin:build:production"
            },
            "local": {
              "browserTarget": "webadmin:build:local"
            },
            "fr": {
              "browserTarget": "webadmin:build:fr",
              "aot": true
            },
            "de": {
              "browserTarget": "webadmin:build:de"
            },
            "de-int": {
              "browserTarget": "webadmin:build:de-int"
            },
            "de-test": {
              "browserTarget": "webadmin:build:de-test"
            }
          }
        }
      }
    }
  },
  "defaultProject": "webadmin",
  "cli": {
    "analytics": "9009c4ee-47f2-453c-af4a"
  }
}

Solution

  • You need to define an extract-i18n target longside with build and serve targets:

    "build": {
      ...
    },
    "serve": {
      ...
    },
    "extract-i18n": {
      "builder": "@angular-devkit/build-angular:extract-i18n",
      "options": {
         "browserTarget": "webadmin:build"
      }
    }