diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/localization/localize.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/localization/localize.directive.js index e957d78660bd..6284ca2798a9 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/localization/localize.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/localization/localize.directive.js @@ -1,86 +1,100 @@ angular.module("umbraco.directives") - /** - * @ngdoc directive - * @name umbraco.directives.directive:localize - * @restrict EA - * @function - * @description - *
- * - *- **/ - .directive('localize', function ($log, localizationService) { - return { - restrict: 'E', - scope: { - key: '@', - tokens: '=', - watchTokens: '@' - }, - replace: true, +/** +* @ngdoc directive +* @name umbraco.directives.directive:localize +* @restrict EA +* @function +* @description +*Close - *Fallback value - * - * - * - * - * - *
+* +*+* ##Use with tokens +* Also supports tokens inside the translation key, example of a translation +*Close +*Fallback value +* +* +* +* +* +*
+*+* Can be used like this: +*You have %0% characters left of %1% +*
+*+* Where the "tokens"-attribute is an array of tokens for the translations, "watch-tokens" will make the component watch the expression passed. +**/ +.directive('localize', function ($log, localizationService) { + return { + restrict: 'E', + scope: { + key: '@', + tokens: '=', + watchTokens: '@' + }, + replace: true, - link: function (scope, element, attrs) { - var key = scope.key; - scope.text = ""; + link: function (scope, element, attrs) { + var key = scope.key; + scope.text = ""; - // A render function to be able to update tokens as values update. - function render() { - element.html(localizationService.tokenReplace(scope.text, scope.tokens || null)); - } + // A render function to be able to update tokens as values update. + function render() { + element.html(localizationService.tokenReplace(scope.text, scope.tokens || null)); + } - localizationService.localize(key).then(function (value) { - scope.text = value; - render(); - }); - if (scope.watchTokens === 'true') { - scope.$watch("tokens", render, true); - } + localizationService.localize(key).then(function (value) { + scope.text = value; + render(); + }); + if (scope.watchTokens === 'true') { + scope.$watch("tokens", render, true); } - }; - }) + } + }; +}) - .directive('localize', function ($log, localizationService) { - return { - restrict: 'A', - link: function (scope, element, attrs) { - //Support one or more attribute properties to update - var keys = attrs.localize.split(','); +.directive('localize', function ($log, localizationService) { + return { + restrict: 'A', + link: function (scope, element, attrs) { + //Support one or more attribute properties to update + var keys = attrs.localize.split(','); - Utilities.forEach(keys, (value, key) => { - var attr = element.attr(value); + Utilities.forEach(keys, (value, key) => { + var attr = element.attr(value); - if (attr) { - if (attr[0] === '@') { - //If the translation key starts with @ then remove it - attr = attr.substring(1); - } + if (attr) { + if (attr[0] === '@') { + //If the translation key starts with @ then remove it + attr = attr.substring(1); + } - var t = localizationService.tokenize(attr, scope); + var t = localizationService.tokenize(attr, scope); - localizationService.localize(t.key, t.tokens).then(function (val) { - element.attr(value, val); - }); - } - }); - } - }; + localizationService.localize(t.key, t.tokens).then(function (val) { + element.attr(value, val); + }); + } + }); + } + }; - }); +});You have %0% characters left of %1% +* +*