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.

How to know when the translation bundles are loaded

See original GitHub issue

I’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

Current behavior I have the necessity to know then the translation bundle is loaded and only then do some extra work. In my case I need to load other modules translations (not lazy-loaded) and I noticed that when a bundle is loaded it completely overrides existing translations instead of merging like setTranslation does with shouldMerge. (Probably related to this line of code, I’ll make a PR if necessary.) Therefore I need a way to know when the AppModule bundle is loaded with the specified loader. For the time being I resolved subscribing translate.use() and setting a custom AsyncSubject, but I’m not sure it’s the correct Observable to subscribe to. Another way would be maybe creating a custom loader with an AsyncSubject, but wouldn’t be very different from the former solution I suppose.

  • ngx-translate version: 6.0.0

  • Angular version: 2.4.x

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:15
  • Comments:11

github_iconTop GitHub Comments

4reactions
BeSpunkycommented, Oct 14, 2019

Just use one of the following observables:

  • onDefaultLangChange
  • onLangChange
  • onTranslationChange

You would probably want to pipe it with a take(1) operator to avoid triggering your code multiple times (and also release memory by having the observable complete after one emission):

import { take } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';

export class SomeComponentOrService
{
    constructor(private translate: TranslateService)
    {
        this.translate.onDefaultLangChange.pipe(take(1)).subscribe(_ => doWhatYouWant());
    }
}
4reactions
Arikaelcommented, Apr 5, 2018

I needed the same functionality. Why not just check translateService.store.translations if it’s empty or not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preparing Translation Bundles - MadCap Flare's Online Help
Select View > File List. Note You can also create bundles from the TOC View window pane. See TOC View Window Pane.
Read more >
How to load translations from another bundle - Stack Overflow
I always leave the options blank and the translations are available in every single bundle I use. I only have to refer to...
Read more >
Embedding translations in your JS bundles with ngx-translate
Safely importing the translations at compile time​​ In order to include the translations in our bundle, we're first going to load these using ......
Read more >
Add or Load Translations - i18next documentation
The range of backends is large from loading translations in the browser using ... There are more options to adding, removing translations...learn more...
Read more >
Translatable Resource bundles — The Dojo Toolkit
Each translated resource is implemented as a file containing a Javascript Object (see JSON notation) where each property may be a string or...
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