Skip to content

fix: allow passing any expression as custom i18n instance#1475

Merged
andrii-bodnar merged 1 commit into
lingui:nextfrom
janicduplessis:fix-custom-i18n
Mar 2, 2023
Merged

fix: allow passing any expression as custom i18n instance#1475
andrii-bodnar merged 1 commit into
lingui:nextfrom
janicduplessis:fix-custom-i18n

Conversation

@janicduplessis
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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%)

@timofei-iatsenko
Copy link
Copy Markdown
Collaborator

@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
Copy Markdown
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
Copy Markdown
Contributor

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

@timofei-iatsenko
Copy link
Copy Markdown
Collaborator

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
timofei-iatsenko pushed a commit to lingui/swc-plugin that referenced this pull request Mar 8, 2023
timofei-iatsenko pushed 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.

3 participants