-
Notifications
You must be signed in to change notification settings - Fork 1
Add optional secondary textdomain support to mki18n #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cartpauj
wants to merge
1
commit into
master
Choose a base branch
from
feature/multi-textdomain
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,81 @@ | ||
| #!/usr/bin/env php | ||
| <?php | ||
| $my_dir = (isset($argv[1]) && !empty($argv[1])) ? $argv[1] : 'i18n'; | ||
|
|
||
| if(!defined('STDIN')) { die("You're unauthorized to view this page."); } | ||
|
|
||
| if(!file_exists('./script/wp-script-config.php')) { die("Your script/wp-script-config.php file wasn't found."); } | ||
|
|
||
| include_once('./script/wp-script-config.php'); | ||
|
|
||
| $commands = array(); | ||
| $commands[] = 'find . -regex "^\.\/[^/]*\.php" -exec /usr/bin/env php ./script/i18n/add-textdomain.php -i \'' . WP_SCRIPT_TEXTDOMAIN . '\' {} \;'; | ||
| $commands[] = 'find . -regex "^\.\/app.*\.php" -exec /usr/bin/env php ./script/i18n/add-textdomain.php -i \'' . WP_SCRIPT_TEXTDOMAIN . '\' {} \;'; | ||
| $commands[] = '/usr/bin/env wp i18n make-pot . ./' . $my_dir . '/' . WP_SCRIPT_TEXTDOMAIN . '.pot'; | ||
| /** | ||
| * Run a single make-pot pass for a given textdomain. | ||
| * | ||
| * @param string $domain Textdomain to filter by. | ||
| * @param string $pot_dir Directory the .pot is written to (relative to plugin root). | ||
| * @param string $exclude Comma-separated --exclude value (empty to skip flag). | ||
| * @param string $include Comma-separated --include value (empty to skip flag). | ||
| * @param bool $auto_tag Whether to run add-textdomain.php first. Skipped automatically | ||
| * when a secondary domain is configured (ambiguous attribution). | ||
| */ | ||
| function wp_script_run_make_pot($domain, $pot_dir, $exclude, $include, $auto_tag) { | ||
| if (empty($domain)) { | ||
| echo "\n[skip] empty textdomain — pass not run\n"; | ||
| return; | ||
| } | ||
| if ($auto_tag) { | ||
| $cmds = array( | ||
| 'find . -regex "^\\./[^/]*\\.php" -exec /usr/bin/env php ./script/i18n/add-textdomain.php -i \'' . $domain . '\' {} \\;', | ||
| 'find . -regex "^\\./app.*\\.php" -exec /usr/bin/env php ./script/i18n/add-textdomain.php -i \'' . $domain . '\' {} \\;', | ||
| ); | ||
| foreach ($cmds as $c) { echo "\n\n$c\n"; system($c); sleep(1); } | ||
| } | ||
|
|
||
| foreach($commands as $command) { echo "\n\n$command\n"; system($command); sleep(1); } | ||
| $pot_path = './' . trim($pot_dir, '/') . '/' . $domain . '.pot'; | ||
|
|
||
| echo "\n\n"; | ||
| $flags = ' --slug=' . escapeshellarg($domain) . ' --domain=' . escapeshellarg($domain); | ||
| if (!empty($exclude)) { $flags .= ' --exclude=' . escapeshellarg($exclude); } | ||
| if (!empty($include)) { $flags .= ' --include=' . escapeshellarg($include); } | ||
|
|
||
| $cmd = '/usr/bin/env wp i18n make-pot . ' . escapeshellarg($pot_path) . $flags; | ||
| echo "\n\n$cmd\n"; | ||
| system($cmd); | ||
| } | ||
|
|
||
| // CLI override for the primary languages dir keeps the old `./mki18n my-dir` behavior. | ||
| $cli_dir = (isset($argv[1]) && !empty($argv[1])) ? $argv[1] : null; | ||
|
|
||
| $primary_dir = $cli_dir | ||
| ? $cli_dir | ||
| : (defined('WP_SCRIPT_LANGUAGES_DIR') && WP_SCRIPT_LANGUAGES_DIR ? WP_SCRIPT_LANGUAGES_DIR : 'i18n'); | ||
|
|
||
| $primary_exclude = defined('WP_SCRIPT_EXCLUDE') ? WP_SCRIPT_EXCLUDE : ''; | ||
| $primary_include = defined('WP_SCRIPT_INCLUDE') ? WP_SCRIPT_INCLUDE : ''; | ||
|
|
||
| $has_secondary = defined('WP_SCRIPT_TEXTDOMAIN_2') && !empty(WP_SCRIPT_TEXTDOMAIN_2); | ||
|
|
||
| // Auto-tagging is only safe for single-domain projects. With two domains | ||
| // configured we cannot infer which one an untagged call should get. | ||
| $auto_tag = !$has_secondary; | ||
|
|
||
| wp_script_run_make_pot( | ||
| WP_SCRIPT_TEXTDOMAIN, | ||
| $primary_dir, | ||
| $primary_exclude, | ||
| $primary_include, | ||
| $auto_tag | ||
| ); | ||
|
|
||
| if ($has_secondary) { | ||
| $secondary_dir = defined('WP_SCRIPT_LANGUAGES_DIR_2') && WP_SCRIPT_LANGUAGES_DIR_2 ? WP_SCRIPT_LANGUAGES_DIR_2 : 'i18n'; | ||
| $secondary_exclude = defined('WP_SCRIPT_EXCLUDE_2') ? WP_SCRIPT_EXCLUDE_2 : ''; | ||
| $secondary_include = defined('WP_SCRIPT_INCLUDE_2') ? WP_SCRIPT_INCLUDE_2 : ''; | ||
|
|
||
| wp_script_run_make_pot( | ||
| WP_SCRIPT_TEXTDOMAIN_2, | ||
| $secondary_dir, | ||
| $secondary_exclude, | ||
| $secondary_include, | ||
| false | ||
| ); | ||
| } | ||
|
|
||
| echo "\n\n"; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,44 @@ | ||
| <?php | ||
| if(!defined('STDIN')) { die("You're unauthorized to view this page."); } | ||
|
|
||
| // ===== Required ===== | ||
| // Primary textdomain — used by mki18n, deploy, etc. | ||
| define('WP_SCRIPT_TEXTDOMAIN',''); | ||
|
|
||
| // ===== Optional: i18n customization ===== | ||
| // Directory where the .pot is written for the primary textdomain. | ||
| // Defaults to 'i18n' (back-compat). Common modern choice: 'languages'. | ||
| // If you pass a directory name as the first CLI arg to mki18n, that wins | ||
| // over this constant. | ||
| // define('WP_SCRIPT_LANGUAGES_DIR', 'languages'); | ||
|
|
||
| // Comma-separated paths to exclude from the primary scan. | ||
| // Mirrors `wp i18n make-pot --exclude=...`. | ||
| // Default (when undefined): nothing extra is excluded. | ||
| // define('WP_SCRIPT_EXCLUDE', 'pro,vendor,vendor-prefixed,node_modules,assets,tests,docs,bin'); | ||
|
|
||
| // Comma-separated paths to restrict the primary scan to. | ||
| // Mirrors `wp i18n make-pot --include=...`. Usually unnecessary for a | ||
| // single-domain plugin; leave undefined to scan everything not excluded. | ||
| // define('WP_SCRIPT_INCLUDE', ''); | ||
|
|
||
| // ===== Optional: secondary textdomain (e.g. Pro add-on bundled in same repo) ===== | ||
| // Define WP_SCRIPT_TEXTDOMAIN_2 to a non-empty string to make mki18n run a | ||
| // second pass with this domain. Each `_2` constant mirrors its primary | ||
| // counterpart. If WP_SCRIPT_TEXTDOMAIN_2 is undefined or empty, the second | ||
| // pass is skipped — single-domain projects are unaffected. | ||
| // | ||
| // NOTE: when a secondary domain is configured, the auto-tag step | ||
| // (add-textdomain.php) is skipped, since auto-tagging cannot tell which | ||
| // domain an untagged string should belong to. Two-domain plugins must | ||
| // tag every gettext call explicitly. | ||
| // define('WP_SCRIPT_TEXTDOMAIN_2', ''); | ||
| // define('WP_SCRIPT_LANGUAGES_DIR_2', ''); | ||
| // define('WP_SCRIPT_EXCLUDE_2', ''); | ||
| // define('WP_SCRIPT_INCLUDE_2', ''); | ||
|
|
||
| // ===== Mothership / deploy ===== | ||
| define('MY_PLUGIN_MAIN_FILE', 'main.php'); | ||
| define('MOTHERSHIP_URL',''); | ||
| define('MOTHERSHIP_API_KEY',''); | ||
| define('MOTHERSHIP_PROJECT_ID',''); | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.