fix: preserve ICU exact-match plural selectors (=0, =1) in export#3548
fix: preserve ICU exact-match plural selectors (=0, =1) in export#3548peterzen wants to merge 1 commit intotolgee:mainfrom
Conversation
Two related issues caused push→pull round-trips to produce file diffs: 1. IcuToGenericFormatMessageConvertor.convert() called toIcuPluralString() without optimize=false, relying on the default optimize=true. This triggered optimizePluralForms + orderPluralForms on every export, silently reordering or removing plural forms that the user authored. 2. orderPluralForms sorted unknown keys (including =0, =1, =2 exact-match selectors) alphabetically after 'other', placing them last instead of first. ICU exact-match selectors should precede keyword selectors and appear in ascending numeric order. Fix: pass optimize=false in the export path so the stored ICU string is emitted verbatim. Also update orderPluralForms to sort =N selectors before keyword forms in numeric order so that explicit optimize calls produce canonical output consistent with the ICU specification. Fixes: tolgee#3267 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThese changes fix plural form handling by preventing automatic optimization of plural forms with exact-match selectors (e.g., Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can customize the high-level summary generated by CodeRabbit.Configure the |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
backend/data/src/test/kotlin/io/tolgee/unit/formats/PluralsFormUtilTest.kt (1)
56-61: Consider using a single combined assertion for clearer test failure messages.The separate
assertcalls could be consolidated to improve readability and provide a more informative failure message.♻️ Optional: Combine ordering assertions
- assert(output.indexOf("=0") < output.indexOf("one")) { - "=0 should come before 'one' in: $output" - } - assert(output.indexOf("=0") < output.indexOf("other")) { - "=0 should come before 'other' in: $output" - } + val idx0 = output.indexOf("=0") + val idxOne = output.indexOf("one") + val idxOther = output.indexOf("other") + assert(idx0 < idxOne && idx0 < idxOther) { + "=0 (at $idx0) should come before 'one' (at $idxOne) and 'other' (at $idxOther) in: $output" + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/data/src/test/kotlin/io/tolgee/unit/formats/PluralsFormUtilTest.kt` around lines 56 - 61, Replace the two separate assert calls that check ordering of "=0" vs "one" and "other" with a single combined assertion in PluralsFormUtilTest that verifies both conditions at once (e.g. check output.indexOf("=0") < output.indexOf("one") && output.indexOf("=0") < output.indexOf("other")) and provide a clear failure message that includes the output and the three indices so test failures show the full ordering info; update the assertion surrounding the variable output accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/data/src/test/kotlin/io/tolgee/unit/formats/PluralsFormUtilTest.kt`:
- Around line 56-61: Replace the two separate assert calls that check ordering
of "=0" vs "one" and "other" with a single combined assertion in
PluralsFormUtilTest that verifies both conditions at once (e.g. check
output.indexOf("=0") < output.indexOf("one") && output.indexOf("=0") <
output.indexOf("other")) and provide a clear failure message that includes the
output and the three indices so test failures show the full ordering info;
update the assertion surrounding the variable output accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 72b94f01-7844-4b10-8f40-3d2eaf2917b0
📒 Files selected for processing (3)
backend/data/src/main/kotlin/io/tolgee/formats/generic/IcuToGenericFormatMessageConvertor.ktbackend/data/src/main/kotlin/io/tolgee/formats/pluralFormsUtil.ktbackend/data/src/test/kotlin/io/tolgee/unit/formats/PluralsFormUtilTest.kt
|
Hey! Thanks a lot for the PR. @Anty0 can you please review this? |
Two related issues caused push→pull round-trips to produce file diffs:
IcuToGenericFormatMessageConvertor.convert() called toIcuPluralString() without optimize=false, relying on the default optimize=true. This triggered optimizePluralForms + orderPluralForms on every export, silently reordering or removing plural forms that the user authored.
orderPluralForms sorted unknown keys (including =0, =1, =2 exact-match selectors) alphabetically after 'other', placing them last instead of first. ICU exact-match selectors should precede keyword selectors and appear in ascending numeric order.
Fix: pass optimize=false in the export path so the stored ICU string is emitted verbatim. Also update orderPluralForms to sort =N selectors before keyword forms in numeric order so that explicit optimize calls produce canonical output consistent with the ICU specification.
Fixes: #3267
Summary by CodeRabbit
Release Notes
=1,=0). These selectors now correctly appear before keyword-based plural forms and are sorted in ascending numeric order.