intlify / vue-i18n

Vue I18n for Vue 3
https://vue-i18n.intlify.dev/
MIT License
2.15k stars 327 forks source link

Modifiers for interpolated values #1754

Open lnvglr opened 7 months ago

lnvglr commented 7 months ago

Clear and concise description of the problem

Lets say you want to translate "Passenger" as well as "Remove passenger". And let's say passengers are not the only thing you want to remove (i.e. images, links etc.).

Currently, what you have to do (it seems), is to add a source key for every scenario:

{
  "passenger": "Passenger",
  "image": "Image",
  "link": "Link",
  "remove.passenger": "Remove @.lower:passenger",
  "remove.image": "Remove @.lower:image",
  "remove.link": "Remove @.lower:link"
}

And you would use it like so: $t("remove.passenger"). But that seems awfully redundant!

Suggested solution

What if, instead, you could lowercase interpolated strings.

{
  "remove": "Remove @.lower:{value}",
  "passenger": "Passenger",
  "image": "Image",
  "link": "Link",
}

And you would use it like so $t("remove", { value: $t("passenger") } )

Alternative

No response

Additional context

This would open up endless possibilities, especially for custom modifiers

Validations

lnvglr commented 1 week ago

Is there a perspective that this may get implemented at some point in the future? Or did I miss something?