We are developing an app with Angular 8.2. This question is not related to AngularJs.
I have read the Angular localization document here: https://angular.io/guide/i18n
But it seems that localization was done in the building process. After the app is built, it can't be changed. So how can we build an Angular app which supports language switching without the internet?
Our app is deployed behind CDN. The CDN servers reverse-proxy the HTML, JavaScript and CSS files and will cache all files passed. The server-side app language switching is not available.
And we have provided a client-side app based on the electron. We need to deliver the app once and the user can switch between different languages without the internet. But I have found no solution to it.
You may mention that we can switch language via the switching the domain. But for CORS reason, our client-side app domain name is limited and can not be switched. So only one domain name is available.
And we have built and published our app to the Google Play Store via TWA. The domain was registered with the app. Switching domains also cause downloading the app from Store again.
And the source code of the app is here: https://github.com/AiursoftWeb/Kahla.App
Just for possible additional info. Don't have to check it for answering this question.
We've faced similar requirements in past and that's why I created a blog post about translations in Angular as a code (without libs just your code and project architecture).
https://medium.com/angular-in-depth/angular-typed-translations-29353f0a60bc
To answer all of the challenges:
CDN:
domain.com/language/page
domain.com
may include some redirect logic
Electron:
Domain:
domain.com/en/contact
for English domain.com/cs/contact
for CzechGoogle Play Store:
Even if you decide not going with the "route" based switching, you may store the translations in your state management or wrapping service and access them as you would do with any other "async" data in the template via async
pipe
3rd Party: Some other solutions involving 3rd party libs are ngx-translate (deprecated) and Transloco