Created
February 14, 2025 14:20
-
-
Save wpscholar/df697a505f03d3b6a5b10ad8c5ba922c to your computer and use it in GitHub Desktop.
An example of how to use the createInterpolateElement in React to properly translate a string containing HTML or a React component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See https://developer.wordpress.org/block-editor/reference-guides/packages/packages-element/#createinterpolateelement | |
import { __ } from '@wordpress/i18n'; | |
import { createInterpolateElement } from '@wordpress/element'; | |
function MyComponent() { | |
return createInterpolateElement( | |
__( 'Please <Link>visit our site</Link> for more info.', 'text-domain' ), | |
{ | |
Link: <a href="https://example.com" />, | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment