1 2angular.module('app') 3 .directive('translateContent', function ($sce, translationService) { 4 return { 5 restrict: 'E,A', 6 scope: { 7 container: '@container', // The key container (used to allow the same key to be translated differently for different containers) 8 key: '@key', // The key of the translatable content 9 defaultContent: '@defaultContent' // The default content in case the key does not return any content and to help make the implementation human-readable/searchable 10 }, 11 template: '<span ng-bind-html="showContent()"></span>', 12 link: function (scope, element, attrs) { 13 scope.translations = translationService.translations; 14 15 if (scope.container) { 16 translationService.getTranslations(scope.container); 17 } 18 19 scope.$watch('container', function (newValue, oldValue) { 20 if (newValue && newValue !== oldValue) { 21 translationService.getTranslations(newValue); 22 } 23 }); 24 25 scope.showContent = function () { 26 if (scope.translations == undefined) { 27 return scope.defaultContent; 28 } 29 else if (scope.translations[scope.container] == undefined) { 30 return scope.defaultContent; 31 } 32 33 if (scope.translations[scope.container][scope.key] !== undefined) { 34 return $sce.trustAsHtml(scope.translations[scope.container][scope.key]); 35 } 36 else if (scope.key != null && scope.translations[scope.container][scope.key.toLowerCase()] !== undefined) { 37 return $sce.trustAsHtml(scope.translations[scope.container][scope.key.toLowerCase()]); 38 } 39 else { 40 return scope.defaultContent; 41 } 42 } 43 } 44 }; 45 });
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.