angular-translate display key

939 Views Asked by At

In my app I use the angular translate .

On my index.html I put the directive translate-cloak class="translate-cloak" with .translate-cloak {visibility: hidden;} on <body> but for the <div ui-view></div> content the key is display before my tranlsted text.

In my controller I try to do

function SearchCtrl ($translatePartialLoader, $translate) {
        $translatePartialLoader.addPart('../components/search');
        $translate.refresh();

        $translate.onReady().then(function(){
          alert($translate.instant('SEARCH_MONTH')); #display SEARCH_MONTH and not the content
          ...

How can I wait the loading of the module before to render my view ?

Thanks

2

There are 2 best solutions below

0
On BEST ANSWER

To wait until your file gets downloaded you have to do following:

$translatePartialLoader.addPart('../components/search');
$translate.refresh().then( /* Do your work here */ );
0
On

Thank you, sandyJoshi! After spending a lot of time trying to figure out how to solve the issue, your solution came out. It was implemented this way:

$translatePartialLoader.addPart('file-upload-js');
$translate.refresh().then(
    // detecting a hash/anchor change using jQuery: http://www.rcneil.com/force-reload-on-a-hash-or-anchor-change-with-jquery/
    $(window).on('hashchange',function(){ 
    window.location.reload(true);
    })
);