diff --git a/src/app/directives/translate.directive.ts b/src/app/directives/translate.directive.ts index 10d5f99..8197ac5 100644 --- a/src/app/directives/translate.directive.ts +++ b/src/app/directives/translate.directive.ts @@ -7,12 +7,12 @@ import { TranslateService } from '../services/translate.service'; export class TranslateDirective implements AfterViewInit { @Input() translate: string; - @Input() substitutions: string | string[]; // ToDo + @Input() substitutions: string | string[]; constructor(private translateService: TranslateService, private element: ElementRef) { } ngAfterViewInit() { const key = this.translate.length ? this.translate : this.element.nativeElement.innerHTML.trim(); - this.element.nativeElement.innerHTML = this.translateService.get(key); + this.element.nativeElement.innerHTML = this.translateService.get(key, this.substitutions); } } diff --git a/src/app/pipes/translate.pipe.ts b/src/app/pipes/translate.pipe.ts index f245168..351b23e 100644 --- a/src/app/pipes/translate.pipe.ts +++ b/src/app/pipes/translate.pipe.ts @@ -8,7 +8,7 @@ export class TranslatePipe implements PipeTransform { constructor(private translateService: TranslateService) { } - transform(key: string): string { - return this.translateService.get(key); + transform(key: string, substitutions?: string | string[]): string { + return this.translateService.get(key, substitutions); } } diff --git a/src/app/services/translate.service.ts b/src/app/services/translate.service.ts index 61440e5..34ffbfa 100644 --- a/src/app/services/translate.service.ts +++ b/src/app/services/translate.service.ts @@ -46,7 +46,12 @@ export class TranslateService { } get(key: string, substitutions?: string | string[]): string { - return this.app.isWebExtension ? browser.i18n.getMessage(key, substitutions) : this.translate(key, substitutions); + if (this.app.isWebExtension) { + const translation = browser.i18n.getMessage(key, substitutions); + return translation.length ? translation : key; + } else { + return this.translate(key, substitutions); + } } private translate(key: string, substitutions?: string | string[]): string {