gpt4 book ai didi

angular - 使用@angular/localize 对原始应用程序进行本地化后,如何将其设为 'ng serve'?

转载 作者:行者123 更新时间:2023-12-03 19:09:22 33 4
gpt4 key购买 nike

我在玩 Angular 的本地化 @angular/localize 并在配置它以将应用程序翻译成不同的语言后 我尝试使用“ng serve”提供默认版本但我收到此错误:

An unhandled exception occurred: The development server only supports localizing a single locale per build.
我基于此尝试使用不同的端口: How to serve different Angular locales during development using ng serve?但无济于事。
对于翻译版本的一切 作品 使用'ng serve --configuration=fr'。
构建 工作在 dist/App 文件夹中正确创建“en-US”和“fr”文件夹。
当我在 dev-server 中删除 inlineLocales.size 条件时,一切正常,没有错误:
if (i18n.shouldInline && tsConfig.options.enableIvy !== false) {
//if (i18n.inlineLocales.size > 1) {
// throw new Error('The development server only supports localizing a single locale per build');
//}
await setupLocalize(i18n, browserOptions, webpackConfig);
}
所以这可能是 Angular-devkit 的问题。
我试图通过创建新的“en-US”语言环境来解决,但出现此错误:
An unhandled exception occurred: An i18n locale ('en-US') cannot both be a source locale and provide a translation.
仅使用“en”而不是“en-US”并使用 <source> 创建新的翻译文件后和 <target>翻译是一样的,它使用 'ng serve --configuration=en' 工作,但它看起来像一个错误的解决方案。
这是我的 angular.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"App": {
"projectType": "application",
"i18n": {
"sourceLocale": "en-US",
"locales": {
"fr": "src/locale/messages.fr.xlf"
}
},
"schematics": {
"@schematics/angular:component": {
"style": "scss"
},
"@schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"localize": true,
"outputPath": "dist/App",
"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"],
"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": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
]
},
"fr": {
"localize": ["fr"]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "App:build"
},
"configurations": {
"production": {
"browserTarget": "App:build:production"
},
"fr": {
"browserTarget": "App:build:fr"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "App: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"],
"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": "App:serve"
},
"configurations": {
"production": {
"devServerTarget": "App:serve:production"
}
}
}
}
}
},
"defaultProject": "App"
}
如何重现:
该应用程序是使用 Angular CLI 10.0.0 和 Angular 10.0.1 生成的,然后通过“ng add @angular/localize”添加 @angular/localize。在 app.component.html 中是单 <h1 i18n="@@app.h1">Hello</h1> .使用上面的 angular.json。

最佳答案

在“选项”中,您必须将“本地化”设置为 false:

"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"localize": false,
并再次构建:
ng build

关于angular - 使用@angular/localize 对原始应用程序进行本地化后,如何将其设为 'ng serve'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62662003/

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