This is the link to the github question about i18n plans:
https://github.com/angular/angular/issues/9104
06-11-2016 @ zh99998 asked:
How to get i18n string in script? eg:
let _THIS_IS_A_I18N_STRING = ??? alert(_THIS_IS_A_I18N_STRING);
and @vicb (angular2 member) said:
@ zh99998 @marcalj This is not possible with the current impl. Could you create the correct function request in the problem tracker by filling out the problem template and adding use cases (and a link to others if applicable).
Thanks.
It seems that there is currently no way to use translations in code.
Although, there is a library for angular2 similar to $translate :
https://github.com/ocombe/ng2-translate
Usage similar to $translate (from docs):
translate.get('HELLO', {value: 'world'}).subscribe((res: string) => { console.log(res); //=> 'hello world' });
Usage similar to translate filter (from docs):
<div>{{ 'HELLO' | translate:param }}</div>
In my case (ng1 / ng2 hybrid app) this was the best solution since I can use the same translation files for both versions of angular.
source share