@@ -64,7 +64,7 @@ export class TranslateDirective implements AfterViewChecked, OnDestroy {
64
64
// if the element is empty
65
65
if ( ! nodes . length ) {
66
66
// we add the key as content
67
- this . element . nativeElement . textContent = this . key ;
67
+ this . setContent ( this . element . nativeElement , this . key ) ;
68
68
nodes = this . element . nativeElement . childNodes ;
69
69
}
70
70
for ( let i = 0 ; i < nodes . length ; ++ i ) {
@@ -77,13 +77,13 @@ export class TranslateDirective implements AfterViewChecked, OnDestroy {
77
77
node . lastKey = null ;
78
78
}
79
79
} else {
80
- let content = node . textContent . trim ( ) ;
80
+ let content = this . getContent ( node ) . trim ( ) ;
81
81
if ( content . length ) {
82
82
// we want to use the content as a key, not the translation value
83
83
if ( content !== node . currentValue ) {
84
84
key = content ;
85
85
// the content was changed from the user, we'll use it as a reference if needed
86
- node . originalContent = node . textContent ;
86
+ node . originalContent = this . getContent ( node ) ;
87
87
} else if ( node . originalContent && forceUpdate ) { // the content seems ok, but the lang has changed
88
88
node . lastKey = null ;
89
89
// the current content is the translation, not the key, use the last real content as key
@@ -109,11 +109,11 @@ export class TranslateDirective implements AfterViewChecked, OnDestroy {
109
109
node . lastKey = key ;
110
110
}
111
111
if ( ! node . originalContent ) {
112
- node . originalContent = node . textContent ;
112
+ node . originalContent = this . getContent ( node ) ;
113
113
}
114
114
node . currentValue = isDefined ( res ) ? res : ( node . originalContent || key ) ;
115
115
// we replace in the original content to preserve spaces that we might have trimmed
116
- node . textContent = this . key ? node . currentValue : node . originalContent . replace ( key , node . currentValue ) ;
116
+ this . setContent ( node , this . key ? node . currentValue : node . originalContent . replace ( key , node . currentValue ) ) ;
117
117
this . _ref . markForCheck ( ) ;
118
118
} ;
119
119
@@ -130,6 +130,18 @@ export class TranslateDirective implements AfterViewChecked, OnDestroy {
130
130
}
131
131
}
132
132
133
+ getContent ( node : any ) : string {
134
+ return isDefined ( node . textContent ) ? node . textContent : node . data ;
135
+ }
136
+
137
+ setContent ( node : any , content : string ) : void {
138
+ if ( isDefined ( node . textContent ) ) {
139
+ node . textContent = content ;
140
+ } else {
141
+ node . data = content ;
142
+ }
143
+ }
144
+
133
145
ngOnDestroy ( ) {
134
146
if ( this . onLangChangeSub ) {
135
147
this . onLangChangeSub . unsubscribe ( ) ;
0 commit comments