古腾堡块翻译

时间:2021-06-03 11:11:20

标签: wordpress wordpress-gutenberg gutenberg-blocks polylang

我有一个带有 Polylang 插件的多语言网站。所有 PHP 翻译都有效,但现在我在我的主题中创建了自定义古腾堡块,我正在努力将其翻译成英语。

我正在粘贴整个代码,因为我没有更多想法在哪里查找错误。

这是我在 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

任何想法有什么问题?谢谢

0 个答案:

没有答案