Ticket #11520: print_scripts_l10n.2.diff

File print_scripts_l10n.2.diff, 8.1 KB (added by scribu, 2 years ago)

get rid of 'l10n_print_after' hack

Line 
1Index: wp-includes/class.wp-scripts.php
2===================================================================
3--- wp-includes/class.wp-scripts.php    (revision 17567)
4+++ wp-includes/class.wp-scripts.php    (working copy)
5@@ -48,34 +48,23 @@
6        }
7 
8        function print_scripts_l10n( $handle, $echo = true ) {
9-               if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) || !is_array($this->registered[$handle]->extra['l10n'][1]) )
10+               if ( empty($this->registered[$handle]->extra['l10n']) || empty($this->registered[$handle]->extra['l10n'][0]) )
11                        return false;
12 
13                $object_name = $this->registered[$handle]->extra['l10n'][0];
14+               $data = $this->registered[$handle]->extra['l10n'][1];
15 
16-               $data = "var $object_name = {\n";
17-               $eol = '';
18-               foreach ( $this->registered[$handle]->extra['l10n'][1] as $var => $val ) {
19-                       if ( 'l10n_print_after' == $var ) {
20-                               $after = $val;
21-                               continue;
22-                       }
23-                       $data .= "$eol\t$var: \"" . esc_js( $val ) . '"';
24-                       $eol = ",\n";
25-               }
26-               $data .= "\n};\n";
27-               $data .= isset($after) ? "$after\n" : '';
28+               $output = "var $object_name = " . json_encode($data) . "; $after\n";
29 
30-               if ( $echo ) {
31-                       echo "<script type='text/javascript'>\n";
32-                       echo "/* <![CDATA[ */\n";
33-                       echo $data;
34-                       echo "/* ]]> */\n";
35-                       echo "</script>\n";
36-                       return true;
37-               } else {
38-                       return $data;
39-               }
40+               if ( !$echo )
41+                       return $output;
42+
43+               echo "<script type='text/javascript'>\n";
44+               echo "/* <![CDATA[ */\n";
45+               echo $output;
46+               echo "/* ]]> */\n";
47+               echo "</script>\n";
48+               return true;
49        }
50 
51        function do_item( $handle, $group = false ) {
52Index: wp-includes/script-loader.php
53===================================================================
54--- wp-includes/script-loader.php       (revision 17567)
55+++ wp-includes/script-loader.php       (working copy)
56@@ -68,7 +68,6 @@
57        $scripts->add_data( 'common', 'group', 1 );
58        $scripts->localize( 'common', 'commonL10n', array(
59                'warnDelete' => __("You are about to permanently delete the selected items.\n  'Cancel' to stop, 'OK' to delete."),
60-               'l10n_print_after' => 'try{convertEntities(commonL10n);}catch(e){};'
61        ) );
62 
63        $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", false, '1.6.1' );
64@@ -86,7 +85,6 @@
65                'enterURL' => __('Enter the URL'),
66                'enterImageURL' => __('Enter the URL of the image'),
67                'enterImageDescription' => __('Enter a description of the image'),
68-               'l10n_print_after' => 'try{convertEntities(quicktagsL10n);}catch(e){};'
69        ) );
70 
71        $scripts->add( 'colorpicker', "/wp-includes/js/colorpicker$suffix.js", array('prototype'), '3517m' );
72@@ -100,7 +98,6 @@
73        $scripts->localize( 'wp-ajax-response', 'wpAjax', array(
74                'noPerm' => __('You do not have permission to do that.'),
75                'broken' => __('An unidentified error has occurred.'),
76-               'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};'
77        ) );
78 
79        $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), '20110327' );
80@@ -193,7 +190,6 @@
81                        'of' => __('of'),
82                        'close' => __('Close'),
83                        'noiframes' => __('This feature requires inline frames. You have iframes disabled or your browser does not support them.'),
84-                       'l10n_print_after' => 'try{convertEntities(thickboxL10n);}catch(e){};'
85        ) );
86 
87 
88@@ -236,7 +232,6 @@
89                        'crunching' => __('Crunching&hellip;'),
90                        'deleted' => __('moved to the trash.'),
91                        'error_uploading' => __('&#8220;%s&#8221; has failed to upload due to an error'),
92-                       'l10n_print_after' => 'try{convertEntities(swfuploadL10n);}catch(e){};',
93        ) );
94 
95        $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", false, '20090102');
96@@ -256,7 +251,6 @@
97                'good' => _x('Medium', 'password strength'),
98                'strong' => __('Strong'),
99                'mismatch' => __('Mismatch'),
100-               'l10n_print_after' => 'try{convertEntities(pwsL10n);}catch(e){};'
101        ) );
102 
103        $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter' ), '20110113' );
104@@ -271,7 +265,6 @@
105                'save' => __('Add Link'),
106                'noTitle' => __('(no title)'),
107                'noMatchesFound' => __('No matches found.'),
108-               'l10n_print_after' => 'try{convertEntities(wpLinkL10n);}catch(e){};',
109        ) );
110 
111        $scripts->add( 'wpdialogs-popup', "/wp-includes/js/tinymce/plugins/wpdialogs/js/popup$suffix.js", array( 'jquery-ui-dialog' ), '20101119' );
112@@ -282,7 +275,6 @@
113                $scripts->localize( 'ajaxcat', 'catL10n', array(
114                        'add' => esc_attr(__('Add')),
115                        'how' => __('Separate multiple categories with commas.'),
116-                       'l10n_print_after' => 'try{convertEntities(catL10n);}catch(e){};'
117                ) );
118 
119                $scripts->add( 'admin-categories', "/wp-admin/js/categories$suffix.js", array('wp-lists'), '20091201' );
120@@ -293,7 +285,6 @@
121                $scripts->localize( 'admin-tags', 'tagsl10n', array(
122                        'noPerm' => __('You do not have permission to do that.'),
123                        'broken' => __('An unidentified error has occurred.'),
124-                       'l10n_print_after' => 'try{convertEntities(tagsl10n);}catch(e){};'
125                ));
126 
127                $scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20090106' );
128@@ -338,7 +329,6 @@
129                        'password' => __('Password Protected'),
130                        'privatelyPublished' => __('Privately Published'),
131                        'published' => __('Published'),
132-                       'l10n_print_after' => 'try{convertEntities(postL10n);}catch(e){};'
133                ) );
134 
135                $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array('wp-lists', 'postbox'), '20090526' );
136@@ -350,7 +340,6 @@
137                        'cancel' => __('Cancel'),
138                        'edit' => __('Edit'),
139                        'submittedOn' => __('Submitted on:'),
140-                       'l10n_print_after' => 'try{convertEntities(commentL10n);}catch(e){};'
141                ) );
142 
143                $scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ), '20090516' );
144@@ -365,7 +354,6 @@
145                $scripts->add_data( 'word-count', 'group', 1 );
146                $scripts->localize( 'word-count', 'wordCountL10n', array(
147                        'count' => __('Word count: %d'),
148-                       'l10n_print_after' => 'try{convertEntities(wordCountL10n);}catch(e){};'
149                ));
150 
151                $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'thickbox' ), '20110118' );
152@@ -380,14 +368,12 @@
153                        'error' => __('Error while saving the changes.'),
154                        'ntdeltitle' => __('Remove From Bulk Edit'),
155                        'notitle' => __('(no title)'),
156-                       'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
157                ) );
158 
159                $scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery' ), '20100615' );
160                $scripts->add_data( 'inline-edit-tax', 'group', 1 );
161                $scripts->localize( 'inline-edit-tax', 'inlineEditL10n', array(
162                        'error' => __('Error while saving the changes.'),
163-                       'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};'
164                ) );
165 
166                $scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'jquery', 'thickbox' ), '20110113' );
167@@ -395,7 +381,6 @@
168                $scripts->localize( 'plugin-install', 'plugininstallL10n', array(
169                        'plugin_information' => __('Plugin Information:'),
170                        'ays' => __('Are you sure you want to install this plugin?'),
171-                       'l10n_print_after' => 'try{convertEntities(plugininstallL10n);}catch(e){};'
172                ) );
173 
174                $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' );
175@@ -421,7 +406,6 @@
176                        'saving' => __( 'Saving...' ),
177                        'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ),
178                        'done' => __( 'Done' ),
179-                       'l10n_print_after' => 'try{convertEntities(setPostThumbnailL10n);}catch(e){};'
180                ) );
181 
182                // Navigation Menus
183@@ -430,7 +414,6 @@
184                        'noResultsFound' => _x('No results found.', 'search results'),
185                        'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ),
186                        'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'),
187-                       'l10n_print_after' => 'try{convertEntities(navMenuL10n);}catch(e){};'
188                ) );
189 
190                $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20101025' );
191@@ -554,7 +537,6 @@
192                'requestFile' => admin_url('admin-ajax.php'),
193                'savingText' => __('Saving Draft&#8230;'),
194                'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'),
195-               'l10n_print_after' => 'try{convertEntities(autosaveL10n);}catch(e){};'
196        ) );
197 
198 }