-
Notifications
You must be signed in to change notification settings - Fork 383
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(macro): add useLingui macro #1859
feat(macro): add useLingui macro #1859
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
d8d4565
to
e30fd67
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1859 +/- ##
==========================================
+ Coverage 76.66% 77.04% +0.37%
==========================================
Files 81 82 +1
Lines 2083 2139 +56
Branches 532 548 +16
==========================================
+ Hits 1597 1648 +51
- Misses 375 378 +3
- Partials 111 113 +2 ☔ View full report in Codecov by Sentry. |
thinking about it, I think a better way may be when the references are processed in the index file, add the |
refactored your PR per my last comment: In my implementation:
|
@dan-dr i cherry-picked your changes to the branch of this PR. I'm going to re-check your changes, add more tests, and mark PR as ready when I finish. Thanks for help and contributing. |
There still issue if the renamed import of useLingui is existing in the file and has renamed specifier, but the same error would be with any other macro, and i dont rembmer any user have issue with that. import { useLingui as useLinguiMacro } from '@lingui/macro';
import { useLingui as useLinguiRenamed } from '@lingui/react';
function MyComponent() {
const { _ } = useLinguiRenamed();
console.log(_);
const { t } = useLinguiMacro();
const a = t`Text`;
} I'm going to fix it in next iterations in another PR's. I'm already working on refactoring which will help with experimental extractor and fix edge cases with renamed imports as well. |
17621bf
to
0544aef
Compare
I updated documentation for useLingui macro. I feel that documentation could be better, but i did my best honestly. |
@andrii-bodnar when it can be merged? I'm thinking of merging it to the main and creating a pre-release (with |
@thekip I can release it with the |
So let's merge it, so i can concentrate on this #1867 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thekip @dan-dr @vonovak thanks for your efforts and contributions!
Overall it looks good to me, but I was concerned about the confusion it might cause for developers trying to understand the difference between the useLingui
macro and the useLingui
React hook. Even now, it's a bit confusing at the documentation level.
The use<something>
is a typical naming convention for React hooks. In our case, the useLingui
macro might be confusing because of this naming convention for hooks.
Perhaps we need to better document the difference or consider choosing a different name for the macro.
What do you think guys?
Co-authored-by: Andrii Bodnar <andrii.bodnar@crowdin.com>
This similar to Trans, which has two versions, macro and runtime. I think naming is fine, but documentation could be improved. |
Guys, i believe we can improve documentation any time later, that should not block merging the feature. |
@thekip thanks for the clarification! Could you please address the 3 remaining discussions? #1859 (comment) Then, I am going to merge this to the |
@andrii-bodnar @vonovak regarding naming, i think we can rise the discussion. I believe the initial idea for macro was a "subset" of the original params from runtime versions (as original author said). So they signatures originally had to match to each other. But since then react/js ecosystem shifted towards typescript and quality typings and high type safety become a more valuable than ever. That resulted in changes in lingui, where runtime and macro version got they own typings with different signatures to highlight for developers different usages of macro/runtime versions. So now we have Trans from /react and /Trans from macro which are diffrent components. This PR will add useLingui from /macro in additional to /react. I think, maybe it's time to change the naming to something more explicit?
The Plural Select and SelectOrdinal doesn't have runtime counterparts, they are traspiled to Trans, but i believe they should be renamed to follow the same naming convention:
What do you think? |
Could next release be created from "main" branch? I don't see a reason for branching here |
Reverted the docs, and just resolved rest, there are nothing to do about them. |
Sounds interesting. Let's move this to a separate discussion and consider it in planning the v5 release. Currently, I don't have other ideas, but the
When merging into the |
I was going to release it today but GitHub is currently experiencing an outage with Actions 😬 Probably better to do it on Monday. |
Co-authored-by: ddyo <danrosenshain@gmail.com>
Co-authored-by: ddyo <danrosenshain@gmail.com>
#1852
Adds new macro
useLingui
which is drastically simplify working with non-jsx messages in react components:becomes:
All syntax flavors of original
t
function is also supported.Also, it's possible to use returned
t
as dependency in react hooks:The implementation still has some not covered cases, but I believe it should cover 95% regular cases and it's already good enough to give it a try.
Description
Types of changes
Fixes # (issue)
Checklist