角度元素与国际化(i18n)

时间:2020-04-08 11:38:00

标签: angular translation angular-i18n angular-elements

我正在一个具有Angular元素(或Angular Web组件)的项目中工作,我需要遵循Angular规则以西班牙语进行国际化(i18n)。

我的 angular.json 是:

.LC0:
        .string "%d and %d"
main:
        pushq   %rbp
        movq    %rsp, %rbp
        subq    $48, %rsp
        movl    $2, -8(%rbp)
        movl    $3, -4(%rbp)
        movl    $10, -48(%rbp)
        movl    $20, -44(%rbp)
        leaq    -8(%rbp), %rax
        movq    %rax, -40(%rbp)
        movl    -48(%rbp), %eax
        movl    %eax, -32(%rbp)
        movl    -44(%rbp), %eax
        movl    %eax, -28(%rbp)
        movb    $-1, -24(%rbp)
        movl    -44(%rbp), %edx
        movl    -48(%rbp), %eax
        movl    %eax, %esi
        movl    $.LC0, %edi
        movl    $0, %eax
        call    printf
        movl    $0, %eax
        leave
        ret

当我尝试构建项目时出现问题。当我执行此命令{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "my-component": { "projectType": "application", "schematics": { "@schematics/angular:component": { "style": "scss" }, "i18n": { "sourceLocale": "en", "locales": { "es": "src/locale/messages.es.xlf" } } }, "root": "", "sourceRoot": "src", "prefix": "app", "architect": { "build": { "builder": "ngx-build-plus:build", "options": { "outputPath": "dist/my-component", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.app.json", "aot": true, "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.scss" ], "scripts": [] }, "configurations": { "es": { "localize": ["es"] }, "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "5mb" }, { "type": "anyComponentStyle", "maximumWarning": "6kb", "maximumError": "10kb" } ] } } }, "serve": { "builder": "ngx-build-plus:dev-server", "options": { "browserTarget": "my-component:build" }, "configurations": { "production": { "browserTarget": "my-component:build:production" }, "es": { "browserTarget": "my-component:build:es" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "my-component:build" } }, "test": { "builder": "ngx-build-plus:karma", "options": { "main": "src/test.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.spec.json", "karmaConfig": "karma.conf.js", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.scss" ], "scripts": [] } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "tsconfig.app.json", "tsconfig.spec.json", "e2e/tsconfig.json" ], "exclude": [ "**/node_modules/**" ] } }, "e2e": { "builder": "@angular-devkit/build-angular:protractor", "options": { "protractorConfig": "e2e/protractor.conf.js", "devServerTarget": "my-component:serve" }, "configurations": { "production": { "devServerTarget": "my-component:serve:production" } } } } } }, "defaultProject": "my-component" } 来构建项目(用于角度元素)时,一切正常,但是当我尝试使用此命令ng build --prod --output-hashing none --single-bundle true来构建转换时,此错误出现在控制台中:

ng build --configuration=es

有什么解决办法的想法吗?

1 个答案:

答案 0 :(得分:0)

您需要将i18n部分移到schematics节点之外

"my-component": {
  "projectType": "application",
  "schematics": {
    "@schematics/angular:component": {
      "style": "scss"
    }
  },
   "i18n": {
      "sourceLocale": "en",
      "locales": {
        "es": "src/locale/messages.es.xlf"
      }
    },
  "root": "",
  "sourceRoot": "src",
相关问题