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(macro): Trans inside Plural has leading whitespace #1437

Merged
merged 4 commits into from
Feb 15, 2023

Conversation

Martin005
Copy link
Contributor

@Martin005 Martin005 commented Feb 14, 2023

Description

Fixes #1292

PR for updates in SWC plugin: lingui/swc-plugin#17

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 Feb 14, 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 Feb 15, 2023 at 9:26AM (UTC)

@github-actions
Copy link

github-actions bot commented Feb 14, 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%)

@codecov
Copy link

codecov bot commented Feb 14, 2023

Codecov Report

Base: 70.92% // Head: 70.92% // No change to project coverage 👍

Coverage data is based on head (1f95bab) compared to base (77d1c08).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #1437   +/-   ##
=======================================
  Coverage   70.92%   70.92%           
=======================================
  Files          75       75           
  Lines        1940     1940           
  Branches      525      525           
=======================================
  Hits         1376     1376           
  Misses        452      452           
  Partials      112      112           
Impacted Files Coverage Δ
packages/macro/src/macroJsx.ts 91.60% <ø> (ø)
packages/macro/test/jsx-plural.ts 100.00% <ø> (ø)

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

@timofei-iatsenko
Copy link
Collaborator

@Martin005 please, to next branch. We agreed on codefreeze on a main branch.

It also should be ported to the SWC plugin, otherwise would be id mismatch with messages in catalog.
Extractor uses results from the js macro, so any changes to the extraction results would affect SWC plugin.

@Martin005
Copy link
Contributor Author

Martin005 commented Feb 14, 2023

@thekip There are already a few commits to the main branch: next vs main and if we want to release some 3.x version with these bugfixes, this is the better way to go.
As for the SWC plugin, I am already looking into it and will create a PR in a moment.

@andrii-bodnar
Copy link
Contributor

Yes, it's a small fix that can be easily merged and released within a 3.x version

@timofei-iatsenko
Copy link
Collaborator

This small fix will also break existing catalogs with translations because of different whitespaces.

Also SWC plugin version should be fixed with extractor version otherwise - id mismatch.

@timofei-iatsenko
Copy link
Collaborator

@Martin005 could you add a unit test into packages/macro/src/macroJsx.test.ts "jsx macro" -> "normalizeWhitespace" suite

packages/macro/test/jsx-plural.ts Outdated Show resolved Hide resolved
packages/macro/test/jsx-plural.ts Outdated Show resolved Hide resolved
@Martin005
Copy link
Contributor Author

@thekip

This small fix will also break existing catalogs with translations because of different whitespaces.

Yeah, I keep forgetting that... I will change the base branch to next.

Also SWC plugin version should be fixed with extractor version otherwise - id mismatch.

Here is the PR for SWC plugin: lingui/swc-plugin#17

@Martin005
Copy link
Contributor Author

Martin005 commented Feb 14, 2023

@thekip

could you add a unit test into packages/macro/src/macroJsx.test.ts "jsx macro" -> "normalizeWhitespace" suite

Added in this commit

@Martin005 Martin005 changed the base branch from main to next February 14, 2023 19:16
@Martin005 Martin005 force-pushed the fix/plural-trans-whitespace branch 2 times, most recently from 2d5a6ff to bbb4776 Compare February 14, 2023 19:54
@timofei-iatsenko
Copy link
Collaborator

In the meantime, we can think about how make generating id's from original message less fragile and depend on the spaces. I have been thinking about that and don't see a clear and easy solution.

Removing all whitespaces from the message before generating the hash?

Not an option because: <Trans>Hello{' '}</Trans> and <Trans>Hello</Trans> would collide.

@andrii-bodnar andrii-bodnar merged commit 320b41f into next Feb 15, 2023
@andrii-bodnar andrii-bodnar deleted the fix/plural-trans-whitespace branch February 15, 2023 09:39
@andrii-bodnar
Copy link
Contributor

@thekip you're right, any message modification before generating hash can have unexpected downsides, so maybe it would be better not to do this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trans inside Plural has surrounding whitespace
3 participants