from this link I tried to implement the i18 internationalization in my Angular 6 app in order to translate in english and italian some text and datetime in my html template.
https://next.angular.io/guide/i18n
I understood that this function consist in 3 phases:
1) Define translation text. No problem, I created a folder src/locale folder with 2 files messages.en.xlf (and message.it.xlf); here is an example for en version.
<trans-unit id="introductionHeader" datatype="html">
<source>Hello i18n! (en-EN)</source>
<note priority="1" from="description">An introduction header for this sample</note>
<note priority="1" from="meaning">User welcome</note>
</trans-unit>
2) link this text to html pages with appropriates tag, and also here no problem, there is my example tag in my app.translations.html.
<h1 i18n="User welcome|An introduction header for this sample">
Hello i18n!
</h1>
Now, I read the way (3. phase) to localize the app during startup (some editing in Angular.json file and start ng serve with configuration option); but, instead of this, I would change the language of the app programmatically. In other words, I want a command such as
SwitchAppLanguage('en')
for example, so that the user can change it self by a button or the app can do this reading the browser default language. How can I do this?
Thank you very much!
Edit: I tried to edit my angular.json file in this way
"configurations": {
"production": {
"i18nFile": "src/locale/messages.it.xlf",
"i18nFormat": "xlf",
"i18nLocale": "it",
(...)
And, after ng build and ng serve, I expect to see the italian text but it doesn't happens (and the app start and serve correctly). What do I wrong? Thanks!
window.location.href = urlOfTheOtherApp;. - JB Nizet