Inline Loaders
When working on a feature module or a library (a common practice in a monorepo environment), it's often useful to include translation files inside the module folder and package them alongside the module. To facilitate this, Transloco supports scopes with inline loaders. This feature allows you to specify a scope name and provide an inline loader that uses ESBuild/Webpack's import
function to lazily load the local translation files.
For example, consider the following Angular CLI project structure:
π¦projects β πfeature β β£ πsrc β β β£ πlib β β β β£ πi18n β β β β β£ en.json β β β β β es.json β β β β£ feature.component.ts β β β β£ feature.routes.ts β β β β feature.service.ts β β β£ public-api.ts π¦src β£ πapp β β£ app.routes.ts β β£ app.component.css β β£ app.component.html β β£ app.component.ts β β£ app.config.ts β β transloco.loader.ts β£ πassets β β£ πi18n β β β£ en.json β β β es.json
Inside the feature route or component, we can define a scope provider and pass an inline loader that dynamically loads translation files:
Now, you can translate the content using the defined scope
:
Last updated
Was this helpful?