-
-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(directive): translate by attribute (not binding) with translation key as value #1268
base: master
Are you sure you want to change the base?
Conversation
node.data = content; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interface for listing all custom fileds used by directive
@@ -17,14 +40,12 @@ export class TranslateDirective implements AfterViewChecked, OnDestroy { | |||
@Input() set translate(key: string) { | |||
if (key) { | |||
this.key = key; | |||
this.checkNodes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be called by ngAfterViewChecked
} | ||
} | ||
|
||
@Input() set translateParams(params: any) { | ||
if (!equals(this.currentParams, params)) { | ||
this.currentParams = params; | ||
this.checkNodes(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be called by ngAfterViewChecked
} else if (node.originalContent) { // the content seems ok, but the lang has changed | ||
// the current content is the translation, not the key, use the last real content as key | ||
key = node.originalContent.trim(); | ||
} else if (content !== node.currentValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code block completelly diplucates the first one
|
||
@Injectable() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pipe no need to be injectable
import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {TranslateModule, TranslateService} from '../src/public_api'; | ||
|
||
@Injectable() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compoenent not need to be injectable.
Fix for angular 9 & 10
This PR fixes the behaiviour of
TranslateDirective
when it is used as a simple attributetranslate
(not attribute binding[translate]
) with value and translated element already contains some text. Example:Currently (without this fix) this code will result in text translated twice. If value for
'TEST'
in english is "This is a test", after directive is executed, value of #attributeWithValue will be "This is a testThis is a test".There was no such problem while using ng-translate with Angular 8. But since Angular 9 it appeared.
This PR also contains some refactorings.