[wp-trac] [WordPress Trac] #55250: Avoid sending empty script translations

WordPress Trac noreply at wordpress.org
Thu Feb 24 16:20:38 UTC 2022


#55250: Avoid sending empty script translations
--------------------------+-----------------------------
 Reporter:  jsnajdr       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  I18N          |    Version:  5.9
 Severity:  normal        |   Keywords:  has-patch
  Focuses:                |
--------------------------+-----------------------------
 For every JS script enqueued, we generate an empty-ish translations script
 that doesn't add any translations:
 {{{
 <script id='react-js-translations'>
 ( function( domain, translations ) {
   var localeData = translations.locale_data[ domain ] ||
 translations.locale_data.messages;
   localeData[""].domain = domain;
   wp.i18n.setLocaleData( localeData, domain );
 }  )( "default", { "locale_data": { "messages": { "": {} } } } );
 </script>
 }}}
 The only reason for that is to ensure that the `wp.i18n` library has a
 record for the domain in question (here `"default"`). But the `wp.i18n`
 library doesn't need that for `__( 'foo', 'domain' )` to work, and it
 never needed.

 There might have been some confusion about the Jed library, whose
 `gettext` methods really would throw an exception if the domain wasn't
 initialized, but 1) `wp.i18n` always caught the exception and returned the
 original string intact, and 2) it's been using `tannin` instead of Jed for
 close to 4 years.

 This patch removes these redundant scripts. On a big page (like `wp-
 admin/post.php` for block editor on a site with many plugins), there would
 be around 90 of them.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55250>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list