Skip to content

Commit

Permalink
fix(directive): update directive with manual key when lang changes
Browse files Browse the repository at this point in the history
Fixes #439
  • Loading branch information
ocombe committed Mar 23, 2017
1 parent 5480e46 commit 8753085
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/translate.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class TranslateDirective implements AfterViewChecked, OnDestroy {
let key: string;
if(this.key) {
key = this.key;
if(forceUpdate) {
node.lastKey = null;
}
} else {
let content = node.textContent.trim();
if(content.length) {
Expand Down
3 changes: 3 additions & 0 deletions tests/translate.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,18 @@ describe('TranslateDirective', () => {

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

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

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

translate.use('fr');
expect(fixture.componentInstance.noKey.nativeElement.innerHTML).toEqual("C'est un test");
expect(fixture.componentInstance.withParams.nativeElement.innerHTML).toEqual("C'est un test");
});

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

0 comments on commit 8753085

Please sign in to comment.