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 extracting from all forms of i18n._ / i18n.t calls #1586

Merged
merged 5 commits into from
Apr 11, 2023

Conversation

thekip
Copy link
Collaborator

@thekip thekip commented Apr 6, 2023

Description

Since i'm still not satisfied with what was done here + latest work on the Vue extractor got me thinking of another solution.

  1. Extractor could match a i18n._ call from any level deep of member access expression.

    ctx.i18n._()
    ctx.request.i18n._()
    // and so one, it matches 2 latest segments to be `i18n._`
  2. Since this matching behavior could match false positives, instead of marking manually what we should extract, i think i's better for DX to mark what we should skip

    /* lingui-extract-ignore */
    ctx.i18n._()
  3. i18n.t is a real alias of i18n._. Every usage is supported.

  4. Extractor, able to extract every usage of i18n._ or i18n.t without an explicit annotation.

    ctx.i18n._({id: "message"}); // <-- now would be correctly extracted
  5. Typings for i18n._ / i18n.t improved. Now they will not allow to misuse a library

    // there two overloads:
    
    i18n._({id: "message", values: {} });  // <-- with message descriptor
    i18n._("id", values, options);  // <-- with 3 separate parameters
    
    i18n._({id: "message", values: {}},  values, options); // <-- Error! No such overload

    mixin message descriptor with other parameters is forbidden

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

Fixes # (issue)

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 necessary documentation (if appropriate)

@vercel
Copy link

vercel bot commented Apr 6, 2023

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 Apr 11, 2023 9:45am

@github-actions
Copy link

github-actions bot commented Apr 6, 2023

size-limit report 📦

Path Size
./packages/core/dist/index.mjs 1.44 KB (0%)
./packages/detect-locale/dist/index.mjs 721 B (0%)
./packages/react/dist/index.mjs 1.56 KB (0%)
./packages/remote-loader/dist/index.mjs 7.24 KB (0%)

@thekip thekip marked this pull request as ready for review April 6, 2023 15:29
@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.26 ⚠️

Comparison is base (6d645de) 75.55% compared to head (a026291) 75.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #1586      +/-   ##
==========================================
- Coverage   75.55%   75.30%   -0.26%     
==========================================
  Files          76       76              
  Lines        1980     1976       -4     
  Branches      520      516       -4     
==========================================
- Hits         1496     1488       -8     
- Misses        372      375       +3     
- Partials      112      113       +1     
Impacted Files Coverage Δ
...ackages/babel-plugin-extract-messages/src/index.ts 93.61% <100.00%> (-0.27%) ⬇️
packages/core/src/i18n.ts 67.16% <100.00%> (-5.98%) ⬇️

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 in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@j4hr3n j4hr3n left a comment

Choose a reason for hiding this comment

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

Looks like a pretty solid change to me! 👏

website/docs/guides/message-extraction.md Outdated Show resolved Hide resolved
website/docs/guides/message-extraction.md Outdated Show resolved Hide resolved
website/docs/guides/message-extraction.md Outdated Show resolved Hide resolved
Co-authored-by: Andrii Bodnar <andrii.bodnar@crowdin.com>
@thekip
Copy link
Collaborator Author

thekip commented Apr 11, 2023

@andrii-bodnar done

@andrii-bodnar andrii-bodnar merged commit 1a0d88d into lingui:next Apr 11, 2023
14 checks passed
@thekip thekip deleted the i18n-t-alias branch April 11, 2023 15:36
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.

None yet

3 participants