Allow sending elements as parameter #520
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 becomeDelete
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}
, literallyDelete 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.