Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created February 14, 2025 14:20
Show Gist options
  • Save wpscholar/df697a505f03d3b6a5b10ad8c5ba922c to your computer and use it in GitHub Desktop.
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.
// 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