Update Localize Directive (attribute & element) with some specifics in documentation about the format of the string for the key. Localize attribute now supports a key without having to be prefixed with @

This commit is contained in:
Warren Buckley
2017-01-22 22:12:16 +00:00
parent 652a7a3655
commit 23abbdb288

View File

@@ -3,9 +3,15 @@ angular.module("umbraco.directives")
/**
* @ngdoc directive
* @name umbraco.directives.directive:localize
* @restrict EA
* @restrict E
* @function
* @description Localize directive
* @description
* Localize a specific token to put into the HTML as an item
* ##Usage
* <pre>
* <localize key="general_close">Close</localize>
* <localize key="section_key">Fallback value</localize>
* </pre>
**/
.directive('localize', function ($log, localizationService) {
return {
@@ -24,10 +30,27 @@ angular.module("umbraco.directives")
};
})
/**
* @ngdoc directive
* @name umbraco.directives.directive:localize
* @restrict A
* @function
* @description
* Add a HTML attribute to an element containing the HTML attribute name you wish to localise
* Using the format of '@section_key' or 'section_key'
* ##Usage
* <pre>
* <input type="text" localize="placeholder" placeholder="@placeholders_entername" />
* <input type="text" localize="placeholder,title" title="@section_key" placeholder="@placeholders_entername" />
* <div localize="title" title="@section_key"></div>
* </pre>
**/
.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(',');
angular.forEach(keys, function(value, key){
@@ -35,13 +58,15 @@ angular.module("umbraco.directives")
if(attr){
if(attr[0] === '@'){
var t = localizationService.tokenize(attr.substring(1), scope);
localizationService.localize(t.key, t.tokens).then(function(val){
element.attr(value, val);
});
//If the translation key starts with @ then remove it
attr = attr.substring(1);
}
var t = localizationService.tokenize(attr, scope);
localizationService.localize(t.key, t.tokens).then(function(val){
element.attr(value, val);
});
}
});
}