wp-cli/language-command
WP-CLI language-command installs, updates, lists, and manages WordPress language packs for core, themes, and plugins. Download and activate translations (e.g., nl_NL) from the command line, including site language switching and language pack maintenance.
Installation:
composer require wp-cli/language-command
Ensure WP-CLI is installed globally (wp --version) and your WordPress environment is accessible.
First Use Case: Install a core language pack (e.g., Dutch):
wp language core install nl_NL
Verify Installation:
wp language core list --fields=language,status
wp language core, wp language plugin, and wp language theme subcommands.Bulk Language Management:
# Install multiple languages for a plugin
wp language plugin install hello-dolly --all fr_FR es_ES
Automated Updates:
# Dry-run update for all plugins
wp language plugin update --all --dry-run --format=json | jq '.[] | select(.update == "available")'
Integration with Deployment Scripts:
# Install and activate language packs during deployment
wp language core install nl_NL --activate
wp language plugin install akismet nl_NL
Conditional Logic in Laravel:
// Check if a language is installed (e.g., in a service provider)
$installed = shell_exec("wp language core is-installed nl_NL") === '0';
if (!$installed) {
shell_exec("wp language core install nl_NL");
}
Dynamic Language Switching:
// Laravel route middleware to switch language
public function handle(Request $request, Closure $next) {
$locale = $request->header('Accept-Language') ?? 'en_US';
shell_exec("wp site switch-language {$locale}");
return $next($request);
}
Local Development:
--dry-run to preview updates before applying them.CI/CD Pipelines:
wp language core update --format=json > updates.json
wp language plugin update --all --format=json >> updates.json
Multisite Management:
# Install language for all sites in a network
wp language core install nl_NL --network
Laravel Artisan Commands:
Create a custom Artisan command to wrap wp-cli language commands:
// app/Console/Commands/InstallLanguage.php
public function handle() {
$language = $this->ask('Language code (e.g., fr_FR)');
shell_exec("wp language core install {$language}");
}
WP-CLI Aliases:
Add aliases to your ~/.wp-cli/config.yml for frequently used commands:
aliases:
install-lang: 'language core install'
update-all: 'language plugin update --all'
Error Handling: Validate language codes before execution:
$validCodes = ['en_US', 'fr_FR', 'es_ES']; // Predefined list
if (!in_array($language, $validCodes)) {
throw new \InvalidArgumentException("Invalid language code.");
}
Deprecated Commands:
wp language core activate (use wp site switch-language instead).Network vs. Single-Site:
wp language core install may behave differently in multisite vs. single-site. Test thoroughly.Permissions:
wp-content/languages/:
chmod -R 755 wp-content/languages/
Language Code Format:
locale format (e.g., nl_NL, not nl). Refer to WordPress Translation Hub for valid codes.Plugin/Theme Compatibility:
Verbose Output: Enable verbose mode for troubleshooting:
WP_CLI_VERBOSE=1 wp language core install nl_NL
Dry-Runs:
Use --dry-run to preview updates without applying changes:
wp language plugin update --all --dry-run
Logging: Redirect output to a log file for debugging:
wp language core update 2>&1 | tee update.log
Common Errors:
Translation not found: Verify the language code and plugin/theme version.Permission denied: Check file permissions for wp-content/languages/.Invalid command: Ensure WP-CLI is up-to-date (wp cli update).Batch Processing:
Use --format=json for programmatic parsing:
wp language plugin list --all --format=json | jq '.[] | select(.status == "uninstalled")'
Automate Updates:
Schedule regular updates via cron:
# Update core languages weekly
0 0 * * 0 wp language core update --format=summary >> /var/log/wp-language-updates.log
Custom Language Packs:
For non-WordPress.org translations, use the --path option (if supported in future versions):
wp language plugin install my-plugin nl_NL --path=/custom/translations/
Performance:
--fields to limit output for faster processing:
wp language core list --fields=language,status --format=csv
Extension Points:
Testing:
composer behat
wp language core install nl_NL --path=/mock/translations/
How can I help you explore Laravel packages today?