This repository has been archived by the owner on Dec 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgutenberg-i18n-block.php
73 lines (63 loc) · 1.82 KB
/
gutenberg-i18n-block.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Plugin Name: Gutenberg I18N Block
* Plugin URI: https://github.com/swissspidy/gutenberg-i18n-block
* Description: Gutenberg block to demo internationalization functionality.
* Author: Pascal Birchler (@swissspidy)
* Author URI: https://pascalbirchler.com
* Text Domain: gutenberg-i18n-block
* Domain Path: /languages
* Version: 0.2.0
*/
namespace Swissspidy\Gutenberg\Blocks\I18n;
/**
* Load all translations for our plugin from the MO file.
*/
function load_textdomain() {
load_plugin_textdomain( 'gutenberg-i18n-block', false, basename( __DIR__ ) . '/languages' );
}
add_action( 'init', __NAMESPACE__ . '\load_textdomain' );
/**
* Registers all block assets so that they can be enqueued through Gutenberg in
* the corresponding context.
*
* Passes translations to JavaScript.
*/
function register_block() {
$script_dependencies = file_exists( __DIR__ . '/build/index.deps.json' )
? json_decode( file_get_contents( __DIR__ . '/build/index.deps.json' ), false )
: array();
wp_register_script(
'gutenberg-i18n-block-editor',
plugins_url( 'build/index.js', __FILE__ ),
$script_dependencies,
'0.2.0'
);
wp_set_script_translations(
'gutenberg-i18n-block-editor',
'gutenberg-i18n-block',
plugin_dir_path( __FILE__ ) . 'languages'
);
wp_register_style(
'gutenberg-i18n-block-editor',
plugins_url( 'assets/editor.css', __FILE__ ),
array(
'wp-blocks',
),
'0.2.0'
);
wp_register_style(
'gutenberg-i18n-block',
plugins_url( 'assets/style.css', __FILE__ ),
array(
'wp-blocks',
),
'0.2.0'
);
register_block_type( 'gutenberg-i18n-block/block', array(
'editor_script' => 'gutenberg-i18n-block-editor',
'editor_style' => 'gutenberg-i18n-block-editor',
'style' => 'gutenberg-i18n-block',
) );
}
add_action( 'init', __NAMESPACE__ . '\register_block', 20 );