【发布时间】:2021-11-19 17:47:12
【问题描述】:
在 WordPress 中创建块时,我需要添加一个带有链接的翻译。我在 JS 中这样做,但它没有提供预期的结果:
import { render } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
export default function Final() {
let d = <a href="https://example.com">bothered me.</a>;
return (
<p> { __( 'The cold never {d} anyway.', 'text-domain' ) } </p>
)
}
document.addEventListener( "DOMContentLoaded", function(event) {
const appRoot = document.getElementById( 'root' );
if ( appRoot ) {
render(
<Final/>,
appRoot
)
}
});
在 PHP 中,我可以使用 sprintf 并使用 %1s 之类的占位符轻松做到这一点。
echo sprintf(
__( 'The cold never %1s anyway', 'text-domain' ),
'<a href="https://example.com">bothered me.</a>'
);
在 react 中创建块时如何做 sprintf 的等效操作?
【问题讨论】:
标签: javascript php reactjs wordpress jsx