I'm developing an app in two different languages (fa/en) using Angular Internationalization (i18n).
I can serve any of the localization (languages) like this
"architect": {
"build": {
...
,
"configurations": {
...
},
"fa": {
"localize": ["fa"],
"baseHref": "/fa/"
},
"en": {
"localize": ["en"],
"baseHref": "/en/"
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "app:build"
},
"configurations": {
"production": {
"browserTarget": "app:build:production"
},
"en": {
"browserTarget": "app:build:en"
},
"fa": {
"browserTarget": "app:build:fa"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "app:build"
}
},
...
}
And then ng serve --configuration=en
works and I have it on http://localhost:4200/en/...
But I need to serve both languages simultaneously during development to work on the styles and the correct layout and check the translations. If I try to do this in the build configuration "localize": ["fa","en"]
I get the following error.
An unhandled exception occurred: The development server only supports localizing a single locale per build
The best I got so far is to run ng serve ..
multiple times on different ports to have two instances of the development server in different locales but that is kinda ugly. I am hoping for a better solution.
You should not use ng serve for production because it use webpack-dev-server that is build for development only.
Syntax. ng serve command builds and serve the application. It rebuilds the application if changes occur. Here project is the name of the application as defined in angular.
Angular uses the Unicode locale identifier (Unicode locale ID) to find the correct locale data for internationalization of text strings. Unicode locale ID. A locale ID conforms to the Unicode Common Locale Data Repository (CLDR) core specification.
From the docs: The CLI supports running a live browser reload experience to users by running ng serve. This will compile the application upon file saves and reload the browser with the newly compiled application. This is done by hosting the application in memory and serving it via webpack-dev-server.
In Angular 9 the development server (ng serve) can only be used with a single locale.
However, you can still serve each locale on different ports by running two separate commands:
ng serve --configuration=fa --port 4200
ng serve --configuration=en --port 4201
Hopefully, they will introduce multiple locale options for development builds in Angular 10 🤞
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With