Skip to content

Comments

Added localization for translated cron-string#168

Merged
Chris53897 merged 5 commits intoDukecity:mainfrom
knallcharge:master
Feb 9, 2026
Merged

Added localization for translated cron-string#168
Chris53897 merged 5 commits intoDukecity:mainfrom
knallcharge:master

Conversation

@knallcharge
Copy link

@knallcharge knallcharge commented Feb 6, 2026

I added the default values for locale (en) and 24h time format (false) to the Entity and the locale from the request in the template. If you overwrite your template, you can also set the time format.

I also bumped to the latest version of lorisleiva/cron-translator

(CodeRabbit now complains that the composer-constraint is not valid, but version 0.5 is available ... ?
https://packagist.org/packages/lorisleiva/cron-translator#v0.5.0)

Summary by CodeRabbit

  • New Features

    • Cron expression translations now respect the current application locale and support choosing 12/24-hour time formats.
    • Cron tooltips will display translations in the user's locale.
  • Chores

    • Updated cron-translator dependency to a version with improved localization support.

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

Adds locale and 24-hour time-format options to cron translation: the interface and BaseScheduledCommand method signatures now accept locale and timeFormat24hours; the Twig list template passes the current request locale; the lorisleiva/cron-translator dependency is bumped to ^0.5.0.

Changes

Cohort / File(s) Summary
Method Signature Enhancement
Entity/BaseScheduledCommand.php, Entity/ScheduledCommandInterface.php
getCronExpressionTranslated() signature updated to getCronExpressionTranslated(string $locale = 'en', bool $timeFormat24hours = false): string; implementation forwards both args to CronTranslator::translate().
Template Locale Integration
Resources/views/List/index.html.twig
Twig template changed to call getCronExpressionTranslated(app.request.locale) so translation uses the current request locale.
Dependency Update
composer.json
Bumped lorisleiva/cron-translator from ^0.4.6 to ^0.5.0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble cron lines in the night,
I learn each locale to get them right,
With twenty-four ticks or AM/PM play,
I translate schedules so they hop your way.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—adding localization support to the cron expression translation method through new locale and time format parameters.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.66%. Comparing base (90e4db4) to head (743dad2).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #168   +/-   ##
=========================================
  Coverage     84.66%   84.66%           
  Complexity      329      329           
=========================================
  Files            33       33           
  Lines          1337     1337           
=========================================
  Hits           1132     1132           
  Misses          205      205           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Entity/BaseScheduledCommand.php (1)

329-336: ⚠️ Potential issue | 🟡 Minor

Update ScheduledCommandInterface to match the implementation signature.

The interface at Entity/ScheduledCommandInterface.php:89 declares getCronExpressionTranslated(): string without the $locale and $timeFormat24hours parameters that the implementation in BaseScheduledCommand.php:329 now includes. While PHP allows optional parameters in implementations beyond the interface, callers typed against the interface cannot pass locale or time-format arguments. Update the interface to maintain consistency:

public function getCronExpressionTranslated(string $locale = 'en', bool $timeFormat24hours = false): string;

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@Entity/ScheduledCommandInterface.php`:
- Line 89: Update the composer constraint for lorisleiva/cron-translator so
Composer can install it: replace the non-existent "^0.5.0" constraint with a
valid released version (e.g. "^0.4.6") in composer.json, then run composer
update; the interface method getCronExpressionTranslated(string $locale = 'en',
bool $timeFormat24hours = false) and BaseScheduledCommand already match the
library API so no other code changes are needed.

public function getNextRunDate(bool $checkExecuteImmediately = true): ?DateTime;

public function getCronExpressionTranslated(): string;
public function getCronExpressionTranslated(string $locale = 'en', bool $timeFormat24hours = false): string;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find all classes implementing ScheduledCommandInterface
echo "=== Implementations of ScheduledCommandInterface ==="
rg -n 'implements\s+ScheduledCommandInterface' --type=php

echo ""
echo "=== Classes extending BaseScheduledCommand ==="
rg -n 'extends\s+BaseScheduledCommand' --type=php

Repository: Dukecity/CommandSchedulerBundle

Length of output: 475


🌐 Web query:

lorisleiva/cron-translator version 0.5.0 translate method signature API

💡 Result:

I couldn’t find any lorisleiva/cron-translator v0.5.0 release/tag on Packagist or in the GitHub releases list (latest shown there is v0.4.6, released June 25, 2025). [1]

For the currently documented API, CronTranslator::translate is a static method that takes:

CronTranslator::translate(string $expression, string $locale = 'en', bool $use24HourTime = false): string
  • 1st arg: cron expression
  • 2nd arg (optional): locale (e.g. 'fr')
  • 3rd arg (optional): use 24-hour time formatting (true/false) [2]

Sources: [1] [2]


🏁 Script executed:

#!/bin/bash
# Check the actual CronTranslator call in BaseScheduledCommand
echo "=== BaseScheduledCommand getCronExpressionTranslated implementation ==="
sed -n '320,340p' Entity/BaseScheduledCommand.php

echo ""
echo "=== Composer dependency for cron-translator ==="
rg -A2 -B2 'cron-translator' composer.json

Repository: Dukecity/CommandSchedulerBundle

Length of output: 994


Dependency version constraint ^0.5.0 for lorisleiva/cron-translator does not exist and will cause composer to fail.

The interface signature change itself is correct and consistent with BaseScheduledCommand, which properly forwards the new optional parameters to CronTranslator::translate(). The parameter order (expression, locale, use24HourTime) matches the library's API.

However, composer.json specifies "lorisleiva/cron-translator": "^0.5.0", but v0.5.0 has never been released. The latest available version is v0.4.6 (June 25, 2025). The constraint ^0.5.0 must be corrected to ^0.4.6 or higher if a newer version becomes available.

No other implementations of ScheduledCommandInterface exist in the codebase that require updating — only BaseScheduledCommand implements it, and its signature already matches.

🤖 Prompt for AI Agents
In `@Entity/ScheduledCommandInterface.php` at line 89, Update the composer
constraint for lorisleiva/cron-translator so Composer can install it: replace
the non-existent "^0.5.0" constraint with a valid released version (e.g.
"^0.4.6") in composer.json, then run composer update; the interface method
getCronExpressionTranslated(string $locale = 'en', bool $timeFormat24hours =
false) and BaseScheduledCommand already match the library API so no other code
changes are needed.

@Chris53897
Copy link
Collaborator

Thanks.
I think this does count as a BC break, but not many users are effected i guess.
Did you test it in a real application? Do you need to make changes to your userland code?

@Chris53897
Copy link
Collaborator

I did update lorisleiva/cron-translator in another PR before i did see your PR.

@knallcharge
Copy link
Author

knallcharge commented Feb 6, 2026

I tested the changes in a real application and it worked as expected. I'm overwriting the templates in my application, so the only change I needed to make was to provide the parameters, but as the changed translate()-function uses defaults, this should work for anyone, even if they overwrite the templates.
What makes you think the changes are a BC break? (Unless the "break" would be that people are suddenly seeing the cron-string unexpectedly translated. - I could remove the change in the template in that case and leave it to the users to decide whether they want the string translated. But I'd assume that nobody notices the possibility :))

@Chris53897
Copy link
Collaborator

Adding paramters to a method in an Interface, looks like a BC Break to me.

What version of symfony and PHP do you use?
I am thinink about making a new release with symfony >= 8 and PHP >= 8.4 only

@knallcharge
Copy link
Author

Adding paramters to a method in an Interface, looks like a BC Break to me.

Even if defaults are provided? 🤔

What version of symfony and PHP do you use?

PHP 8.5.1, Symfony 8.0.5

I am thinink about making a new release with symfony >= 8 and PHP >= 8.4 only

That's probably a good idea. Do you want me to remove the template-change from my PR so users can decide whether they want the text translated?

@Chris53897 Chris53897 mentioned this pull request Feb 9, 2026
10 tasks
@Chris53897
Copy link
Collaborator

I guess now changes are needed at this PR for now.
My actual plan is described here.
#171

@Chris53897 Chris53897 merged commit 06ba9b8 into Dukecity:main Feb 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants