1
- angular . module ( "umbraco.directives" )
2
-
1
+ angular . module ( 'umbraco.directives' )
3
2
/**
4
3
* @ngdoc directive
5
4
* @name umbraco.directives.directive:localize
@@ -8,12 +7,12 @@ angular.module("umbraco.directives")
8
7
* @description
9
8
* <div>
10
9
* <strong>Component</strong><br />
11
- * Localize a specific token to put into the HTML as an item
10
+ * Localize a specific token to put into the HTML as an item.
12
11
* </div>
13
12
* <div>
14
13
* <strong>Attribute</strong><br />
15
- * Add a HTML attribute to an element containing the HTML attribute name you wish to localise
16
- * Using the format of '@section_key' or 'section_key'
14
+ * Add an HTML attribute to an element containing the HTML attribute name you wish to localize,
15
+ * using the format of '@section_key' or 'section_key'.
17
16
* </div>
18
17
* ##Usage
19
18
* <pre>
@@ -36,12 +35,11 @@ angular.module("umbraco.directives")
36
35
watchTokens : '@'
37
36
} ,
38
37
replace : true ,
39
-
40
38
link : function ( scope , element , attrs ) {
41
39
var key = scope . key ;
42
- scope . text = "" ;
40
+ scope . text = '' ;
43
41
44
- // A render function to be able to update tokens as values update.
42
+ // A render function to be able to update tokens as values update
45
43
function render ( ) {
46
44
element . html ( localizationService . tokenReplace ( scope . text , scope . tokens || null ) ) ;
47
45
}
@@ -50,26 +48,28 @@ angular.module("umbraco.directives")
50
48
scope . text = value ;
51
49
render ( ) ;
52
50
} ) ;
51
+
53
52
if ( scope . watchTokens === 'true' ) {
54
53
scope . $watch ( "tokens" , render , true ) ;
55
54
}
56
55
}
57
56
} ;
58
57
} )
59
-
60
58
. directive ( 'localize' , function ( $log , localizationService ) {
61
59
return {
62
60
restrict : 'A' ,
63
61
link : function ( scope , element , attrs ) {
64
- //Support one or more attribute properties to update
62
+ // Support one or more attribute properties to update
65
63
var keys = attrs . localize . split ( ',' ) ;
66
64
67
65
Utilities . forEach ( keys , ( value , key ) => {
68
66
var attr = element . attr ( value ) ;
69
-
70
67
if ( attr ) {
68
+ // Localizing is done async, so make sure the key isn't visible
69
+ element . removeAttr ( value ) ;
70
+
71
71
if ( attr [ 0 ] === '@' ) {
72
- //If the translation key starts with @ then remove it
72
+ // If the translation key starts with @ then remove it
73
73
attr = attr . substring ( 1 ) ;
74
74
}
75
75
@@ -82,5 +82,4 @@ angular.module("umbraco.directives")
82
82
} ) ;
83
83
}
84
84
} ;
85
-
86
85
} ) ;
0 commit comments