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.

Wait for translate to be loaded before displaying

See original GitHub issue

Hello people,

I want to wait for the translation to be ready before displaying the page - to avoid the bad UX where the text is flickering when first launching the app.

I was using the filter, like that :

{{'tabs.gallery' | translate}}

And transformed it to use the service instead :

$translate(['tabs.wall', 'tabs.gallery']).then(function (translations) {
    $scope.tabsWall = translations['tabs.wall'];
    $scope.tabsGallery = translations['tabs.gallery'];
});

It didn’t work, and I understood why by looking at the docs :

$translate service works asynchronously, which means it returns the translation for the given translation id, as soon as it could determine it. If it doesn't exist it'll probably just return the translation id.

So I also tried to use the directive, didn’t help. I added $translate.onReady before using the service, didn’t work. I tried to use translate-cloak, didn’t work. Wanted to use the resolve of the ui router’s state… Didn’t find a way to do that efficiently either. I could potentially use in that resolve :

$rootScope.$on('$translateChangeSuccess', function () {
    deferred.resolve(true);
});

BUT then of course it works only on the first load of the page, and it seems very inaccurate to me.

Sooooo any help ?

Thanks !

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
rdesokycommented, May 3, 2016

@JerryBels, make sure that you call $translate() after $translate.use(/lang_id/) returned promise has been resolved.

0reactions
rdesokycommented, May 25, 2016

@JerryBels I am glad that I could help

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript wait for whole function to be executed before going on
Problem is that the page has to be fully built before translating it otherwise some items are not found by Translator when it...
Read more >
Page: DOMContentLoaded, load, beforeunload, unload
Naturally, it has to wait for styles to load. As DOMContentLoaded waits for scripts, it now waits for styles before them as well....
Read more >
Preventing Content Reflow From Lazy-Loaded Images
Lazy loading doesn't guarantee that the image will fully load before it enters the viewport. The result is a perceived janky experience, even...
Read more >
How to run a function when the page is loaded in JavaScript
Method 1: Using onload method: The body of a webpage contains the actual content that is to be displayed. The onload event occurs...
Read more >
What is JavaScript? - Learn web development | MDN
Errors may occur if JavaScript is loaded and run before the HTML ... the page's client-side code is downloaded, then run and displayed...
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