模板或模板片段中的文本如果是HTML文件,则不能被翻译。
模式块可以用来在一个区块模板内插入可翻译的内容。由于这些文件是基于PHP的,所以有一种机制可以标记字符串进行翻译或提供动态URL。
区块模式示例
<?php register_block_pattern( 'myfirsttheme/wordpress-credit', array( 'title' => __( 'WordPress credit', 'myfirsttheme' ), 'content' => ' <!-- wp:paragraph --> <p>' . sprintf( /* Translators: WordPress link. */ esc_html__( 'Proudly Powered by %s', 'myfirsttheme' ), '<a href="' . esc_url( __( 'https://wordpress.org', 'myfirsttheme' ) ) . '" rel="nofollow">WordPress</a>' ) . '</p> <!-- /wp:paragraph -->', 'inserter' => false ) );
可以使用参数:'inserter' => false
从块插入器中隐藏模式
使用模式块在模板或模板片段中添加模式:
<!-- wp:group --> <div class="wp-block-group"> <!-- wp:pattern {"slug":"myfirsttheme/wordpress-credit"} /--> </div> <!-- /wp:group -->
资源链接
更新日志:
- Created 2022-01-24