How to pass/interpolate components in paraglide-js (e.g. Link-Component) ? #1959
-
Say, i want to display a notification like : "User {actingUser} has blocked user {affectedUser} for reason {reason}" and instead of plain text i want to link to the respective user profiles via a Link-component. I believe in react-i18next I was able to just pass that component into the translate-function. Mapped to paraglide-js I would imagine it would work similar like:
But doing so will right now stringify the component which then results in [object object]. My question is, wether interpolating components is supported using another way or if there is a best practice how to deal with text that should include components - other than splitting it up in multiple sub strings? Greets |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
That's a use-case we haven't really considered before. I don't believe there currently is a any way to do it. However, given that this likely is a common use-case we will think of something |
Beta Was this translation helpful? Give feedback.
-
To add to @LorisSigrist #1959 (comment), our major concern is collaboration with translators and designers when we add such a feature to paraglide js. Mixing code/rendering logic into messages will exclude every non-dev that needs to be collaborated with. While the desire exists from a dev perspective, the outcome might be devasting from an organizational perspective. Questions like "How do designers and translators interact with this feature?" need to be elaborated before we can implement this feature. |
Beta Was this translation helpful? Give feedback.
-
To start off the elaboration, I believe this is largely a theoretical issue. In my example, translators must not care about wether variables in the en.json within the key "blockUser" actually output a plain string or Link-Components, Avatar-Images or even just a different text format like making that part bold. But from a developer-perspective it is crucial that the original and translated sentence under the key "blockuser" is complete and correct in a grammatical sense. We can not naively split up the string like:
and then (again naively) put that together:
This is not only a nightmare to maintain, it also will not work in different languages that have different grammatical rules. Also, the translator has not really any context anymore what the translation is about. As I stated before, react-i18next which I used a couple of years ago does allow for quite some ways of interpolating, from simple cases like text formatting within a sentence to embedding full React components. (https://react.i18next.com/latest/trans-component) While I don't believe you would need all of their options, I think that to allow replacing {key} only with plain text is not sufficient for many projects where localization is required. Greets |
Beta Was this translation helpful? Give feedback.
Oh, now I understand your use case! What you are describing is in RFC stage at #913.
TL;DR
{b}
tag should become a<Bold>
React componentIf #913 is your use case, please mark my reply as the answer so that we can close this feature request in favor of the other one.