Skip to content

Commit

Permalink
Fix translation issue on webextension
Browse files Browse the repository at this point in the history
when key is not existing under _locales + update translate directive & pipe
  • Loading branch information
AXeL-dev committed Mar 29, 2020
1 parent 4aa544a commit 36acd5d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/directives/translate.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/app/pipes/translate.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 6 additions & 1 deletion src/app/services/translate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 36acd5d

Please sign in to comment.