![](/img/trans.png)
[英]An unhandled exception occurred: Configuration 'dev' is not set in the workspace
[英]An unhandled exception occurred: Configuration 'es' is not set in the workspace
我正在創建一個使用 i18n 支持不同語言的 Angular 應用程序。 該應用程序可以很好地使用英語。 但是,我嘗試使用以下 CLI 命令檢查西班牙語:
ng serve --configuration=es
出現未處理的錯誤。 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
}
}
能否請您幫忙查找文件中的配置問題。
您需要使用18n
然后使用locales
來指定翻譯語言環境。 另請參閱在構建配置中定義語言環境
"projects": {
"i18nDemo": {
"i18n": {
"sourceLocale": {
"code": "en"
},
"locales": {
"es": {
"translation": "src/translate/messages.es.xlf"
}
}
}
這樣,當您使用 cli 命令時,所有翻譯都將被編譯
ng build --localize
就配置而言,問題在於您將配置"es"
嵌套在"production"
配置內而不是在其下。 這是將"es"
移到"production"
之外的簡單問題。 盡管考慮到您要設置的內容,但我認為在這種情況下沒有任何理由使用名為“es”的配置部分。 另請參閱僅對一種語言環境應用特定的構建選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.