sm-sayedi
sm-sayedi

Reputation: 935

Change the Angular app language dynamically using @angular/localize

I use @angular/localize to localize my Angular app. Is there a way to change the app locale dynamically; for example by using a dropdown button? I am fine with reloading the page when the locale is changed!

Note: There are third-party packages that make this possible, for example ngx-translate, but I would like to use a first-party solution.

Upvotes: 0

Views: 45

Answers (1)

JSON Derulo
JSON Derulo

Reputation: 17698

Typically when building an Angular i18n app, for each language a new directory is created during the build, for example for english the built app is located in /en/ or for french in /fr/ etc. See the i18n deploy guide.

So, when you want to give the users the possibility to change the language, simply add a link using the updated prefix:

<a href="/en/">English</a>

Upvotes: 0

Related Questions