Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Language Command Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require wp-cli/language-command
    

    Ensure WP-CLI is installed globally (wp --version) and your WordPress environment is accessible.

  2. First Use Case: Install a core language pack (e.g., Dutch):

    wp language core install nl_NL
    
  3. Verify Installation:

    wp language core list --fields=language,status
    

Where to Look First

  • Command Reference: Focus on wp language core, wp language plugin, and wp language theme subcommands.
  • Examples: The README provides clear examples for installation, activation, and listing.
  • WordPress Translation Hub: translate.wordpress.org for language codes.

Implementation Patterns

Usage Patterns

  1. Bulk Language Management:

    # Install multiple languages for a plugin
    wp language plugin install hello-dolly --all fr_FR es_ES
    
  2. Automated Updates:

    # Dry-run update for all plugins
    wp language plugin update --all --dry-run --format=json | jq '.[] | select(.update == "available")'
    
  3. 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
    
  4. 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");
    }
    
  5. 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);
    }
    

Workflows

  1. Local Development:

    • Use --dry-run to preview updates before applying them.
    • Test language packs in a staging environment before production.
  2. CI/CD Pipelines:

    • Automate language pack updates in deployment scripts:
      wp language core update --format=json > updates.json
      wp language plugin update --all --format=json >> updates.json
      
  3. Multisite Management:

    # Install language for all sites in a network
    wp language core install nl_NL --network
    

Integration Tips

  • 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.");
    }
    

Gotchas and Tips

Pitfalls

  1. Deprecated Commands:

    • Avoid wp language core activate (use wp site switch-language instead).
    • Check for deprecated commands in the changelog.
  2. Network vs. Single-Site:

    • Commands like wp language core install may behave differently in multisite vs. single-site. Test thoroughly.
  3. Permissions:

    • Ensure WP-CLI has write permissions to wp-content/languages/:
      chmod -R 755 wp-content/languages/
      
  4. Language Code Format:

  5. Plugin/Theme Compatibility:

    • Not all plugins/themes support language packs. Test with your specific stack.

Debugging

  1. Verbose Output: Enable verbose mode for troubleshooting:

    WP_CLI_VERBOSE=1 wp language core install nl_NL
    
  2. Dry-Runs: Use --dry-run to preview updates without applying changes:

    wp language plugin update --all --dry-run
    
  3. Logging: Redirect output to a log file for debugging:

    wp language core update 2>&1 | tee update.log
    
  4. 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).

Tips

  1. Batch Processing: Use --format=json for programmatic parsing:

    wp language plugin list --all --format=json | jq '.[] | select(.status == "uninstalled")'
    
  2. 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
    
  3. 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/
    
  4. Performance:

    • Install only necessary languages to reduce overhead.
    • Use --fields to limit output for faster processing:
      wp language core list --fields=language,status --format=csv
      
  5. Extension Points:

    • Override default behavior by extending the package (e.g., custom download sources).
    • Hook into WP-CLI events for pre/post-installation logic.
  6. Testing:

    • Use Behat for acceptance testing:
      composer behat
      
    • Mock HTTP requests to test offline scenarios:
      wp language core install nl_NL --path=/mock/translations/
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky