Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 i18n get translation for TS/JS code also

I'm using the default i18n process for my Angular 4 project, so I use ng-i18n to generate the .xlf without problem.

But on my typescript code I also have some texts that need to be translated and retrieved by id for the current language.

I can't find any way to do that in Angular 4. Did I miss something ? I'm using AOT if that matter.

The problem can also occur if the server send back some message/error code from web services, how translate them with Angular

like image 642
jaumard Avatar asked Oct 18 '22 10:10

jaumard


1 Answers

Currently it is not yet possible to translate with i18n from the typescript code.

"Angular only supports using i18n in your templates for now, I'm working on the feature that will allow you to use it in your code, but it's still a work in progress. This lib works both in code and templates" (Olivier Combe, Angular Core Team contractor)

Look at this discussion: https://github.com/ngx-translate/core/issues/495

like image 183
riorudo Avatar answered Oct 20 '22 19:10

riorudo