Use ngx-translate in a multi-module Angular setup and child-libraries
Asked Answered
K

0

7

I am using ngx-translate for translation in my Angular app. It works just fine with a simple project setup, but we develop a large-scale business application and different components are split into several seperate libraries.

Some of the libraries do need to have some translations and of course translation should change for all parts of the app with a click on the same button.

Using angular-librarian for bundling the component libraries I have so far not been succesful to just create one instance of ngx-translate for both the top-level Angular-Cli project and the included angular-librarian libraries.

I have tried several project-setups using basically all sorts of combinations of importing ngx-translate with forRoot() and / or forChild() without success. I always had either a missing provider, text showed up but languages did not change together or at all etc. pp.

Has anyone pulled this of and can show a working project-setup example / plunkr?

Kerwon answered 31/8, 2017 at 11:29 Comment(6)
have you managed to get something working?Eucalyptus
sorry no, not really. I workaround the problem by passing a custom translation object to the library now ... Not pretty, but it is only 6 strings that need translationKerwon
@newnoise can you explain a bit more regarding your workaround?Duque
@BrunoBruzzano it's really fairly straight forward passing the strings as @Inputs into the components of the library that need translated strings. Nothing special, I just avoided handling translations in my library at all.Kerwon
@newnoise not a viable solution in my case - but thanks!Duque
@BrunoBruzzano yes I know, I wouldn't really call it a solution after all, but for the very few strings we have it does the job. If you find a better way, please share it here with an answer or a comment.Kerwon

© 2022 - 2024 — McMap. All rights reserved.