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

fix(message-utils): correctly handle multi-digit complex argument cases #1937

Merged
merged 3 commits into from
May 16, 2024

Conversation

Bertg
Copy link
Contributor

@Bertg Bertg commented May 15, 2024

Description

Current version of lingui will not handle following pluralisation correctly: {count, plural, one {One} other {#} =13 {thirteen}}. This PR fixes that.

I also added some tests, but maybe some dedicated test should be made, I'm not sure what the maintainer expect here.

Did not report the issue separately, as I already had the fix.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

Copy link

vercel bot commented May 15, 2024

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

Name Status Preview Comments Updated (UTC)
js-lingui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 15, 2024 9:07pm

Copy link

github-actions bot commented May 15, 2024

size-limit report 📦

Path Size
./packages/core/dist/index.mjs 2.87 KB (0%)
./packages/detect-locale/dist/index.mjs 723 B (0%)
./packages/react/dist/index.mjs 1.67 KB (0%)
./packages/remote-loader/dist/index.mjs 7.26 KB (0%)

Copy link

codecov bot commented May 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.04%. Comparing base (d6b9698) to head (8f41475).
Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1937      +/-   ##
==========================================
- Coverage   76.65%   76.04%   -0.61%     
==========================================
  Files          81       85       +4     
  Lines        2090     2112      +22     
  Branches      533      541       +8     
==========================================
+ Hits         1602     1606       +4     
- Misses        375      393      +18     
  Partials      113      113              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Bertg
Copy link
Contributor Author

Bertg commented May 15, 2024

I also want to add an other suggestion here. Added it to the PR as from my POV it's a win.

I noticed that the cause of this bug was a wrong regex, and regexes are hard. We could replace that regex with this operation instead: item.key[0] === '=' ? item.key.slice(1) : item.key. I think this has several advantages:

  • Not a regex! so easier to understand
  • More intention revealing (now it is clear that this also handles cases not starting with a =
  • A lot faster, like a lot... JSBench tells me the regex method is 92.48 % slower (based on micro test cases)

So if desired, I can add that optimisation to this PR as well, or add it as a separate PR.

Copy link
Collaborator

@timofei-iatsenko timofei-iatsenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job. Thanks

@andrii-bodnar andrii-bodnar merged commit 47a0dde into lingui:main May 16, 2024
16 checks passed
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.

3 participants