Angular 9国际化

问题描述 投票:0回答:1

我正在尝试使用Angular 9中的新国际化方式来更改我们现有的应用程序。这是我在angular.json中配置它的方式:

{
...
"projects": {
    "my-project": {
      ...
      "i18n": {
        "sourceLocale": "en-US",
        "locales": {
          "bg": "src/locale/messages.bg.xlf"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "customWebpackConfig": {
              "path": "./extra-webpack.config.js"
            },
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              ...
            ],
            "styles": [
              ...
            ],
            "scripts": [
              ...
            ],
            "i18nMissingTranslation": "error"
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            },
            "bg": {
              "localize": ["bg"]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "viewer:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "viewer:build:production"
            },
            "bg": {
              "browserTarget": "viewer:build:bg"
            }
          }
        },
        "extract-i18n": {
          ...
        },
        "test": {
          ...
        },
        "lint": {
          ...
        }
      }
    },
    "viewer-e2e": {
      ...
    }
  },
  ...
}

但是当我运行ng serve --configuration=bg时,它仍然提供默认的en翻译。有什么想法吗?

angular internationalization
1个回答
0
投票

尝试在aot文件中将true设置为angular.json。没有此功能,它将使用JIT模式,为此您需要使用TRANSLATIONS令牌动态提供翻译。

"architect": {
    "build": {
      "builder": "@angular-builders/custom-webpack:browser",
      "options": {
        "aot": true,
        "customWebpackConfig": {
          "path": "./extra-webpack.config.js"
        },
© www.soinside.com 2019 - 2024. All rights reserved.