feat: Support GetText template files support during compile #1296
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.
This PR brings full e2e support for gettext *.pot files into linguijs.
What is a template or *.pot file?
Template is a file where all messages extracted from sourcecode is stored. It doesn't have any translations. It treated as build artifact and could be added to gitignore.
What's wrong with current support of *.pot files?
Short version:
They are not taken into account during compiling messages.
Long version:
Standard gettext flow looks like the following
There are few things which important to notice.
Merging new messages to the translations should happen outside of build process. It's the responsibility of translation software (such as PoEditor or modern cloud services like crowdin) to do so, not the linguijs extractor.
In current linguijs flow, extractor tries to merge new messages (and delete old) into translation files.
What's wrong with this? Translations files are usually under version control. Running a build with NODE_ENV=production without fresh extracted messages will cause that messages where ICU is used would be corrupted and this force developers to always extract messages before build in CI process (for test/staging builds, for production builds we assume that 100% messages are translated).
Every time we run a development build on CI, our translation files marked as changed.
This might not be a big deal for regular repositories, but could be a dealbreaker for monorepos where some strategies for incremental builds are used. Usually tools such as turborepo / rush / ultra-runner trying to be smart and detect which project inside monorepo was changed and rebuild only this one. With linguijs this doesn't work because every build touches translations and therefore bursting the cache.
But lingui has a command to
extract-template
, you can use this, you may say. Actually not.What happend if we generate template file using
lingui extract-template
?How this PR changes it?
Instead of merging new messages into catalogs during extraction phase, it merges template with requested catalog during compile time. If you have actual template - your translations catalogs are also actual.