Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support GetText template files support during compile #1296

Merged
merged 2 commits into from
Nov 7, 2022

Conversation

timofei-iatsenko
Copy link
Collaborator

@timofei-iatsenko timofei-iatsenko commented Oct 28, 2022

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

  • Change source code and potentially change messages
  • Run extractor and produce *.pot file
  • Send *.pot file together with translations (en.po, pl.po) to the translators.
  • Translators upload .pot and *.po files into theirs translation software which merges them
  • Translators translate
  • Translators return translated files.

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?

  • The template would be generated and translations files would not be touched. That's good.
  • You build your application and realize that all plurals expressions doesn't work because they was not compiled because they are not in the translation files - That sucks.
  • Your understand that in current stage, extracting *.pot files are useless in linguijs.

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.

@vercel
Copy link

vercel bot commented Oct 28, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
js-lingui ✅ Ready (Inspect) Visit Preview Oct 28, 2022 at 3:04PM (UTC)

@timofei-iatsenko timofei-iatsenko changed the title Support GetText template files support during compile improvement: Support GetText template files support during compile Oct 28, 2022
@codecov
Copy link

codecov bot commented Oct 28, 2022

Codecov Report

Base: 81.67% // Head: 82.14% // Increases project coverage by +0.46% 🎉

Coverage data is based on head (2879580) compared to base (da070ba).
Patch coverage: 81.81% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1296      +/-   ##
==========================================
+ Coverage   81.67%   82.14%   +0.46%     
==========================================
  Files          56       56              
  Lines        1779     1781       +2     
  Branches      495      498       +3     
==========================================
+ Hits         1453     1463      +10     
+ Misses        196      188       -8     
  Partials      130      130              
Impacted Files Coverage Δ
packages/cli/src/api/catalog.ts 85.38% <81.81%> (+3.82%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@semoal semoal changed the title improvement: Support GetText template files support during compile feat: Support GetText template files support during compile Nov 7, 2022
@semoal semoal merged commit 5e43810 into lingui:main Nov 7, 2022
@semoal
Copy link
Contributor

semoal commented Nov 7, 2022

Looks good to me! Thanks for the contribution mate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants