问题
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