Get With Gutenberg - How to Internationalize Your Block • https://getwithgutenberg.com/2019/04/how-to-internationalize-your-block/
<?php | |
function gwg_register_block_type() { | |
if ( ! function_exists( 'register_block_type' ) ) { | |
// Gutenberg is not active. | |
return; | |
} | |
wp_register_style( | |
'gwg-style', | |
GWG_ESNEXT_PLUGIN_URL . 'style.css', | |
[], | |
GWG_ESNEXT_VERSION | |
); | |
wp_register_style( | |
'gwg-editor', | |
GWG_ESNEXT_PLUGIN_URL . 'editor.css', | |
[], | |
GWG_ESNEXT_VERSION | |
); | |
wp_register_script( | |
'gwg-block', | |
GWG_ESNEXT_PLUGIN_URL . 'block.build.js', | |
[ 'wp-blocks', 'wp-i18n' ], | |
GWG_ESNEXT_VERSION, | |
true // Enqueue script in the footer. | |
); | |
register_block_type( | |
'gwg/esnext-starter', | |
[ | |
'editor_script' => 'gwg-block', | |
'editor_style' => 'gwg-editor', | |
'style' => 'gwg-style', | |
] | |
); | |
} | |
add_action( 'init', 'gwg_register_block_type' ); |
registerBlockType('gwg/esnext-starter', { | |
title: __('Get With Gutenberg - ESNext Starter', 'gwg'), | |
category: 'common', | |
edit(props) { | |
return <p className={props.className}>{__('Hello editor.', 'gwg')}</p>; | |
}, | |
save(props) { | |
return <p className={props.className}>{__('Hello saved content.', 'gwg')}</p>; | |
}, | |
}); |
<script type='text/javascript'> | |
( function( domain, translations ) { | |
var localeData = translations.locale_data[ domain ] || translations.locale_data.messages; | |
localeData[""].domain = domain; | |
wp.i18n.setLocaleData( localeData, domain ); | |
} )( "gwg", {"translation-revision-date":"YEAR-MO-DA HO:MI+ZONE","generator":"WP-CLI\/2.1.0","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"en","plural-forms":"nplurals=2; plural=(n != 1);"},"Get With Gutenberg - ESNext Starter":[""],"Hello editor.":[""],"Hello saved content.":[""]}}} ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment