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.

Using $translateProvider.useLoader, the addPart/refresh combination does not work properly for the frist element's translation.

See original GitHub issue

Hi Pascal,

Here is the config

.config(['$translateProvider', '$translatePartialLoaderProvider', function ($translateProvider, $translatePartialLoaderProvider) {

    $translateProvider.useLoader('$translatePartialLoader', {
        urlTemplate: 'i18n/{lang}/{part}.json'
    });
    $translateProvider.preferredLanguage('en-EN');
    $translatePartialLoaderProvider.addPart('main');
}])

Tranlsation files are :- i18n/en-EN/main.json i18n/en-EN/pa.json i18n/fr-FR/main.json i18n/fr-FR/pa.json

The files have few common elements for example page heading is common in all files which refers to the heading of that particular page.

MainCtrl for mainview.html

angular.module('appApp')//organization-definition
    .controller('MainCtrl', ['$scope', '$translate', '$translatePartialLoader',
        function ($scope,   $translate, $translatePartialLoader) {            
            $translatePartialLoader.addPart('main');
            $translate.refresh();
        }
    ]);

PaAddCtrl for paview.html

angular.module('appApp')
    .controller('PaAddCtrl', ['$scope', '$translate', '$translatePartialLoader',
        function ($scope, $translate, $translatePartialLoader) {
            $translatePartialLoader.addPart('positions');
            $translate.refresh();
        }])

When the app starts, MainCtrl is the one so the language part sets up to main and it works fine. When I move to PaAddCtrl from MainCtrl, then the translation of first element does not come from the positions.json file but instead comes from the main.json file. And same thing happens when I move from PaAddCtrl’s paview.html to MainCtrl’s main.html.

What am I doing wrong? Can you please point it out and help me fix this?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:35 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
DWandcommented, Apr 12, 2015

@knalli, it seams that this issue is not resolved yet. I was unable to operate with the provided plunker. Also I did not look at the example on GitHub as it is huge and has a lot of directories.

But, there are at least two possible things which can lead to an unexpected behavior here.

  1. Race condition between added parts in the loader. It can happen if different parts have some identical translation keys. Actually it is not the race condition here, but very similar and leads to unpredictable result. To solve this thing the developer has either to avoid a usage of identical translation ids or delete old parts before the refresh() method is called. Also, at the moment we have additional tools to help to fight this situation: the getRegisteredParts method and priority of the parts.
  2. As for the question from stackoverflow, @gtbuchanan is right. There is a problem with synchronization between use() and refresh() methods.
0reactions
knallicommented, Mar 20, 2016

Closed due inactivity. Enhancements for the partial loader already addressed in the linked issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using $translateProvider.useLoader, the addPart/refresh ...
Using $translateProvider.useLoader, the addPart/refresh combination does not work properly for the frist element's translation.
Read more >
Using $translate in service does not work - Stack Overflow
I want to use angular translate in service. I tried to load it using translatePartialLoader and then refresh but no success I am...
Read more >
Applying markup to translations in Angular applications (the ...
Supporting translated text with markup in Angular applications is challenging. A proper solution is presented in this article.
Read more >
Adding translation using angular-translate to an angularjs app
This post adds internationalisation (i18n) to the app using the angular-translate library. This library allows "on-the-fly" translation of ...
Read more >
[SOLVED] Why angular-translate not working? - Ionic Forum
Hi, I installed angular-translate and angular-local-storage in my project which save in the path [project]/www/lib/.
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