- How do I install Laravel Lang Publisher for a Laravel 11 project?
- Run `composer require --dev laravel-lang/publisher` in your project directory. The package is designed as a dev dependency and integrates seamlessly with Laravel’s existing localization system. No additional configuration is needed for basic usage.
- Can I publish only specific translation files (e.g., auth or validation) without overwriting everything?
- Yes, use the `--only` flag with the `lang:publish` command. For example, `php artisan lang:publish --only=auth,validation` will only publish those files. This is useful for partial adoption or customization.
- Does Laravel Lang Publisher support custom translation file structures (e.g., nested directories like `resources/lang/{locale}/messages/{context}.php`)?
- Yes, the package preserves nested arrays and subkeys in custom file structures since version 16.7.0. Just ensure your files follow Laravel’s JSON-compatible format, and the publisher will handle the rest without flattening the hierarchy.
- What happens if I run `lang:publish` and there are conflicting keys between my existing translations and the published files?
- By default, the publisher skips conflicts to avoid overwriting your custom translations. Use the `--force` flag to overwrite existing files, but test this cautiously in a staging environment first to avoid unintended data loss.
- Is Laravel Lang Publisher compatible with Lumen or non-Laravel PHP projects?
- The package is Laravel-specific and designed for Laravel 10–13. For Lumen, you’ll need to manually define `lang_path()` in your `bootstrap/app.php` (supported in Lumen 14.4.0+). Non-Laravel projects (e.g., Symfony) are not directly supported due to reliance on Laravel’s translation service provider.
- How can I customize or extend the publisher’s behavior, such as adding pre-publish validation?
- Leverage Laravel’s event system to listen for `lang.publishing` or `lang.published` events in a service provider. You can also override published files post-publish using scripts or the `--force` flag. For advanced use cases, extend the `PublisherServiceProvider` class.
- Will this package slow down my CI/CD pipeline if I publish translations on every deploy?
- The publisher is lightweight and optimized for CLI use, but publishing many locales (e.g., 20+) may introduce minor delays. For CI/CD, consider running it only during feature releases or caching published files to avoid redundant operations.
- Does Laravel Lang Publisher work with non-JSON translation files (e.g., `.po` or `.xlf`)?
- No, the package is designed for JSON-based translation files (`.php` arrays in Laravel’s `resources/lang/` structure). If you’re using `.po` or `.xlf`, you’ll need to convert them to JSON first or use a dedicated localization tool.
- How do I set a default locale for the publisher if my app uses dynamic locales?
- Use the `LANG_PUBLISHER_DEFAULT_LOCALE` environment variable in your `.env` file. This allows runtime adjustments, such as `LANG_PUBLISHER_DEFAULT_LOCALE=en_US`, while still supporting dynamic locale switching in your app via `config('app.locale')`.
- Are there alternatives to Laravel Lang Publisher for managing Laravel translations?
- For basic translation management, Laravel’s built-in `lang` publish command suffices. However, Laravel Lang Publisher offers deeper integration with the Laravel-Lang ecosystem (e.g., locales, fallback logic) and supports partial publishing. Alternatives like `spatie/laravel-translatable` focus on database-driven translations, not file-based publishing.