Autoloader: use the wp-textdomain npm package to update package textdomains #18003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We need to provide a way for a consuming plugin to use its own textdomain in the package strings. This PR presents a possible solution which uses the wp-textdomain NPM package to detect translatable strings and change them to a given textdomain.
How a Consumer Plugin Would Use This
Add the jetpack-autoloader package to the plugin's composer dependencies in
composer.json
. (All plugins that use Jetpack packages should use the autoloader package to load package files.)Add a composer script to the plugins's
composer.json
file, with the plugin's textdomain as the first argument:"post-autoload-dump": "node vendor/automattic/jetpack-autoloader/js/update_textdomain.js {textdomain}"
Add
wp-textdomain
as a development dependency in the plugin'spackage.json
file.When the plugin is built with
composer install
,composer update
orcomposer dump-autoload
, the post autoload dump script will run. The script will update every textdomain in the .php files in the Automattic packages.Changes proposed in this Pull Request:
Add
wp-textdomain
to Jetpack's development dependencies inpackage.json
.Add a new file to the autoloader package,
update_textdomain.js
, which useswp-textdomain
to detect and update the textdomain of package strings.Why is this in the autoloader package?
I put this in the autoloader package because:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
Add the composer script to
composer.json
. Enter a textdomain that's notjetpack
so you can verify that the script worked."post-autoload-dump": "node vendor/automattic/jetpack-autoloader/js/update_textdomain.js {textdomain}"
Run
composer dump-autoload
. The textdomain for the translatable strings in the composer packages should be changed fromjetpack
to the string used in step 1.Proposed changelog entry for your changes: