lingui / js-lingui

🌍 📖 A readable, automated, and optimized (3 kb) internationalization for JavaScript
https://lingui.dev
MIT License
4.32k stars 368 forks source link

RFC: Split macro to vanilla js + react #1361

Open thekip opened 1 year ago

thekip commented 1 year ago

Current macro assuming usage only with React. But there are cases where people want to use it with vanilla js or even different framework.

Current macro depending on @types/react and @lingui/react which brings react to the host project which might be unwanted behavior.

There was an attempt to fix this here https://github.com/lingui/js-lingui/issues/936 But the solution is far from perfect.

I propose to split macro into two different packages:

@lingui/js-macro (or just macro) @lingui/react-macro

This in future would allow us to adopt other jsx based-frameworks.

An automatic codemod could be written to help people migrate to the new version.

Related to:

andrii-bodnar commented 1 year ago

This is a good idea, I already thought exactly about a Vue package and other frameworks.

I think we can follow the existing naming:

Found one old issue related to this topic - #708 (Added to the issue description)

thekip commented 1 year ago

For macro to work, it should end on macro https://github.com/kentcdodds/babel-plugin-macros/blob/main/other/docs/author.md#filename

So @lingui/react/macro or @lingui/react-macro but not @lingui/macro/react

tricoder42 commented 1 year ago

I definitely like this idea. I always wanted to make this library framework-agnostic. Using single macro package for only for simplicity, but I understand it can be annoying.

JSteunou commented 1 year ago

I currently need this feature. I'm in a Vue project and I do not want to install the all React ecosystem. How can I help? Is there some plan I can follow?

thekip commented 4 months ago

I think we can plan that for lingui v5. I see this in the following manner:

The actual transform of code would be kept as-is, e.q. one transform process both js and jsx (react) nodes. The only changes would be in typescript typings.

Lingui would have packages called:

JSteunou commented 4 months ago

Ok so if I add the vuejs support in I could already do it with a @lingui/vue-macro package which would re-export everything from actual macro (later on the new version, which would remove the dependency with react) + the Trans useLingui vt etc