Skip to content

Commit

Permalink
SHIBUI-814 Added translate directive
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Sep 13, 2018
1 parent ad57c60 commit bebdeaf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
aria-expanded="false"
ngbDropdownToggle>
<i class="fa fa-plus-circle fa-fw" aria-hidden="true"></i>
<ng-container i18n="@@action--add-new">Add New</ng-container>
<ng-container translate="action.add-new">Add</ng-container>
</button>
<div ngbDropdownMenu aria-labelledby="addNewDropdown">
<a class="nav-link"
Expand Down
13 changes: 10 additions & 3 deletions ui/src/app/i18n/directive/translate.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class TranslateDirective implements OnDestroy {
key: string;
lastParams: any;
currentParams: any;
messages: Messages;
messages: Messages = {};
sub: Subscription;

@Input() set translate(key: string) {
Expand All @@ -40,11 +40,18 @@ export class TranslateDirective implements OnDestroy {
private element: ElementRef,
private _ref: ChangeDetectorRef
) {
this.sub = this.store.select(fromI18n.getMessages).subscribe(m => this.messages = m);
this.sub = this.store.select(fromI18n.getMessages).subscribe(m => {
if (m && Object.keys(m).length) {
this.messages = m;
this.update();
}
});
}

update(): void {
this.element.nativeElement.textContent = this.service.translate(this.key, this.currentParams, this.messages);
const translated = this.service.translate(this.key, this.currentParams, this.messages);
this.element.nativeElement.textContent = translated;
// this.element.nativeElement.data = translated;
}

ngOnDestroy() {
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/i18n/service/i18n.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class I18nService {
translate(value: string, interpolated: any, messages: Messages): string {
interpolated = interpolated || {};
let val = messages.hasOwnProperty(value) ? messages[value] : value;
console.log(val, messages);
return this.interpolate(val, interpolated);
}

Expand Down

0 comments on commit bebdeaf

Please sign in to comment.