[wp-trac] [WordPress Trac] #45103: Automatically load JavaScript translations when scripts are enqueued if these exist. (was: Automatically load JavaScript language packs when scripts are enqueued if these exist.)

WordPress Trac noreply at wordpress.org
Wed Oct 17 20:33:10 UTC 2018


#45103: Automatically load JavaScript translations when scripts are enqueued if
these exist.
-------------------------+-------------------------
 Reporter:  herregroen   |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  high         |   Milestone:  5.0
Component:  I18N         |     Version:  trunk
 Severity:  critical     |  Resolution:
 Keywords:  needs-patch  |     Focuses:  javascript
-------------------------+-------------------------
Changes (by ocean90):

 * focuses:   => javascript
 * severity:  normal => critical
 * priority:  normal => high
 * milestone:  Awaiting Review => 5.0


Old description:

> In order to support javascript language packs and allow these to be
> selectively loaded as described in
> https://meta.trac.wordpress.org/ticket/3875 WordPress should load
> language packs for a given JS file when that file is enqueued and the
> appropriate language pack exists.
>
> Language packs for JS files should be generated when
> https://meta.trac.wordpress.org/ticket/3876 is resolved. This will mean
> that there will be separate language packs for every JS file present.
>
> When a script is enqueued WordPress should check if a language pack for
> that specific script exists and, if so, use `wp_localize_script` to load
> all these translations. An additional script should also be added to then
> load these translation using `wp.i18n.setLocaleData` ( see
> [[https://github.com/WordPress/gutenberg/tree/master/packages/i18n|@wordpress/i18n]].
> Note that `setLocaleData` will only create a new `Jed` instance if none
> exist, otherwise the new domain will be merged into any existing domains
> ).
>
> Because we do not know in advance which domains a script uses we should
> load all domains for which files exist, likely using `glob` to find all
> language packs for the given filename and current locale ).
>
> Doing this would ensure that all translations a JS file uses are loaded
> into `wp.i18n` before that script is run and that only the translations
> that might possibly be used are loaded instead of every single
> translation.

New description:

 In order to support javascript translations and allow these to be
 selectively loaded as described in #Meta3875 WordPress should load
 translations for a given JS file when that file is enqueued and the
 appropriate language pack exists.

 Translations for JS files should be generated when #Meta3876 is resolved.
 This will mean that there will be separate language packs for every JS
 file present.

 When a script is enqueued WordPress should check if a translation file for
 that specific script exists and, if so, use `wp_localize_script` to load
 all these translations. An additional script should also be added to then
 load these translation using `wp.i18n.setLocaleData` ( see
 [[https://github.com/WordPress/gutenberg/tree/master/packages/i18n|@wordpress/i18n]].
 Note that `setLocaleData` will only create a new `Jed` instance if none
 exist, otherwise the new domain will be merged into any existing domains
 ).

 Because we do not know in advance which domains a script uses we should
 load all domains for which files exist, likely using `glob` to find all
 translation files for the given filename and current locale ).

 Doing this would ensure that all translations a JS file uses are loaded
 into `wp.i18n` before that script is run and that only the translations
 that might possibly be used are loaded instead of every single
 translation.

--

Comment:

 Moving to 5.0 since this is required for the new editor.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45103#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list