Skip to content

docs: migrate examples to v4#1674

Merged
andrii-bodnar merged 1 commit intolingui:mainfrom
timofei-iatsenko:migrate-examples-v4
May 26, 2023
Merged

docs: migrate examples to v4#1674
andrii-bodnar merged 1 commit intolingui:mainfrom
timofei-iatsenko:migrate-examples-v4

Conversation

@timofei-iatsenko
Copy link
Copy Markdown
Collaborator

Description

Some of examples get outdated after updating to v4. This PR migrates them to latest version.

#1673

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

vercel Bot commented May 26, 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 May 26, 2023 9:17am

@github-actions
Copy link
Copy Markdown

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.59 KB (0%)
./packages/remote-loader/dist/index.mjs 7.24 KB (0%)

one: 'Developer',
other: `Developers`
})}
<Plural value={selected} one={'Developer'} other={`Developers`} />
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@yunsii whenever non-react macro (t, plural, select, etc) is used in react component, useLingui() hook should be added as well. OR just use JSX macro instead.

That caused a translation mismatch you noticed in the issue.

Here i've just changed it to JSX macro, because it's more appropriate usage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It means if i don't use i18n, should still call useLingui hook like below?

import { useLingui } from "@lingui/react"
import { plural } from '@lingui/macro'

function App() {
  useLingui()
  //...

  return (
    <p>
      {plural(selected, {
        one: 'Developer',
        other: `Developers`
      })}
    </p>
  )
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes. plural / t / select / selectOrdinal macro is simply a syntax sugar over i18n, it is expanded to the i18n._ call during build.

I recommend to use react-related macros whenever possible, because it auto subscribe for a changes and less error-prone.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Theaks for your detail explanation 👌

Comment on lines +24 to +26
#. js-lingui-explicit-id
#: src/components/AboutText.tsx:6
msgid "next-explanation"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@yunsii for explicit custom ids lingui@4 requires #. js-lingui-explicit-id comment to be added. This was a root cause why this section was not translated.

"@lingui/core": "^4.1.2",
"@lingui/react": "^4.1.2",
"next": "13.2.3",
"next": "13.3.1",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The release version of @lingui/swc-plugin was built with a newer version of the swc-core, which is not compatible with next@13.2.3" this caused a "panic" during build. I put a compatible version and added a compatibility notice into readme.

@timofei-iatsenko timofei-iatsenko changed the title examples: migrate examples to v4 docs: migrate examples to v4 May 26, 2023
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (f06cdf5) 75.70% compared to head (984e17a) 75.70%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1674   +/-   ##
=======================================
  Coverage   75.70%   75.70%           
=======================================
  Files          79       79           
  Lines        2033     2033           
  Branches      520      520           
=======================================
  Hits         1539     1539           
  Misses        379      379           
  Partials      115      115           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@andrii-bodnar
Copy link
Copy Markdown
Contributor

@thekip thank you!

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