PluginProbe
Code Snippets / 3.10.1
Code Snippets v3.10.1
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / php / Integration / Classic_Editor / mce-strings.php

mce-strings.php in Code Snippets 3.10.1, at php/Integration/Classic_Editor/mce-strings.php

60 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * For some reason, WordPress requires that TinyMCE translations be hosted in an external file. So that's what this is.
4 *
5 * @package Code_Snippets
6 *
7 * phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
8 */
9
10 namespace Code_Snippets\Integration\Classic_Editor;
11
12 use _WP_Editors;
13 use Code_Snippets\Model\Snippet;
14 use function Code_Snippets\get_snippets;
15
16 /**
17 * Variable types.
18 *
19 * @var array<string, string|array<string, Snippet[]>> $strings
20 */
21
22 $strings = [
23 'insert_content_menu' => __( 'Content Snippet', 'code-snippets' ),
24 'insert_content_title' => __( 'Insert Content Snippet', 'code-snippets' ),
25 'snippet_label' => __( 'Snippet', 'code-snippets' ),
26 'php_att_label' => __( 'Run PHP code', 'code-snippets' ),
27 'format_att_label' => __( 'Apply formatting', 'code-snippets' ),
28 'shortcodes_att_label' => __( 'Enable shortcodes', 'code-snippets' ),
29
30 'insert_source_menu' => __( 'Snippet Source Code', 'code-snippets' ),
31 'insert_source_title' => __( 'Insert Snippet Source', 'code-snippets' ),
32 'show_line_numbers_label' => __( 'Show line numbers', 'code-snippets' ),
33 ];
34
35 $strings = array_map( 'esc_js', $strings );
36
37 $snippets = get_snippets();
38
39 $strings['all_snippets'] = [];
40 $strings['content_snippets'] = [];
41
42 foreach ( $snippets as $snippet ) {
43 if ( 'content' === $snippet->scope ) {
44 $strings['content_snippets'][ $snippet->id ] = $snippet->display_name;
45 }
46
47 $strings['all_snippets'][ $snippet->id ] = sprintf(
48 '%s (%s)',
49 $snippet->display_name,
50 strtoupper( $snippet->type )
51 );
52 }
53
54 asort( $strings['all_snippets'], SORT_STRING | SORT_FLAG_CASE );
55 asort( $strings['content_snippets'], SORT_STRING | SORT_FLAG_CASE );
56
57 $strings = [ _WP_Editors::$mce_locale => [ 'code_snippets' => $strings ] ];
58 /** $strings is used by outer file. @noinspection PhpUnusedLocalVariableInspection */
59 $strings = 'tinyMCE.addI18n(' . wp_json_encode( $strings ) . ');';
60