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: allow passing any expression as custom i18n instance #1475

Merged
merged 1 commit into from
Mar 2, 2023

Conversation

janicduplessis
Copy link
Contributor

Description

Currently passing a custom i18n instance to the t macro only supports passing identifier, although any expression should be valid.

For example this currently crashes during extraction:

t(context.intl)`Hello`;

This changes the check from isIdentifier to isExpression so we can support function calls or member properties.

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

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 Mar 1, 2023

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

Name Status Preview Comments Updated
js-lingui ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 1, 2023 at 7:10PM (UTC)

@janicduplessis janicduplessis changed the title Allow passing any expression as custom i18n instance fix: allow passing any expression as custom i18n instance Mar 1, 2023
@github-actions
Copy link

github-actions bot commented Mar 1, 2023

size-limit report 📦

Path Size
./packages/core/build/esm/index.js 1.76 KB (0%)
./packages/detect-locale/build/esm/index.js 812 B (0%)
./packages/react/build/esm/index.js 1.79 KB (0%)
./packages/remote-loader/build/esm/index.js 7.29 KB (0%)

@thekip
Copy link
Collaborator

thekip commented Mar 1, 2023

@janicduplessis thanks for you contribution. We have an active development in next branch. Please port your changes there.

@janicduplessis janicduplessis changed the base branch from main to next March 1, 2023 19:09
@janicduplessis
Copy link
Contributor Author

@thekip Ok, I rebased against the next branch

@andrii-bodnar andrii-bodnar merged commit f591f6f into lingui:next Mar 2, 2023
@andrii-bodnar
Copy link
Contributor

@thekip do we need the same fix for the SWC plugin?

@thekip
Copy link
Collaborator

thekip commented Mar 2, 2023

I'm not sure. We need to write the same test case and check how it behaves.

Extra point: we need somehow to write a universal test fixtures for both SWC and Babel transform, to be always sure that they behave the same

@janicduplessis janicduplessis deleted the fix-custom-i18n branch March 2, 2023 14:28
thekip added a commit to lingui/swc-plugin that referenced this pull request Mar 8, 2023
thekip added a commit to lingui/swc-plugin that referenced this pull request Mar 8, 2023
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