Use of Inline Loaders when building a library with Ng-Packagr
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[x] Support request
[ ] Other... Please describe:
Current behavior
I just switched from ngx-translate to transloco in order to deal with lazy loading issues with my libraries.
So I’m using the Inline Loaders feature.
My issue is not related to transloco itself, but how to use transloco when building a library with ng-packagr.
Here is the transloco Inline Loader example from the doc :
export const loader = ['en', 'es'].reduce((acc, lang) => {
acc[lang] = () => import(`../i18n/${lang}.json`);
return acc;
}, {});
It uses dynamic import. But ng-packagr does not support it for now. See this this issue.
My question is how to deal with this ? I believe Ng-packagr is used a lot and I wonder how you guys handle this situation. Inline Loaders seems to be meant to work with library, so I suppose this need is common.
Thank you
Environment
Angular version: 8.2.11
Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [x] Firefox version 70
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: 10.16.0
- Platform: Windows
Others:
ng-packagr: 5.7.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Angular Library with ng-packagr - Medium
We can developer libraries using the ng-packagr, which is a project ... It is consumed by different module loaders, inline the templates by ......
Read more >ng-packagr - npm
Compile and package Angular libraries in Angular Package Format (APF). Latest version: 15.0.3, last published: 13 days ago.
Read more >How to create an Angular Component Library - SystemJs and ...
In this post we are going to see how an Angular component library can be built and then consumed using both SystemJs and...
Read more >Lazy translation assets with Angular, Transloco and Nx ...
Instead, making use of webpack's inline loaders and Nx's buildable libs; you can fetch smaller translation assets only for a feature's scope ...
Read more >Creating a Library in Angular 6 using Angular CLI and ng ...
This article takes a close look at what happens when you run "ng new", explores the notion of a workspace and library modules...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have tested your solution and it works !
I did the eager imports in each modules of my library (that is packaged as npm), and called setTranslation in their constructors as you proposed.
Each modules’s components of my library are effectively translated according to their own i18n file, without any work in my main application that use these components.
I’m admitting that I do not understand how this works, because I expected setTranslation calls to override each others. I’m guessing there is a TranslationService instance for each module, so there is no override.
In order to help people who reads this issue, here some steps I have been through :
*transloco="let t;"
in the top tag of my templates and used t(‘i18n.key’) to do translationsThanks a lot for your support 👍
I don’t know if it’s in transloco scope, but i think these steps might help other people.
Thanks for your detailed summary. Transloco doesn’t create new instance for each module. When you call
setTranslation
by default it merges the translations. We hope thatng-packagr
will add theimport
support in the future, and when it does it will work out of the box. I’m closing this issue for now.