From 1dc9f7f297cc90d24941a29ab6834b15e7f75610 Mon Sep 17 00:00:00 2001 From: cartpauj Date: Sat, 25 Apr 2026 00:19:29 -0600 Subject: [PATCH] Add optional secondary textdomain support to mki18n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plugins that bundle a Pro add-on (or any second textdomain) inside the same repo can now define optional WP_SCRIPT_TEXTDOMAIN_2 plus matching LANGUAGES_DIR_2 / EXCLUDE_2 / INCLUDE_2 constants. When set, mki18n runs a second `wp i18n make-pot` pass scoped to its own subtree and filtered to its own domain. Single-domain projects are unaffected — every new constant is gated behind defined() and falls through to the original behavior. Also exposes WP_SCRIPT_LANGUAGES_DIR / EXCLUDE / INCLUDE for the primary domain so callers can avoid the legacy `i18n/` default and pass scoping flags from config rather than CLI. The auto-tag step (add-textdomain.php) is skipped when a secondary domain is configured: an untagged call cannot be unambiguously assigned to either domain, so two-domain plugins must tag every gettext call explicitly. Co-Authored-By: Claude Opus 4.7 (1M context) --- README.md | 31 ++++++++++++++- mki18n | 78 +++++++++++++++++++++++++++++++++---- wp-script-config.sample.php | 37 +++++++++++++++++- 3 files changed, 136 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5534c01..d7abd85 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,37 @@ And ./script/mki18n find . -regex "^\.\/[^/]*\.php" -exec /usr/bin/env php ./script/i18n/add-textdomain.php -i 'memberpress' {} \; find . -regex "^\.\/app.*\.php" -exec /usr/bin/env php ./script/i18n/add-textdomain.php -i 'memberpress' {} \; -/usr/bin/env php ./script/i18n/makepot.php wp-plugin . ./i18n/memberpress.pot +/usr/bin/env wp i18n make-pot . ./i18n/memberpress.pot --slug=memberpress --domain=memberpress ``` + +`wp i18n make-pot` extracts strings from PHP **and** JS/JSX/TSX in one pass, +so JavaScript `__('text', 'my-domain')` calls are picked up automatically. + +### Multiple textdomains in one project + +For projects that bundle a Pro add-on (or any second textdomain) inside the +same repo, define the optional `_2` constants in `wp-script-config.php`: + +``` +define('WP_SCRIPT_TEXTDOMAIN', 'my-plugin'); +define('WP_SCRIPT_LANGUAGES_DIR', 'languages'); +define('WP_SCRIPT_EXCLUDE', 'pro,vendor,vendor-prefixed,node_modules,assets,tests,docs,bin'); + +define('WP_SCRIPT_TEXTDOMAIN_2', 'my-plugin-pro'); +define('WP_SCRIPT_LANGUAGES_DIR_2', 'pro/languages'); +define('WP_SCRIPT_INCLUDE_2', 'pro'); +define('WP_SCRIPT_EXCLUDE_2', 'pro/vendor,pro/vendor-prefixed,pro/node_modules,pro/assets'); +``` + +`mki18n` will then run two passes — `./languages/my-plugin.pot` and +`./pro/languages/my-plugin-pro.pot` — each scoped to its own subtree and +filtered to its own textdomain. Single-domain projects that don't define +`WP_SCRIPT_TEXTDOMAIN_2` get the original behavior unchanged. + +The auto-tag step (`add-textdomain.php`) is skipped when a secondary domain +is configured, since an untagged call can't be unambiguously assigned to +either domain. Two-domain projects must tag every gettext call explicitly. + And (if you have a mothership project associated with this git repo) ``` diff --git a/mki18n b/mki18n index a8f0e09..9630146 100755 --- a/mki18n +++ b/mki18n @@ -1,19 +1,81 @@ #!/usr/bin/env php