Search code examples
angularinternationalizationcommand-line-interfacetranslationaot

i18n Angular 5 change translations


i have an Angular 5 CLI project. He works, but I don't know how to change the local by the website. If I want an English translation, I have to use this command:

ng build --aot --locale en --i18n-format xlf --i18n-file src/Ressources/translations/messages.en.xlf --missing-translation error

Or this command for a French translation:

ng build --aot --locale fr --i18n-format xlf --i18n-file src/Ressources/translations/messages.fr.xlf --missing-translation error

Etc... However, I have to make this change by a combo box and I don't have any idea how to do it.


Solution

  • For AOT, after you compile your project for en and fr you should serve in your nginx(or the http server you are using) an instance for each language, for example if your domain is: mydomain.com, it should be served smething like this: mydomain.com/en and mydomain.com/fr. Then in your combobox, you just redirect to the desired translation.