Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions 01-basic-esnext/block.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { __ } = wp.i18n;
const { __, setLocaleData } = wp.i18n;
const { registerBlockType } = wp.blocks;

const blockStyle = {
Expand All @@ -7,8 +7,10 @@ const blockStyle = {
padding: '20px',
};

setLocaleData( { '': {} }, 'gutenberg-examples' );
Copy link
Member

@iandunn iandunn Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to include the localized strings and current locale via gutenberg_get_jed_locale_data() ?

For example: https://github.com/swissspidy/gutenberg-i18n-block/blob/c2c59155f1dbbc957fa1531e42a4e4a490555253/gutenberg-i18n-block.php#L78

Related #27
cc @swissspidy

If so, then I think this approach might be a more readable, because it separates the data from the code:

// foo.php
wp_add_inline_script(
	'syntaxhighlighter-blocks',
	sprintf( '
		var syntaxHighlighterData = {
			localeData: %s
		};',
		json_encode( gutenberg_get_jed_locale_data( 'syntaxhighlighter' ) ),
	),
	'before'
);
// foo.js
setLocaleData( syntaxHighlighterData.localeData, 'syntaxhighlighter' );

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right also this changes will help in understanding how to add localization to blocks.
will update all examples to properly implement localization.

Thank you


registerBlockType( 'gutenberg-examples/example-01-basic-esnext', {
title: __( 'Example: Basic (esnext)' ),
title: __( 'Example: Basic (esnext)', 'gutenberg-examples' ),
icon: 'universal-access-alt',
category: 'layout',
edit() {
Expand Down
Loading