- How do I install and use this package in Laravel?
- Install via Composer with `composer require lorisleiva/cron-translator`. Use `CronTranslator::translate('* * * * *')` anywhere in your code. For Laravel services, bind it in a provider or inject directly. Works in Blade, APIs, and CLI.
- Does this support Laravel Task Scheduling cron syntax?
- Yes, it handles standard 5-field cron expressions (e.g., `* * * * *`). For extended syntax (e.g., `L`, `W`), validate input first or extend the package via PR. Pair with `spatie/cron-expression` for robust validation.
- Can I use this in Blade templates for admin dashboards?
- Absolutely. Embed it in Blade with `@php echo CronTranslator::translate($cronExpr) @endphp`. For performance, cache translations if used frequently in high-traffic dashboards.
- What locales are supported, and how do I add more?
- 18 locales are included (e.g., `en`, `fr`, `zh-TW`). Add missing locales by submitting a PR to the GitHub repo. For urgent needs, pre-process translations in your app layer.
- Will this work in Laravel APIs for JSON responses?
- Yes, it’s API-friendly. Use it to return human-readable cron descriptions in webhook docs or task schedules. Cache translations for identical cron expressions to avoid redundant parsing.
- Does it support 24-hour time formatting?
- Yes, pass `true` as the third argument to enforce 24-hour format: `CronTranslator::translate('30 18 * * *', 'fr', true)`. Defaults to 12-hour with AM/PM.
- What’s the performance impact of translating cron expressions?
- Translation is O(1) for simple cron, with negligible overhead. For complex expressions (e.g., `1,2 0 */2 1,2 *`), benchmark in production if used in hot paths like API responses.
- How do I handle invalid or unsupported cron syntax?
- Validate input cron expressions before translation (e.g., using `spatie/cron-expression`). Define a fallback message like `Invalid cron format` or log errors for debugging.
- Can I integrate this with Laravel’s service container?
- Yes, wrap it in a Laravel service provider for dependency injection (e.g., `app('cron-translator')`). This improves testability and maintainability in larger applications.
- What are the PHP version requirements?
- Requires PHP 8.2+. If using older PHP, fork the package or polyfill (though not recommended). The package leverages PHP 8.2+ features like strong typing.