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

[question]: Is there any way to use a component inside a message? #59

Open
SanichKotikov opened this issue Apr 20, 2021 · 6 comments
Open

Comments

@SanichKotikov
Copy link

Hi,

Is there any way to use a component inside a message? Something like how it works in react-intl or lingui.

<Text
  id='some.id'
  defaultMessage='Some message with <link>link text</link> in the middle.'
  link={<CustomLink to='...' />}
  // or link={(text) => <CustomLink to='...'>{text}</CustomLink>}
/>

Thanks!

@pret-a-porter
Copy link
Collaborator

Hi, it is possible, in your case it would be:

<Text
 id='some.id'
 defaultMessage='Some message with {link} in the middle.'
 link={<CustomLink to='...'>link text</CustomLink>}
/>

I will check, why it does not work, when we pass function as param.

@SanichKotikov
Copy link
Author

SanichKotikov commented Apr 20, 2021

Thanks, but as I understand it requires two templates: Some message with {link} in the middle. & link text. But I'm talking about single template: Some message with <link>link text</link> in the middle.. It's more useful and some localise platforms has free/paid limitations based on strings count.

@pret-a-porter
Copy link
Collaborator

Yes, it make sense. For now, you can do it with html tags, like:

<Text
  html
  id='some.id'
  defaultMessage='Some message with <a class="%css_class%" href="{url}">link text</a> in the middle.'
  url='%url%'
/>

Therefore you can use any html syntax inside message, but jsx syntax inside message does not supported.

@SanichKotikov
Copy link
Author

but jsx syntax inside message does not supported.

That's the case. I suppose, it might be a good feature.

@pret-a-porter
Copy link
Collaborator

Yeah, thank you for the idea! I will research, how it can be implemented nicely, but in general I would strongly recommend avoid using any code inside translations. It creates hard connection between translations and implementation of view.

@taozhou-glean
Copy link

Just curious any update on this ? ;) it would be great if we can support something similar to Trans from react-i18next. I think the benefit is that the translator will get the full context, and that can be very helpful to have accurate translations

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

No branches or pull requests

3 participants