Defining Custom React Components as a Wrapper for the Trans Macro #1728
-
Hello, I'm currently working on a project where we'd like to wrap the
This way you could use it like:
and after running This way, we could use our own components like Is there a way to achieve this directly, or could this be a feature considered for future releases? I believe it could provide additional flexibility for projects that have their own component libraries. Thank you for your time and your work on this project. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
No, it's not possible and never would be. The extractor operates on AST, it doesn't execute your code. All your strings should be explicitly marked for extraction with either Trans, t, or any of i18n methods to be picked up by extractor. So you library could be used only this way: import { Heading } from '@chakra-ui/react';
import { Trans } from '@lingui/macro';
<Heading>
<Trans>My message!</Trans> <!-- // Message declared in-place, and could be statically analyzed -->
</Heading> |
Beta Was this translation helpful? Give feedback.
No, it's not possible and never would be. The extractor operates on AST, it doesn't execute your code. All your strings should be explicitly marked for extraction with either Trans, t, or any of i18n methods to be picked up by extractor.
So you library could be used only this way: