简体   繁体   English

发生未处理的异常:工作区中未设置配置“es”

[英]An unhandled exception occurred: Configuration 'es' is not set in the workspace

I am creating an Angular App that support different language by using i18n.我正在创建一个使用 i18n 支持不同语言的 Angular 应用程序。 The app working well with English language.该应用程序可以很好地使用英语。 However, I tried to check Spanish language using the following CLI command:但是,我尝试使用以下 CLI 命令检查西班牙语:

ng serve --configuration=es

The unhandled error appears.出现未处理的错误。 The modified versoin of The Angular.json shown below: The Angular.json 的修改版本如下所示:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "i18nDemo": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/i18nDemo",
            "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.css"
            ],
            "scripts": []
          },
          "configurations": {
            "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"
                }
              ],
              "es": { 
                "aot": true, 
                "i18nFile": "src/translate/messages.es.xlf", 
                "i18nFormat": "xlf",
                "i18nLocale": "es", 
                "i18nMissingTranslation": "error" }
            }
          }
        
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "i18nDemo:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "i18nDemo:build:production"
            },
            "es": {
              "browserTarget": "i18nDemo:build:es"
             }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "i18nDemo:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular: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.css"
            ],
            "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": "i18nDemo:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "i18nDemo:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "i18nDemo",
  "cli": {
    "analytics": false
  }
}

Could you please help to find the configuration issue in the file.能否请您帮忙查找文件中的配置问题。

You need to use the 18n and then locales to specify the translation locales.您需要使用18n然后使用locales来指定翻译语言环境。 See also Define locales in the build configuration另请参阅在构建配置中定义语言环境

  "projects": {
    "i18nDemo": {
      "i18n": {
        "sourceLocale": {
          "code": "en"
        },
        "locales": {
          "es": {
            "translation": "src/translate/messages.es.xlf"
          }
        }
      }

That way all your translations will be compiled when you use the cli command这样,当您使用 cli 命令时,所有翻译都将被编译

ng build --localize

As far as the configuration the issue is that you have the configuration "es" nested inside the "production" configuration instead of under it.就配置而言,问题在于您将配置"es"嵌套在"production"配置内而不是在其下。 That is a simple matter of moving "es" to outside of "production" .这是将"es"移到"production"之外的简单问题。 I do not see any reason to have a configuration section named "es" in this case though given what you are trying to set.尽管考虑到您要设置的内容,但我认为在这种情况下没有任何理由使用名为“es”的配置部分。 See also Apply specific build options for just one locale .另请参阅仅对一种语言环境应用特定的构建选项

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发生未处理的异常:工作区中未设置配置“dev” - An unhandled exception occurred: Configuration 'dev' is not set in the workspace 发生未处理的异常:工作区中未设置配置“生产” - An unhandled exception occurred: Configuration 'production' is not set in the workspace 发生未处理的异常:在工作空间中未设置配置'es5'。 ng在角度8中投放es5 - An unhandled exception occurred: Configuration 'es5' is not set in the workspace. ng serve in angular 8 for es5 Angular ng 服务导致:发生未处理的异常:未在工作区中设置配置“生产” - Angular ng serve leads to: An unhandled exception occurred: Configuration 'production' is not set in the workspace 发生未处理的异常:D:\workspace-angular\demoapp1 包含 both.browserslistrc 和 browserslist - An unhandled exception occurred: D:\workspace-angular\demoapp1 contains both .browserslistrc and browserslist 将角度版本从 10 更新到 12 显示:发生未处理的异常:必须使用导入来加载 ES 模块 - Updating angular version from 10 to 12 shows : An unhandled exception occurred: Must use import to load ES Module Angular 9 build 正在为差异加载生成 ES5 包...发生未处理的异常: - Angular 9 build Generating ES5 bundles for differential loading... An unhandled exception occurred : 发生未处理的异常:NGCC 失败 - An unhandled exception occurred: NGCC failed Angular 配置未设置到工作区 - Angular configuration not set to the workspace Angular - 工作区中未设置配置 - Angular - Configuration is not set in the workspace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM