transloco
transloco copied to clipboard
feat(transloco): add intlmessageformat transpiler
Adding an alternative messageformat transpiler based on formatjs/intlmessageformat
white_check_mark Closes: #364
PR Checklist
Please check if your PR fulfills the following requirements:
- [X] The commit message follows our guidelines: https://github.com/ngneat/transloco/blob/master/CONTRIBUTING.md#commit
- [X] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
[ ] Bugfix
[X] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:
What is the current behavior?
Transloco MessageFormatTranspiler may lead to CSP Problems due to usage (in messageformat.js) of the eval function.
Issue Number: #364
What is the new behavior?
Provide an alternative IntlMessaeFormatTranspiler based on formatjs/intl(messageformat)
Does this PR introduce a breaking change?
[ ] Yes
[X] No
Other information
I'd gladly discuss it with you as I'm not an expert in packaging libs! I also inspired myself a lot from your MessageFormatTranspiler. Thanks.
Run & review this pull request in StackBlitz Codeflow.
-
Please note I used version 2.3.4 of formatjs/intl as more recent version needs at least typescript 4.7. As soon as you update typescript, we can take the latest formatjs/int 2.7.1 at the time of writing.
-
Caching is not yet functional. But I'd like to shortly discuss it before fixing/implementing. Does it make still sense? What should we cache? The AST (decomposition) of the message in ICU Format? The final translated/transpiled message?
@f-aubert Thanks for the PR! There is a PR for upgrading the internal to the latest versions, let's continue this after it's merged since we want TS v4.7. Regarding the cache, I'll review it when I have the time and leave comments. (might take a while so be patient 🙂 )
@shaharkazaz the other PR was merged, do we want to go on with this one?
hello @f-aubert @shaharkazaz do we have any update on this? I also cannot ship with unsafe-eval and I use MessageFormat.
@shaharkazaz any update on this one? I'd gladly help some more
@f-aubert Hi! sorry for not being here for a while, a lot going on both personally and nationally. A lot of changes were made to this repo ever since this PR was open, if you'd like to update your branch with all the changes I'll do my best to push this forward 🔥