This is all about having translation text strings and implementing them in JSX.
Lets say I have two strings. One for english and another for spanish like this:
English
const phrase = `this is just a string with some [replace]weird[/replace] link inside`
Spanish
const phrase = `esto es solo un string con un [replace]raro[/replace] enlace dentro`
When I am in English mode the string will of course come as the first example.
I am trying to replace the [replace]word inside[/replace] with a component like this.
<p dangerouslySetInnerHTML={{
__html: phrase.replace(/\[replace\](.*)\[\/replace\]/, <Link to={linkurl} >test</Link>)
}}>
The output is: this is just a string with some [object Object] link inside
This one works fine, using just plain html tags
<p dangerouslySetInnerHTML={{
__html: phrase.replace(/\[replace\](.*)\[\/replace\]/, "<b>$1</b")
}}>
</p>
the output is: this is just a string with some weird link inside
I've also tried the following:
<p dangerouslySetInnerHTML={{
__html: phrase.replace(/\[replace\](.*)\[\/replace\]/, "<Link to=\""+linkurl+"\">$1</Link>")
}}>
</p>
the output is: this is just a string with some weird link inside
but the word 'weird' should be a link element, and it's not...
By the way the component is just a component from gatsby, it allows you to navigate with routing (currently using reach router).