11/*@ngInject */
22function dtrwTranslateChildDirective ( $compile , $translate ) {
33
4- function rebuildElement ( element , translateKey , translateInto , translateValues ) {
5- if ( translateInto ) {
6- element . attr ( translateInto , $translate . instant ( translateKey , translateValues ) ) ;
7- element . removeAttr ( 'translate-child-into' ) ; //remove the attribute to avoid indefinite loop
8- } else {
9- element . attr ( 'translate' , translateKey ) ;
10- }
11-
12- element . removeAttr ( 'translate-child' ) ; //remove the attribute to avoid indefinite loop
13- }
14-
154 return {
165 restrict : 'A' ,
176 replace : false ,
@@ -20,16 +9,24 @@ function dtrwTranslateChildDirective($compile, $translate) {
209 require : '^translateBase' ,
2110 // Make sure this directive is run first
2211 priority : 1000 ,
23- link : function link ( scope , element , attrs , translateBaseCtrl ) {
12+ link : function link ( scope , element , attrs , translateBaseCtrl ) { // jshint ignore:line
13+ let { translateChildInto, translateChildKeyInto, translateValues} = attrs ;
2414 let translateKey = translateBaseCtrl . getTranslationKey ( attrs . translateChild ) ;
25- let translateInto = attrs . translateChildInto ;
26- let translateValues ;
2715
28- if ( translateInto && attrs . translateValues ) {
29- translateValues = scope . $eval ( attrs . translateValues ) ;
16+ if ( translateChildInto && translateChildKeyInto ) {
17+ throw new Error ( 'translate-child-into and translate-child-key-into are mutually exclusive' ) ;
18+ }
19+
20+ if ( translateChildInto ) {
21+ translateValues = ( translateValues ) ? scope . $eval ( translateValues ) : { } ;
22+ element . attr ( translateChildInto , $translate . instant ( translateKey , translateValues ) ) ;
23+ } else if ( translateChildKeyInto ) {
24+ element . attr ( translateChildKeyInto , translateKey ) ;
25+ } else {
26+ element . attr ( 'translate' , translateKey ) ;
3027 }
3128
32- rebuildElement ( element , translateKey , translateInto , translateValues ) ;
29+ element . removeAttr ( 'translate-child' ) ; //remove the attribute to avoid indefinite loop
3330
3431 $compile ( element ) ( scope ) ;
3532 }
0 commit comments