wordpress - 古腾堡块翻译
问题描述
我有带有 Polylang 插件的多语言网站。所有 PHP 翻译都有效,但现在我在我的主题中创建了自定义 Gutenberg 块,我正在努力将其翻译成英文。
我正在粘贴整个代码,因为我没有更多的想法去哪里寻找错误。
这是我的块src/index.js
:
import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import { InnerBlocks } from '@wordpress/block-editor';
registerBlockType( 'neuro/references-block', {
title: __( 'Bibliografia', 'neuro' ),
icon: 'book',
category: 'text',
edit: ( props ) => {
const ALLOWED_BLOCKS = [ 'core/list', 'core/paragraph' ];
return (
<div className={ props.className }>
<h4>{ __( 'Bibliografia', 'neuro' ) }</h4>
<InnerBlocks allowedBlocks={ ALLOWED_BLOCKS } />
</div>
);
},
save: ( props ) => {
return (
<div className={ props.className }>
<h4>{ __( 'Bibliografia', 'neuro' ) }</h4>
<InnerBlocks.Content />
</div>
);
},
} );
它被编译成build/index.js
文件。
我创建了neuro-en_GB-neuro-references-block.json
放置在languages
文件夹中的文件,这是它的内容:
{"translation-revision-date":"","generator":"WP-CLI\/2.5.0","source":"build\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"en-gb","plural-forms":"nplurals=2; plural=(n != 1);"},"Bibliografia":["References"]}}}
在functions.php
文件中,我像这样注册古腾堡块:
function neuro_register_gutenberg_block() {
wp_register_script(
'neuro-references-block',
get_template_directory_uri() . '/build/index.js',
array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-i18n', 'wp-polyfill' ),
'1.0.0'
);
register_block_type( 'neuro/references-block', array(
'editor_script' => 'neuro-references-block',
) );
}
add_action( 'init', 'neuro_register_gutenberg_block' );
我设置这样的翻译:
function neuro_set_script_translations() {
wp_set_script_translations( 'neuro-references-block', 'neuro', get_template_directory() . '/languages' );
}
add_action( 'init', 'neuro_set_script_translations' );
我的wp_set_script_translations
函数返回true
。
有什么想法有什么问题吗?谢谢
解决方案
推荐阅读
- asn1 - ASN1 全局约束
- api - 使用 RestSharp 的 API 测试不断返回“未经授权的访问,无效的 API 密钥”
- regex - 使用正则表达式 tr 或 awk 过滤 bash 脚本中的变量
- python - 如何在 pandas 中应用 groupby 以随着时间的推移计算出特定于客户的查询
- python - 有没有使用python客户端删除现有记录箱的功能
- angular - 如何以角度绑定 8 位十六进制颜色
- powershell - PowerShell - 在远程机器/计算机上调用命令
- javascript - 页面在 MutationObserver 内的 chrome 扩展中完全加载完成后执行功能
- php - 如何使用普通托管服务使用 php 进行端口转发
- android - 使用最新的番石榴库实现 CacheBuilder 时出错(实现 'com.google.guava:guava:28.2-jre)