lingui / js-lingui

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

Place PO file relatively to the component file #2025

Open hejtmii opened 1 week ago

hejtmii commented 1 week ago

Is your feature request related to a problem? Please describe. We are using AI to help with our codebase. We would auto-translate the PO files giving the AI also the original source file code to get as much context as possible. To effectively script it and keep it near the original context, we would like to place the PO file in the same directory as the original source code.

However, the {name} macro only gives the name of the original file...

Describe proposed solution Offer some {dir} macro that will resolve into a folder of the source component

Describe alternatives you've considered I was thinking about {path} macro as a full path to the component, but I think dir is more versatile, as it can be combined with {name} when needed and cover both (all) needs that I can imagine

Additional context I could create a PR for this if approved. Otherwise I would like to learn if there are any serious reasons why you wouldn't like it.

vonovak commented 1 week ago

Hello and thanks for asking,

we would like to place the PO file in the same directory as the original source code.

probably not as fine-grained as you want it but take a look at this config

However, the {name} macro only gives the name of the original file...

I'm afraid I don't follow what you're saying TBH. Can you expand?

TY 🙂

hejtmii commented 1 week ago

Sure, as you linked that config, the {name} macro resolved only to RegistrationForm but there is no macro that would allow placing the result in the same directory as the component. In the case you linked the "component library" is rather flat, but our solution structure is rather large and hierarchical. Here is an example of files and their translations I would like to work with:

/components/shared/Button/Button.tsx
/components/shared/Button/Button.cs.po
/components/shared/Button/Button.en.po

/components/richText/plugins/images/components/Image.tsx
/components/richText/plugins/images/components/Image.cs.po
/components/richText/plugins/images/components/Image.en.po

/apps/assets/components/Image.tsx
/apps/assets/components/Image.cs.po
/apps/assets/components/Image.en.po

And I would like to keep the translation dictionaries separate for components named the same, just placed in different parts of the app, and keep the PO files close to the source they belong to

In this simple example I could register 3 catalogs, but in our case there are hundreds of such components and app parts at various levels of hierarchy