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