1(function () { 2 'use strict'; 3 4 angular.module('app').service('translationService', ['$http', '$q', 'appService', function ($http, $q, appService) { 5 6 var service = this; 7 8 // Public property so that directives/controllers can use this data globally 9 service.translations = {}; 10 11 service.getTranslations = function (container) { 12 var containerTranslations; 13 var translations = idstc().getExpirableSessionStorageVar('translations', 60); 14 15 var languageCode = localStorage.getItem('languageCode'); 16 var countryCode = localStorage.getItem('countryCode'); 17 18 if (translations == null) { 19 translations = {}; 20 } 21 else { 22 translations = JSON.parse(translations); 23 containerTranslations = translations[container]; 24 } 25 26 if (containerTranslations == null) { 27 if (service[container + 'promise']) { 28 return service[container + 'promise']; 29 } 30 31 var translationUrl = apiRoot + 'api/translation/getTranslationsByCountryLanguage?container=' + container; 32 33 if (languageCode != null && languageCode != '') { 34 translationUrl += '&languageCode=' + languageCode; 35 } 36 37 if (countryCode != null && countryCode != '') { 38 translationUrl += '&countryCode=' + countryCode; 39 } 40 41 service[container + 'promise'] = $http.get(translationUrl).then( 42 function (resp) { 43 // Get from storage again in case another call caused an update while waiting for this response from server 44 var translations = idstc().getExpirableSessionStorageVar('translations', 60); 45 if (translations == null) { 46 translations = {}; 47 } 48 else { 49 translations = JSON.parse(translations); 50 } 51 52 translations[container] = resp.data; // Set to local variable and use that for session storage (doesn't seem to like stringify'ing the angular scope variable) 53 service.translations[container] = resp.data; 54 55 idstc().setExpirableSessionStorageVar('translations', JSON.stringify(translations)); 56 }, 57 function (error) { 58 idstc().processError({ error: error, showNotifications: true }); 59 }); 60 61 return service[container + 'promise']; 62 } 63 else { 64 service.translations[container] = containerTranslations 65 } 66 } 67 68 service.init = function () { 69 var promises = [appService.makeReady()]; 70 71 $q.all(promises).then(function (result) { 72 service.getTranslations('general'); 73 }); 74 } 75 76 service.init(); 77 }]); 78})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.