1(function() { 2 'use strict'; 3 4 const CONTAINER_LOADED_EVENT = 'beautysocietyTranslationContainerLoaded'; 5 6 /** 7 * Drop-in for translate-content when labels must update after async load 8 * (e.g. inside ng-if). Refreshes when translationService finishes loading 9 * a container (beautysocietyTranslationContainerLoaded event). 10 */ 11 angular.module('app').directive('beautysocietyTranslateContent', function($sce, translationService, $rootScope) { 12 return { 13 restrict: 'E', 14 scope: { 15 container: '@', 16 fallbackContainer: '@?', 17 key: '@', 18 defaultContent: '@defaultContent' 19 }, 20 template: '<span ng-bind-html="displayHtml"></span>', 21 link: function(scope) { 22 function lookup(container) { 23 if (!container) { 24 return null; 25 } 26 27 const containerMap = translationService.translations[container]; 28 29 if (!containerMap) { 30 return null; 31 } 32 33 if (containerMap[scope.key] != null && containerMap[scope.key] !== '') { 34 return containerMap[scope.key]; 35 } 36 37 if (scope.key && containerMap[scope.key.toLowerCase()] != null && containerMap[scope.key.toLowerCase()] !== '') { 38 return containerMap[scope.key.toLowerCase()]; 39 } 40 41 return null; 42 } 43 44 function resolveText() { 45 return lookup(scope.container) 46 || lookup(scope.fallbackContainer) 47 || scope.defaultContent 48 || ''; 49 } 50 51 function refresh() { 52 scope.displayHtml = $sce.trustAsHtml(resolveText()); 53 } 54 55 function ensureContainerRequested(container) { 56 if (!container) { 57 return; 58 } 59 60 if (translationService.translations[container]) { 61 return; 62 } 63 64 const result = translationService.getTranslations(container); 65 66 if (result && typeof result.then === 'function') { 67 result.then(function () { 68 $rootScope.$broadcast(CONTAINER_LOADED_EVENT, container); 69 }); 70 } else if (translationService.translations[container]) { 71 $rootScope.$broadcast(CONTAINER_LOADED_EVENT, container); 72 } 73 } 74 75 scope.displayHtml = $sce.trustAsHtml(scope.defaultContent || ''); 76 77 ensureContainerRequested(scope.container); 78 ensureContainerRequested(scope.fallbackContainer); 79 refresh(); 80 81 const off = $rootScope.$on(CONTAINER_LOADED_EVENT, function(event, container) { 82 if (container === scope.container || container === scope.fallbackContainer) { 83 refresh(); 84 } 85 }); 86 87 scope.$on('$destroy', off); 88 } 89 }; 90 }); 91})();
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.