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.

Improve .get() to update whenever language is being changed with .use()

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
[ ] support request => check the FAQ and search github for a similar issue before submitting
[x] feature request

Current behavior Whenever I change language, parts in my code where I use .get doesn’t change. I am aware of onLangChange, but that wouldn’t make sense for me to use it.

Expected/desired behavior It should call again on subscribtion with new languages translations. I assume that observable has completed and that is why it is not calling anymore(haven’t looked at source).

Reproduction of the problem Example code of what I have now (using with ng2-breadcrumbs):

    this.translate.get(['pages.user.title', 'menus.user.profile']).subscribe((res) => {
      this.breadcrumb.addFriendlyNameForRoute('/users', res['pages.user.title']);
      this.breadcrumb.addFriendlyNameForRoute('/users/edit', res['menus.user.profile']);
    });

If I would use .onLangChange code would look something like this:

    this.translate.get(['pages.user.title', 'menus.user.profile']).subscribe((res) => {
      this.breadcrumb.addFriendlyNameForRoute('/users', res['pages.user.title']);
      this.breadcrumb.addFriendlyNameForRoute('/users/edit', res['menus.user.profile']);
    });

    this.translate.onLangChange.subscribe(() => {
      this.translate.get(['pages.user.title', 'menus.user.profile']).subscribe((res) => {
        this.breadcrumb.addFriendlyNameForRoute('/users', res['pages.user.title']);
        this.breadcrumb.addFriendlyNameForRoute('/users/edit', res['menus.user.profile']);
      });
    });

Please tell us about your environment:

  • ng2-translate version: 4.0.1

  • Angular version: 2.2.1

  • Browser: [all]

  • Language: [all]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
zsparalcommented, Apr 29, 2017

This would drastically simplify a lot of our components and I’ll even send a PR for it to - hopefully - get it into a release. Since changing the current get would silently lead to memory leaks I think adding a new function would be less destructive.

Any ideas for the function name? I’ll send the PR in the meantime but will change the name to whatever’s suggested here.

2reactions
ocombecommented, Dec 21, 2016

Not yet, but should be in the next major

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Manage Programming Language Upgrades and EOL
Learn how to reduce the costs of upgrading open source languages, as well as best practices when a programming language becomes EOL.
Read more >
How to refresh activity after changing language (Locale ...
Register an OnSharedPreferenceChangeListener , in its onShredPreferenceChanged() , invoke restartActivity() if language preference was changed.
Read more >
Do programming languages 'update' (change) themselves ...
Yes, they change over time. There is no official process where this happens, except some languages have been adopted by standards committees, ...
Read more >
How to change your Automatic Updates settings by using ...
How to change your Automatic Updates settings by using Windows Security Center. Microsoft Windows XP Service Pack 2 Microsoft Windows XP Home Edition...
Read more >
Update the IDE and SDK Tools - Android Developers
Update your IDE and change channels · Open the Preferences window by clicking File > Settings (on Mac, Android Studio > Preferences). ·...
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