[英]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.