问题
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