How to load separate translation files per module
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[x] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request
Expected/desired behavior Our application is very large and we don’t want the user to download all translations when they may only use a subset of the available modules. In some places the user must also be able to switch languages. Is there a way to load only the translations for the modules the user has access to? I’ve seen #22, but it doesn’t seem to have arrived at a final solution.
@nchutchind / @ollwenjones, I would love to hear about either of your solutions if you ever arrived at one?
What is the motivation / use case for changing the behavior? To prevent users from downloading resources they don’t require and allow dynamically switching languages at runtime
Please tell us about your environment: angular-cli@1.0.0-beta.26 generated so no access to webpack config etc
- ng2-translate version: latest
- Angular version: 2.4.5
- Language: TypeScript 2.1.5
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (4 by maintainers)
Top GitHub Comments
@uberspeck i did something similar but using
require
on each lazy loaded module i have thisBTW for do that i did a PR for allow deep merge of objects
@AlwaysAbhl001, i’ve created a simple service to load translations for each module/component…
/app/shared/services/translation-loader.service.ts
…then create the language files. You could use a different shape here if you wish.
/app/app.en.ts
…I then configure translation in the root module and load the root translation files…
/app/app.module.ts
…and set up translation in each feature module/component as necessary…
/app/feature-module/feature.module.ts
…and finally, in a component…
I’m sure this solution isn’t perfect, but it works for us. If you come up with improvements I’d love to hear them! Something to watch out for. You can’t rely on translations from lazy loaded sibling or child modules to be present so make sure any translations needed across lazy loaded modules are available to a parent of those modules. Hope that helps!