- How do I install and use lorisleiva/cron-translator in a Laravel app?
- Install it with composer require lorisleiva/cron-translator. Then call CronTranslator::translate('30 22 * * *') to get output such as Every day at 10:30pm. No service provider, migrations, or runtime infrastructure are required. Wrap the static call in your own service if you want easier testing and central fallback behavior.
- Which Laravel and PHP versions does cron-translator support?
- cron-translator is a framework-agnostic PHP package, so it does not require a specific Laravel version or a service provider. It fits Laravel applications running modern PHP, and the TPM assessment recommends PHP 8.2+ with a pinned 0.x version. Because the package is 0.x, test upgrades and check PHP compatibility before updating.
- Does cron-translator support all CRON expressions, including L, W, ?, and seconds fields?
- It handles standard 5-part cron expressions with ranges, steps, and lists. It does not support special operators such as L, W, or ?, nor seconds fields or every cron dialect. Validate expressions before translation and provide a fallback for unsupported input.
- How do I translate a cron expression into a specific language or locale?
- Pass the locale as the second argument, for example CronTranslator::translate('30 18 * * *', 'fr'). Supported locales include en, fr, de, es, pt, ru, zh, zh-TW, and others, for 20 total. Map your application locales explicitly and keep en as a fallback; note codes such as ua for Ukrainian and zh-TW for Traditional Chinese.
- How can I show cron descriptions in 24-hour time format?
- Pass true as the third argument: CronTranslator::translate('30 18 * * *', 'fr', true) returns Chaque jour à 18:30. Without it, the default is 12-hour formatting with am/pm. Drive this flag from the user or tenant preference instead of hard-coding it.
- Does cron-translator handle timezones when describing schedules?
- No. The translator only describes the cron pattern, not when it will run in a given timezone. Treat timezone as a separate display concern and show it alongside the translated description. Do not expect the package to convert or interpret regional time.
- What happens if cron-translator receives an invalid or unsupported expression?
- Invalid or unsupported expressions may throw an exception or produce awkward output. Validate cron expressions with Laravel's validator before calling the translator, and catch failures in your wrapper. Return the raw expression or a generic fallback in the UI so support can still inspect the schedule.
- Is lorisleiva/cron-translator safe to use in production?
- It is a small, MIT-licensed, community-maintained package suitable for presentation-layer cron display. It is not a high-assurance scheduling component and should not replace Laravel's scheduler or validation. Pin the 0.x version, test upgrades, and keep the raw expression visible next to the translated text.
- Can I use cron-translator to generate cron expressions or convert natural language to cron?
- No. The package only translates existing cron expressions into human-readable text. It does not generate cron expressions, parse natural language, or validate schedules as a primary control. Use Laravel's scheduler and validation for those responsibilities.
- How should I test cron-translator output in a Laravel application?
- Wrap CronTranslator::translate in an application-owned service and assert its output for your supported expressions and locales. Include tests for fallback behavior on invalid or unsupported expressions and for 24-hour formatting. Avoid asserting exact translated strings for every locale unless your team reviews that copy.