preact-translate icon indicating copy to clipboard operation
preact-translate copied to clipboard

Allow sending elements as parameter

Open mbenoukaiss opened this issue 5 months ago • 0 comments

Firstly thank you for your work !

Problem

I started using your library however there is one feature which I needed and was not covered by your library which is to allow using elements as params to the translation function. This may be needed when someone wants to have elements like inputs in the end result for example.

It may already already be achieved by just splitting the translation string into multiple strings like Delete {user}'s {object} would become Delete and 's however this is not practical and you would most likely end up in awkward translations since the order of words changes depending on the language. For example in french one way to say it would be Supprime le {object} de {user}, literally Delete the {object} of {user}, correct english but the unnecessary "of" preposition adds to wordiness. (there are probably better examples)

Proposed fix

One way I found to do it without breaking existing uses of the library would be to keep the current code and make the function return a string if there is no object (read JSX.Element) in the params, else it returns an array that may contain strings, numbers or JSX.Element.

I don't know much about (p)react or typescript since I am quite new to both, so there may be better ways to do it, let me know if you want me to change some things.

mbenoukaiss avatar Jan 13 '24 12:01 mbenoukaiss