jsverse / transloco

🚀 😍 The internationalization (i18n) library for Angular
https://jsverse.github.io/transloco/
MIT License
2.01k stars 195 forks source link

MessageFormat plug-in and pre-compiled messages #102

Closed glen-84 closed 5 years ago

glen-84 commented 5 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[X] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Please clarify whether or not the MessageFormat plug-in supports build-time compilation of messages / reading from pre-compiled messages (functions).

The messageformat documentation recommends using messageformat as a compile-time tool, to avoid having to download the compiler to the client and compile messages at run-time. It also solves a potential CSP issue.

Is there any way to use pre-compiled messages with this library?

itayod commented 5 years ago

Hi @glen-84,

The plugin we provide does not support build-time since most of the time the transpilation of the message includes variables that we need to resolve, that could happen only during runtime.

example:

{
  "message": "Can replace {{value}} and also give parse messageformat: The {gender, select, male {boy won his} female {girl won her} other {person won their}} race - english",
}
      <span>{{ t.message | translocoParams: { value: dynamic, gender: user.gender } }}</span>

Therefore it doesn't make sense for our case to support precompilation for message format.

glen-84 commented 5 years ago

@itayod,

I'm referring to pre-compilation from ICU message to JS function, not to the resulting string.

Example:

greeting: Hello {name} -> function greeting(name) { return ``Hello ${name}``; }

(the above is just an example, it doesn't look exactly like that)

fxck commented 5 years ago

https://github.com/ngneat/transloco/issues/47#issuecomment-525872345

itayod commented 5 years ago

Hi @glen-84.

I see what you meant here, but unfortunately, we are currently not going to support that soon.