angular - 没有项目支持 'extract-i18n' 目标

标签 angular typescript localization angular-cli angular-builder

我正在尝试在一个旧项目上添加一个新标签,该项目已经通过 Angular xi18n 进行了内部化

如何重新生成 xlf 文件? 或者我可以将自己的 trans-unit 手动插入到 xlf 文件中吗?如果可以,我可以制作自己的跨单位 ID 和线路号码吗?

因为当我使用与我使用的服务相同的路径尝试 ng xi18n 时,它返回以下错误:发生未处理的异常:没有项目支持“extract-i18n”目标。 [错误]错误:没有项目支持“extract-i18n”目标。

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)

这是我的 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"
  }
}

最佳答案

您需要使用 buildserve 目标定义一个 extract-i18n 目标长边:

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

关于angular - 没有项目支持 'extract-i18n' 目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70245516/

相关文章:

asp.net-mvc - Kendo UI MVC 日期选择器本地化

html - intro.js 中是否有任何选项可以使突出显示的文本或图像清晰

Angular i18n 与 em 和强?

javascript - Angular 补丁可观察数据到 react 表单字段

node.js - typescript /Node 意外 token *

string - 带有变量的 NSLocalizedString 对我不起作用

grails - 每个区域的Stripe Grails配置

Angular2 路由

Angular : how to trigger bindings manually?

typescript - 如何获得元组元组的扁平元组类型?