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.

Partial Loader Not Interpolating Values On First Page Load

See original GitHub issue

Subject of the issue

I’m making use of the translate directive, partial loader, loader cache, and the gulp-ng-lang2js tool. When I navigate to a page for the first time, the IDs are not interpolated. If leave the page and come back, they will be interpolated. Translation IDs will also be interpolated if I go directly to the page by URL.

This is what my configuration looks like:

$translateProvider
        .useLoader('$translatePartialLoader', {
          urlTemplate: 'i18n/{part}/lang/{lang}.json'
        })
        .useSanitizeValueStrategy('sanitize')
        .fallbackLanguage('en')
        .preferredLanguage('en')
        .useLoaderCache('$translationCache')
        .forceAsyncReload(true);

angular.module("myApp")
  .run(["$rootScope", "$translate",
    function($rootScope, $translate) {
      $rootScope.$on('$translatePartialLoaderStructureChanged',
        function() {
          $translate.refresh();
        });
    }
  ]);

I have pulled $translationCache into my controller and found it does indeed contain the cached table on first load. I am calling $translatePartialLoader.addPart() in the controller. I watch the network tab in Chrome Devtools and verified that no call is made to the server to get the translation table.

Essentially what I am finding is that $translatePartialLoader.addPart() MUST be called before loading the controller and not within the controller, even though I have already cached the translation table.

What is going on?

Your environment

  • version of angular-translate ^2.12.1
  • version of angular 1.5.8
  • which browser and its version Chrome 54.0.2840.90

Steps to reproduce

Working on a Plunker

Expected behaviour

The ID’s should be interpolated on first load.

Actual behaviour

The IDs are not interpolated on first load, but are interpolated when returning to the page.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
mtwarcommented, Jan 24, 2017

The fix I made for this also causes a regression where the translate cloak directive will not decloak on the first load of a particular part. This is due to a problem in the way the promises from loadAsync are handled in refresh. The $q.all promise resolves after all of the handlers on the individual promise queues, which will always cause determineTranslation to have a cache miss on the first call to $translate after a part is added, this first call being the one from the translate-cloak directive. The fix is to just add the translations call (to update the global table) to each promise queue individually before the q.all promise is established. I’ll include this as well with the other fix I mentioned previously. I think I now have two for translate-cloak, two for refresh, and one for the partial loader that together make them behave sanely together. I’ll be sure to post them soon; bug me if I don’t!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Partial Loader Not Interpolating Values On First Page Load -
I'm making use of the translate directive, partial loader, loader cache, and the gulp-ng-lang2js tool. When I navigate to a page for the...
Read more >
How can I provide parameters for webpack html-loader ...
I found another solution, using html-loader with interpolate option. ... And then in html page you can import partials html and javascript ...
Read more >
raster - Using Python for interpolate data points with Scipy ...
My end goal is to interpolate these points to get raster with the given dimensions (3586, 2284) with the correct coordinates. I'm also...
Read more >
Unity Tips | Part 3 - Interpolation - Daniel Ilett
The first two parameters to a lerp function are two values being interpolated between ... By default, Unity physics does not interpolate.
Read more >
How to use EJS to template your Node.js application
ejs partial has the title of the web page hard coded as such, which is not desirable. We want the title of the...
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