Skip to content

Commit 8753085

Browse files
committed
fix(directive): update directive with manual key when lang changes
Fixes #439
1 parent 5480e46 commit 8753085

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/translate.directive.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export class TranslateDirective implements AfterViewChecked, OnDestroy {
6767
let key: string;
6868
if(this.key) {
6969
key = this.key;
70+
if(forceUpdate) {
71+
node.lastKey = null;
72+
}
7073
} else {
7174
let content = node.textContent.trim();
7275
if(content.length) {

tests/translate.directive.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,18 @@ describe('TranslateDirective', () => {
119119

120120
it('should update the DOM when the lang changes', () => {
121121
expect(fixture.componentInstance.noKey.nativeElement.innerHTML).toEqual('TEST');
122+
expect(fixture.componentInstance.withParams.nativeElement.innerHTML).toEqual('TEST');
122123

123124
translate.setTranslation('en', {"TEST": "This is a test"});
124125
translate.setTranslation('fr', {"TEST": "C'est un test"});
125126

126127
translate.use('en');
127128
expect(fixture.componentInstance.noKey.nativeElement.innerHTML).toEqual('This is a test');
129+
expect(fixture.componentInstance.withParams.nativeElement.innerHTML).toEqual('This is a test');
128130

129131
translate.use('fr');
130132
expect(fixture.componentInstance.noKey.nativeElement.innerHTML).toEqual("C'est un test");
133+
expect(fixture.componentInstance.withParams.nativeElement.innerHTML).toEqual("C'est un test");
131134
});
132135

133136
// Test (temporarily) disabled as the directive tests manipulate the DOM manually which breaks this test.

0 commit comments

Comments
 (0)