Can I use Angular i18n to translate string literals in typescript code

廉价感情. 提交于 2019-12-20 02:40:17

问题


I'm localizing my Angular app using Angular's i18n tools, which extract text from HTML templates into an xlf file, and then build a localized version of the whole app using AOT (ahead of time compilation).

My question is: Can is use this framework to extract string literals in typescript code, so they are listed in the same xlf file and replaced in the localized AOT build?

Ideally, I'd like to write something like this in my typescript code:

foo() {
   this.bar = i18n('baz');

and the string 'baz' would be listed in the xlf file I send to my translator.

Alternatively, if this isn't possible, is there a library that does something similar? I.e. extract strings from typescript code into an xlf file, then replaces them either at runtime or during build?


回答1:


There is no official support yet, but Olivier Combe, who is both the writer of ngx-translate (that you could use), and a member of the Angular team responsible for i18n, has written a speculative polyfill, that you could use.



来源:https://stackoverflow.com/questions/49124757/can-i-use-angular-i18n-to-translate-string-literals-in-typescript-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!