File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed
classes/Visualizer/Module Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -198,9 +198,23 @@ public function init() {
198
198
$ this ->_addFilter ( 'mce_external_languages ' , 'add_tinymce_lang ' , 10 , 1 );
199
199
$ this ->_addFilter ( 'mce_external_plugins ' , 'tinymce_plugin ' , 10 , 1 );
200
200
$ this ->_addFilter ( 'mce_buttons ' , 'register_mce_button ' , 10 , 1 );
201
+ $ this ->_addFilter ( 'tiny_mce_before_init ' , 'get_strings_for_block ' , 10 , 1 );
201
202
}
202
203
}
203
204
205
+ /**
206
+ * Add the strings required for the TinyMCE buttons for the classic block (not the classic editor).
207
+ *
208
+ * @since ?
209
+ * @access friendly
210
+ */
211
+ function get_strings_for_block ( $ settings ) {
212
+ $ class = new Visualizer_Module_Language ();
213
+ $ strings = $ class ->get_strings ();
214
+ $ array = array ( 'visualizer_tinymce_plugin ' => json_encode ( $ strings ) );
215
+ return array_merge ( $ settings , $ array );
216
+ }
217
+
204
218
/**
205
219
* Load plugin translation for - TinyMCE API
206
220
*
Original file line number Diff line number Diff line change @@ -68,6 +68,18 @@ public function tinymce_translation() {
68
68
return $ translated ;
69
69
}
70
70
71
+ /**
72
+ *
73
+ * The method that returns the strings array
74
+ *
75
+ * @since ?
76
+ * @access public
77
+ * @return array
78
+ */
79
+ public function get_strings () {
80
+ return $ this ->strings ;
81
+ }
82
+
71
83
}
72
84
73
85
$ visualizerLangClass = new Visualizer_Module_Language ();
Original file line number Diff line number Diff line change 3
3
( function ( $ ) {
4
4
tinymce . PluginManager . add ( 'visualizer_mce_button' , function ( editor , url ) {
5
5
editor . addButton ( 'visualizer_mce_button' , {
6
- title : editor . getLang ( 'visualizer_tinymce_plugin. plugin_label' ) ,
7
- label : editor . getLang ( 'visualizer_tinymce_plugin. plugin_label' ) ,
6
+ title : getTranslation ( editor , ' plugin_label' ) ,
7
+ label : getTranslation ( editor , ' plugin_label' ) ,
8
8
icon : 'visualizer-icon' ,
9
9
onclick : function ( ) {
10
10
var frame = wp . media ( {
16
16
} ) ;
17
17
} ) ;
18
18
19
+ /**
20
+ * Gets the translation from the editor (when classic editor is enabled)
21
+ * OR
22
+ * from the settings array inside the editor (when classic block inside gutenberg)
23
+ */
24
+ function getTranslation ( editor , slug ) {
25
+ var string = editor . getLang ( 'visualizer_tinymce_plugin.' + slug ) ;
26
+ // if the string is the same as the slug being requested for, look in the settings.
27
+ if ( string === '{#visualizer_tinymce_plugin.' + slug + '}' ) {
28
+ string = editor . settings . visualizer_tinymce_plugin [ slug ] ;
29
+ }
30
+ return string ;
31
+ }
32
+
19
33
} ) ( jQuery ) ;
You can’t perform that action at this time.
0 commit comments