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

WordPress Trac noreply at wordpress.org
Thu Oct 18 11:29:53 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
-------------------------+-------------------------

Comment (by herregroen):

 Replying to [comment:1 swissspidy]:
 > > 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 ).
 >
 > -1
 >
 > We require developers to only use exactly one text domain in their
 projects, which is the plugin/theme slug.
 >
 > If they're not following that, they're `doing_it_wrong()`.

 Good point and agreed. In that case it's a matter of figuring out the
 originating plugin by the enqueued's script's path, and loading the
 appropriate file from there. There is the use case of premium plugins
 which bundle functionality of their free counterpart and have separate
 domains for translations from the free plugin and premium additions so I
 do believe this should be filterable.

 Replying to [comment:4 swissspidy]:
 > Note that with #meta3876 we'd get Jed-formatted JSON files (one JSON
 file per JS file). It would be way easier if we can just pass these files
 to setLocaleData() instead of doing some hacky things server-side to get
 different domains.

 Agreed. I think the ideal implementation would be basically @nerrad his
 function except it can perhaps take a file path directly and simply use
 `get_file_contents` instead of having to decode and then encode the json
 again.

 That just leaves automatically detecting if translation files exist for
 enqueued scripts I think.

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


More information about the wp-trac mailing list