- How do I install and use Cron Translator in a Laravel project?
- Run `composer require lorisleiva/cron-translator` to install. Use the static method `CronTranslator::translate('* * * * *')` directly or bind it as a singleton in `AppServiceProvider` for Laravel’s container. No configuration is needed for basic usage.
- Does this package support Laravel’s localization system (e.g., `App::getLocale()`)?
- Yes. Pass the locale as a second argument: `CronTranslator::translate('0 12 * * *', 'fr')` for French. It integrates with Laravel’s i18n ecosystem and supports 18+ locales out of the box.
- Can I use 24-hour time formatting for cron translations?
- Absolutely. Add a third boolean argument: `CronTranslator::translate('30 18 * * *', 'en', true)` forces 24-hour format (e.g., `18:30`). Defaults to 12-hour for most locales.
- What Laravel versions and PHP versions are supported?
- The package requires **PHP 8.2+** and is optimized for **Laravel 9+**. It’s stateless and dependency-free, so it won’t conflict with older Laravel versions, but some features (like facades) assume Laravel’s service container.
- How can I integrate this into Laravel’s Artisan commands or middleware?
- Bind the translator as a singleton in `AppServiceProvider` and inject it into commands or middleware. For example, create a `cron:translate` Artisan command to debug cron expressions in CLI: `php artisan cron:translate '0 * * * *'`.
- Does Cron Translator handle extended cron syntax (e.g., `@yearly`, `L`, `W`)?
- No. It supports **standard 5-part cron syntax** (minute, hour, day, month, weekday). For extended syntax, pre-process expressions (e.g., convert `@yearly` to `0 0 1 1 *`) or use a custom wrapper to handle unsupported patterns.
- Is there a performance impact when translating cron expressions in hot paths (e.g., API responses)?
- Translation is **O(1) for simple cron** and typically adds **<1ms** even for complex expressions. For high-frequency use (e.g., API responses), cache results with Laravel’s `Cache::remember()` to avoid repeated parsing.
- How can I contribute missing translations or fix locale issues?
- Check the [GitHub repository](https://github.com/lorisleiva/cron-translator) for contribution guidelines. Submit a PR with updated locale files or open an issue to report inconsistencies. The package welcomes community-driven localization.
- Can I use this package in non-Laravel PHP projects?
- Yes. It’s a **standalone utility** with no Laravel dependencies. Use `require 'vendor/autoload.php'` and call `CronTranslator::translate()` directly. However, Laravel-specific features (like facades or service binding) won’t work outside Laravel.
- Are there alternatives to Cron Translator for Laravel?
- For basic cron translation, alternatives include `spatie/cron-expression` (focused on parsing) or custom solutions using `DateTime` logic. However, Cron Translator uniquely combines **human-readable output**, **multi-language support**, and **Laravel-native integration** in a single package.