In my Ionic2 project, I'm utilizing ng-translate from ng2-translate to translate strings in the code. Currently, I am using the service in the following way:
translate.get('ERROR').subscribe((res: string) => {
//The translated string with code 'ERROR' is stored in res
this.errorString = res;
});
....
//Later on, when an error occurs:
alert(this.errorString);
Handling numerous strings, alerts, and notifications across multiple files by subscribing to each one separately can be quite cumbersome. In HTML, you can simplify this process using the async pipe or a translate pipe, which eliminates the need for explicit subscription to the observable:
<div>{{ 'ERROR' | translate}}</div>
Is there a way to achieve the same level of simplicity for translating strings that reside in TypeScript files? For instance, it would be ideal to have a shorthand function for subscription like this:
alert(idealTranslateFunction('ERROR'));