此外,当我尝试为特定语言在本地部署应用程序时,遇到了相同的问题。
我的要求是(Angular 15):
- 生产构建:构建所有语言。
- 本地开发:能够服务于所选语言。
从build:options
中删除"localize": true
,并将其放置在build:configurations:production
中。
然后在build:configurations:development
中设置"localize": false
。
此外,为语言设置新的配置(例如“en”和“it”)build:configurations:en
与"localize": ["en"]
和build:configurations:it
与"localize": ["it"]
。
在serve
部分中包含以下配置:serve:configurations:en
与"browserTarget": "MyApp:build:development,en"
和serve:configurations:it
与"browserTarget": "MyApp:build:development,it"
。
请确保在语言前使用逗号而不是冒号。
然后运行ng serve --configuration=it
以启动意大利语应用程序。
这是完整的angular.json
文件:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"myProject": {
"projectType": "application",
"i18n": {
"sourceLocale": "en",
"locales": {
"it": {
"translation": "./src/locale/messages.it.json",
"baseHref": ""
}
}
},
"schematics": {
"@schematics/angular:component": {
"style": "scss",
"skipTests": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/App",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"localize": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
"localize": false,
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
},
"en": {
"localize": ["en"]
},
"it": {
"localize": ["it"]
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "MyApp:build:production"
},
"development": {
"browserTarget": "MyApp:build:development"
},
"en": {
"browserTarget": "MyApp:build:development,en"
},
"it": {
"browserTarget": "MyApp:build:development,it"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "MyApp: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",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"src/**/*.ts",
"src/**/*.html"
]
}
}
}
}
},
"cli": {
"schematicCollections": [
"@angular-eslint/schematics"
],
"analytics": false
}
}