[英]Angular CLI 6: Unknown option: '--locale'
在新的 Angular 6 中,按照文檔解釋( https://next.angular.io/guide/i18n )使用自定義區域設置數據運行ng serve
,我收到此錯誤:
Unknown option: '--locale'
delete-output-path
和named-chunks
。 我們現在如何設置這個標志?
作為引入CLI Workspaces 的一部分,開發人員刪除了與構建相關的命令行開關,轉而在新的angular.json
文件中配置它們。
在深入研究新模式(可在上面的鏈接中找到)之后,重新引入本地化開關的最簡單方法是將它們添加到angular.json
的以下路徑下: projects/your-project/architect/build/options 。
然后在沒有任何開關的情況下為您的應用ng serve
: ng serve
。
從長遠來看,我想鼓勵您定義自己不同的配置並在那里設置這些選項。 同樣,請參閱架構了解更多信息。
這是我所做的一個例子:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"my-app": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"i18nFile": "src/locale/messages.some-lang.xlf",
"i18nLocale": "some-lang",
"i18nFormat": "xlf",
"aot": true,
"assets": [ ...
],
"styles": [ ...
...
作為記錄,-- --locale
也從ng build
刪除,但他們引入了--i18n-locale
如angular 文檔中指定的那樣。
例如,你可以這樣做:
ng build --prod --i18n-locale de --i18n-format xlf --i18n-file src/locale/messages.de.xlf
不幸的是,這不適用於ng serve
。
使用 Angular 9,上述答案都不起作用(至少對於ng serve
)。 這是如何做到的:
打開angular.json
文件,轉到architect -> build -> options
部分。 為pt
語言環境添加選項"i18nLocale": "pt"
。 這會將您的應用程序的默認本地設置為pt
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.