Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getTranslation to return string Type #11

Closed
ieow opened this issue Jul 24, 2017 · 4 comments
Closed

getTranslation to return string Type #11

ieow opened this issue Jul 24, 2017 · 4 comments

Comments

@ieow
Copy link

ieow commented Jul 24, 2017

Hi,
getTranslation is define to return LocalizedElement type
returns (key | key[], data) => LocalizedElement | { [key: string]: LocalizedElement }

Is there a way to return string type only?
Thanks

@ryandrewjohnson
Copy link
Owner

In order to allow for the rendering of HTML inside translation strings it needs to be returned as an element. I will look into maybe only returning an element when HTML is detected in the translation, and for other scenarios it would just return a string.

Would that satisfy your ask?

@ieow
Copy link
Author

ieow commented Jul 25, 2017

Actually, if there is an option for me to choose String type would be good enough.
I am now using LocalizedElement.props.children which is not a good solution.

@ryandrewjohnson
Copy link
Owner

I have updated the translate function to return a string when a translation does not include HTML. In the case where a translation contains HTML it will still return the translation wrapped in a <span> tag like it did previously.

I have also updated the README for getTranslate to explain this.

I chose this route instead of adding an option because:

  1. Keeps the API the same - no changes needed
  2. In order to render HTML contained in translations it has to be wrapped in a React element anyway.

You can find the changes in v2.3.0.

@ieow
Copy link
Author

ieow commented Jul 25, 2017

Cool. Thanks. Tested. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants