fix: Gettext formatter merges duplicate plural entries#2347
fix: Gettext formatter merges duplicate plural entries#2347andrii-bodnar merged 22 commits intolingui:mainfrom
Conversation
|
@garikkh is attempting to deploy a commit to the Crowdin Team on Vercel. A member of the Team first needs to authorize it. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2347 +/- ##
==========================================
- Coverage 77.05% 76.70% -0.35%
==========================================
Files 84 100 +16
Lines 2157 2739 +582
Branches 555 713 +158
==========================================
+ Hits 1662 2101 +439
- Misses 382 509 +127
- Partials 113 129 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Ah, didn't work properly, need to continue working on it |
|
I think implementation is suboptimal, instead of introducing another type of comment, simply print the same comments many times #. js-lingui:icu=%7BanotherCount%2C+plural%2C+one+%7Bone+book%7D+other+%7Bmany+books%7D%7D&pluralize_on=anotherCount
#. js-lingui:icu=%7Bcount%2C+plural%2C+one+%7Bone+book%7D+other+%7Bmany+books%7D%7D&pluralize_on=count
#: src/App.tsx:61
msgid "one book"
msgid_plural "many books"
msgstr[0] "one book"
msgstr[1] "many books"When deserializing just take to consideration that there could be multiple comments, flat map 1 message + 1 comment and use existing methods to process that. |
|
I considered that approach, but it seemed messier to me when you have many duplicates. In our codebase, we've only been using lingui a few months, but already have cases with ~7 duplicates. So now you'd have a PO entry with 7 ICU comments instead of 1 really long comment. |
Also wanted to note, this isn't introducing another comment - it's just using the const contextComment = item.extractedComments
.find((comment) => comment.startsWith(ctxPrefix))
?.substring(ctxPrefix.length)
const ctx = new URLSearchParams(contextComment)This solution is a little more complex, but IMO is more elegant/consistent |
|
bump @timofei-iatsenko |
|
@garikkh i pushed a commit to your branch with a refactoring and some changes:
I will update PR description and docs, so it could be used as release notes. |
From how I understand PO spec, the |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Thank you for the changes + merge! Unfortunately the last change you mentioned breaks our TMS again Same issue as in #2004 - if a comment gets too long, our TMS breaks it up into multiple lines, and multiple lines don't get parsed correctly in lingui With this change, we have an entry: #. jsi18nicu={hours, plural, one {{hours} hr} other {{hours} hrs}}&pluralize_on=hours
msgid "{hours} hr"
msgid_plural "{hours} hrs"
msgstr[0] "{hours} hr"
msgstr[1] "{hours} hrs"That our TMS changes to: #. jsi18nicu={hours, plural, one {{hours} hr} other {{hours}
#. hrs}}&pluralize_on=hours
msgid "{hours} hr"
msgid_plural "{hours} hrs"
msgstr[0] ""
msgstr[1] ""
msgstr[2] ""And cannot be parsed when doing lingui compile step. Looking for feedback here, either we revert the changes for having ICU readable, or change the compiling/PO parser to combine the comments. FWIW I attempted the latter, and its fairly involved. |
|
@garikkh kchh 💩 what if we will add a way to override serialize/deserialize function for this context comment? So you would be able to override and do whatever you want with it. |
|
@timofei-iatsenko how do you see that working? Are you talking about an option to override these two functions: https://github.com/lingui/js-lingui/pull/2347/files#diff-b1e7f700a5d1ca961f671624ce8d6d9c4bbee951afafa93523db9393d0afdfd9R319-R365 Would you want to take it one step further and handle |
|
@garikkh yes i'm speaking about these two functions.
I also have been thinking about this, but it seems it would be hard to find this comment from all others comment, and if we will change that - this will be a breaking change. But the idea is OK, i will investigate is it possible technically or not. |
Description
Fixes #2346
When using po-gettext formatter, plural calls with identical strings but different variables:
generated duplicate msgid entries in PO files, which violates PO format rules.
Added pre-processing step that merges duplicate plural catalog entries before serialization.
msgid/msgid_pluralentries in generated PO filesWith this change the PO now looks like:
Types of changes
Fixes #2346
Checklist