我可以使用wordpress成功翻译我的插件。org用于所有php字符串。一切都很好。我甚至可以看到需要翻译的字符串https://translate.wordpress.org/projects/wp-plugins/simpletoc/stable/de/default/ 在这种情况下,它是“更新目录”:
https://plugins.trac.wordpress.org/browser/simpletoc/tags/1.8/build/index.js#L111
所以我翻译了它们,等了24小时。我可以翻译新的php字符串,但JavaScript翻译仍然无法显示。当然,我从wordpress下载了最新的翻译。组织机构=/
下面是相关的php代码
add_action(\'init\', __NAMESPACE__ . \'\\\\init\');
add_action(\'init\', __NAMESPACE__ . \'\\\\register_block\');
function init() {
wp_register_script(
\'simpletoc\',
plugins_url(\'build/index.js\', __FILE__),
[ \'wp-i18n\', \'wp-blocks\', \'wp-editor\', \'wp-element\', \'wp-server-side-render\'],
filemtime(plugin_dir_path(__FILE__) . \'build/index.js\')
);
wp_register_style(
\'simpletoc-editor\',
plugins_url(\'editor.css\', __FILE__),
array( \'wp-edit-blocks\' ),
filemtime(plugin_dir_path(__FILE__) . \'editor.css\')
);
if (function_exists(\'wp_set_script_translations\')) {
/**
* May be extended to wp_set_script_translations( \'my-handle\', \'my-domain\',
* plugin_dir_path( MY_PLUGIN ) . \'languages\' ) ). For details see
* https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/
*/
wp_set_script_translations(\'simpletoc-js\', \'simpletoc\');
}
}
这是索引。js公司
const { __ } = wp.i18n;
const el = wp.element.createElement;
const registerBlockType = wp.blocks.registerBlockType;
const BlockControls = wp.blockEditor.BlockControls;
const ServerSideRender = wp.serverSideRender;
const Toolbar = wp.components.Toolbar;
const IconButton = wp.components.Button;
const simpletocicon = wp.element.createElement(\'svg\', { width: 20, height: 20 },
el(\'path\', {
d: "M5.5 7C4.67 7 4 6.33 4 5.5 4 4.68 4.67 4 5.5 4 6.32 4 7 4.68 7 5.5 7 6.33 6.32 7 5.5 7zM8 5h9v1H8V5zm-2.5 7c-.83 0-1.5-.67-1.5-1.5C4 9.68 4.67 9 5.5 9c.82 0 1.5.68 1.5 1.5 0 .83-.68 1.5-1.5 1.5zM8 10h9v1H8v-1zm-2.5 7c-.83 0-1.5-.67-1.5-1.5 0-.82.67-1.5 1.5-1.5.82 0 1.5.68 1.5 1.5 0 .83-.68 1.5-1.5 1.5zM8 15h9v1H8v-1z"
})
);
function sendfakeAttribute(props) {
// this acuallty triggers the ServerSideRender again ¯\\_(ツ)_/¯
props.setAttributes({ updated: Date.now()});
}
registerBlockType(\'simpletoc/toc\', {
title: __(\'SimpleTOC\', \'simpletoc\'),
icon: simpletocicon,
category: \'layout\',
edit: function(props) {
return [
el(
BlockControls, { key: \'controls\' },
el( Toolbar, null,
el(
IconButton, {
className: \'components-icon-button components-toolbar__control\',
label: __(\'Update table of contents\', \'simpletoc\'),
onClick: function() {
sendfakeAttribute(props)
},
icon: \'update\'
}
)
)
),
el(
\'p\', { className: props.className },
el(
ServerSideRender, {
block: props.name,
attributes: props.attributes
}
)
)
];
},
save: props => {
return null;
},
});
整个插件可在此处找到:
https://github.com/mtoensing/simpletoc知道为什么这个标签:\\uuu(\'Update table of contents\',\'simpletoc\')没有被翻译,但php所做的一切都被翻译了吗?