Wait for translate to be loaded before displaying
See original GitHub issueHello 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:
- Created 8 years ago
- Comments:20 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@JerryBels, make sure that you call $translate() after $translate.use(/lang_id/) returned promise has been resolved.
@JerryBels I am glad that I could help