Idea for only loading specific i18n strings needed in a given view (wp.i18n) #6015
Closed
2 of 5 tasks
Labels
Gutenberg Plugin
Issues or PRs related to Gutenberg Plugin management related efforts
Internationalization (i18n)
Issues or PRs related to internationalization efforts
[Type] Build Tooling
Issues or PRs related to build tooling
Milestone
Issue Overview
The wp.i18n package has made some great progress towards easier i18n in js. However, as far as I know one downside still encountered is that regardless of what js is actually loaded for a given view, all translated strings for a given locale/domain will get queued up on
wp.i18n.setLocale
. This isn't too much of an issue when the number of strings is relatively small. But rapidly becomes an issue if on every page load using js, the entire locale data is enqueued for that page load.So I'd like to surface an idea of only enqueuing i18n strings that are specific to the js being used in a given view (see https://wordpress.slack.com/archives/C5UNMSU4R/p1522940224000403 where this was initially surfaced and some convo between me and @aduth about it)
chunk_name: [ ]
where the array is an array of i18n strings in that file.That way you’re only getting strings loaded on a view that are used in that view.
PHP side, it could be something as simple as:
This might register the chunk with a new i18n property on
WP_Scripts
? Then when scripts are enqueued there could be the retrieval of the registered strings, grab the locale data for those strings, then merge into the final object used for thewp.i18n.setLocaleData()
Related
wp-components
script handle to pass locale data towp.i18n
#5910Todos
The text was updated successfully, but these errors were encountered: