question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom component's dynamic translation loading

See original GitHub issue

I’m submitting a…


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

What is the motivation / use case for changing the behavior?

Current lazy loading behavior supports only application-related translations that are placed at one global folder. Even this case requires additional time to maintain component’s translation files that are separated with component’s folder.

i18n/
  en.json
  es.json
  todos/
    en.json
    es.json
src/
  some/
    module/
      component/
        todos/
          images/
          todos.ts
          todos.html
          todos.scss

Also there is no way to seamlessly provide lazy loaded shared lib components translations. Our case is a monorepo with a lot of libs that are used in different applications (at the same repository).

It would be cool to have an ability to provide custom dynamic imports for TRANSLOCO_SCOPE, like this

todos/
  images/
  translation/
    en.json
    es.json
  todos.ts
  todos.html
  todos.scss
export function en() { return import('./translation/en.json'); }
export function es() { return import('./translation/es.json'); }

@Component({
  providers: [
    {
      provide: TRANSLOCO_SCOPE,
      useFactory: () => ({
        scope: 'todos',
        translations: { en, es }
      }),
    },
  ]
})
export class ToDosComponent {}

Currently we found one way to achieve this with some hacks, but it works only at a module level and requires more code

Stackblitz https://stackblitz.com/github/artaommahe/transloco-dynamic-translations/tree/module Repo https://github.com/artaommahe/transloco-dynamic-translations/tree/module

There are an eagerly loaded component, dynamically loaded via routing and a component from lib. All have dyncamically loading translations that are placed next to the components files. E.x.

And the translations loading code on lang changes https://github.com/artaommahe/transloco-dynamic-translations/blob/module/libs/translate/src/module.ts#L18

updated solution below: https://github.com/ngneat/transloco/issues/121#issuecomment-540535199

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:30 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
shaharkazazcommented, Oct 15, 2019

Inline loaders are now avialable in v2.2.0.

We also released a schematics command to build a unified translation file from all the sub-translation files. Currently, it supports JSON format, but other formats support is in progress. 🙂

1reaction
NachoVazquezcommented, Oct 15, 2019

Amazing!! I’ll test it tonight.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Translation - Product Documentation | ServiceNow
You can dynamically translate text entered in an application, such as a user-entered text on forms, for a seamless localization experience.
Read more >
Dynamic translations in Angular made possible - Medium
A practical guide to implement lazy-loaded translations. If you have ever dealt with internationalization (or “i18n” for short) in Angular or is about...
Read more >
Dynamic component loader - Angular
An application might need to load new components at runtime. This cookbook shows you ... Angular comes with its own API for loading...
Read more >
Dynamic loading of translations during runtime in VueJS and ...
We're using the VueI18n plugin for internationalizing our Vue application which is working fine so far. Text contents are managed and translated ......
Read more >
Add or Load Translations - i18next documentation
If you want to lazy load some translations via a backend plugin, you may need to use the partialBundledLanguages: true option. This allows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found