Angular - Use static json for translations before the user authorized and after - use data from server

67 Views Asked by At

Is it possible to use static json for translations before the user authorized and after - use data from server?

2

There are 2 best solutions below

0
On BEST ANSWER

If you use angular-translate you can use $translateProvider (or $translatePartialLoader) to perform some asynchronous loading.

Works great for me and looks to solve what you are trying to do.

angular.module('contact')
.controller('ContactCtrl', function ($scope, $translatePartialLoader, $translate) {
  $translatePartialLoader.addPart('contact');
  $translate.refresh();
});
0
On

used following:

 if('user is not logged in') {
 //get local file
   return this.getLocalTranslation(refresh, lang);
 }
 var deferred = $q.defer(); 
   else {
   $http({
     url: "" ;
     method: "GET"
   }).then(function(result) {
     if(result.data.success === 'true') { 
       console.log(result.data);
     } else {
       console.error(result.data.message);
       deferred.reject(result.data);
     }
   });
 }

if user is not logged in - then use local file, else call the source form server