gpt4 book ai didi

Angular 9 国际化 - 请求的语言环境错误

转载 作者:行者123 更新时间:2023-12-04 16:27:06 25 4
gpt4 key购买 nike

我正在 Angular 9 中使用新的国际化方式创建一个新应用程序。当我运行命令时 ng serve --configuration=en我收到以下错误 -

An unhandled exception occurred: Requested locale 'en' is not defined for the project.



我已经验证了 xlf 文件位置。存在区域设置文件。应用程序在没有配置参数的情况下运行良好。我的项目的 Angular.json -
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"khelFever2": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
},
"i18n": {
"locales": {
"en": "src/locale/messages.en.xlf",
"hi": "src/locale/messages.hi.xlf"
}
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/khelFever2",
"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",
"node_modules/bootstrap/dist/css/bootstrap.min.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"
}
]
},
"en": {
"localize": ["en"]
},
"hi": {
"localize": ["hi"]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "khelFever2:build"
},
"configurations": {
"production": {
"browserTarget": "khelFever2:build:production"
},
"en": {
"browserTarget": "khelFever2:build:en"
},
"hi": {
"browserTarget": "khelFever2:build:hi"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "khelFever2: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.scss",
"node_modules/bootstrap/dist/css/bootstrap.min.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": "khelFever2:serve"
},
"configurations": {
"production": {
"devServerTarget": "khelFever2:serve:production"
}
}
}
}
}
},
"defaultProject": "khelFever2",
"cli": {
"analytics": false
}
}

最佳答案

这个错误是因为你包含了 i18n schematics 中的数据节点。您需要将其向上移动一级

试试

"projects": {
"khelFever2": {
"projectType": "application",
"i18n": {
"locales": {
"en": "src/locale/messages.en.xlf",
"hi": "src/locale/messages.hi.xlf"
}
}
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",

关于Angular 9 国际化 - 请求的语言环境错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61705840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com