i18n with ngrx store - translating angular application

丶灬走出姿态 提交于 2019-12-12 23:38:41

问题


I'm writing to ask you for advice. We build store based angular application, which requires translation. The request is to use official angular i18n method, although I have no idea how to connect my translations with values from the store. Is it even possible, does anyone have any experience with this or should I straight away go to the solutions like ngx-translate library..? I must say I researched quite a bit, but have not found understandable (I'm a junior and it's pretty hard for me to grasps all pros, cons and what's possible) answers. So my request is to share your knowledge if you have any applicable experience. Thanks in advance!


回答1:


Tl;dr; Use Ngrx and I18n -- but don't store translations in Ngrx store.

So using Ngrx and the Angular platform I18n tools together is fine. That said, your translations won't be in the Ngrx store. The store is for application State. This state typically is backed from a data source.

The i18n translation are separate from the application state. The translations are statically compiled into the application at build time. This can be automated to place the Spanish build in dist/es/ and the french in dist/fr/ and so on.

Because it is compile time, there is no runtime translation that the state store can even touch.

Now this may change with Angular 6, where there may be a concept of runtime translations like in ngx-translate. That said, I still wouldn't put translations into the state store unless I was forced to because they come from a web service.



来源:https://stackoverflow.com/questions/48545613/i18n-with-ngrx-store-translating-angular-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!