Is there a way to create an util with a static TranslationService call?

Viewed 55

I'm thinking about something like this

@Injectable({
    providedIn: 'root'
})
export class TranslationUtil {
    constructor(private translateService: TranslateService) {
    }

    public static translate(translationKey: string): string {
        //how to make this work in a static method
        return this.translateService.instant(translationKey);
    }
}

The reason I want to do achieve so I won't have to call it in every constructor.
But tell me if it's something I shouldn't do or there is a better practice for it.

0 Answers
Related