chore: update translations compilation script and use AST output #582
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #539
Updates the
build-translations
script in the following ways:rely more on
@formatjs/cli
and@format/cli-lib
to turn extracted messages into app-ready translationsoutput an AST instead of the normal message format. reasons for this are:
it allows react-intl to skip work parsing the data at runtime, improving performance (https://formatjs.io/docs/guides/advanced-usage#pre-compiling-messages)
it allows us to avoid including the relevant parser in the bundled app, which reduces bundle size (https://formatjs.io/docs/guides/advanced-usage#react-intl-without-parser-40-smaller)EDIT: had to punt on this because if you're missing message keys for a language, it will fail to parse the code-defined defaultMessage (which is not in AST form) verbatim and thus not actually interpolate placeholders values, which is not desired. Removed in a subsequent commit but would be nice to take advantage of this eventually.the downside of using the AST is that it's larger in size compared to regular string messages, although it can be efficiently compressed. This means that given the current approach of loading the translations into the app (i.e. all at once, not lazily), this will probably result in slightly more memory being used.
I'm open to removing the change to using the AST, in which case the issue referenced would not be closed and this PR would solely be making our custom script rely more on
@formatjs
tooling.less boilerplate code to make it more linear in terms of reading (at the small cost of functional purity/modularity)