Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pluralization not being used for duration translations #183

Merged
merged 1 commit into from
Jul 31, 2023

Conversation

kbond
Copy link
Contributor

@kbond kbond commented Jul 31, 2023

Pluralization is not being triggered for the new duration translations:

{{ 1|duration }} {# 1 second|%count% seconds #}
{{ 2|duration }} {# 2 seconds #}

I can't immediately see the issue...

@weaverryan
Copy link
Collaborator

You mean it's literally outputting 1 second|%count% seconds?

@kbond
Copy link
Contributor Author

kbond commented Jul 31, 2023

You mean it's literally outputting 1 second|%count% seconds?

Yes

@weaverryan
Copy link
Collaborator

What does $seconds look like by the time it gets here? https://github.com/KnpLabs/KnpTimeBundle/blob/main/src/DateTimeFormatter.php#L56

@kbond
Copy link
Contributor Author

kbond commented Jul 31, 2023

1.0, 2.0, etc

@kbond
Copy link
Contributor Author

kbond commented Jul 31, 2023

Found the problem, I'm not passing %count% to

return $this->translator->trans($format[1], [], 'time', $locale);

@kbond kbond changed the title [WIP] bug: pluralization not being used for duration translations fix: pluralization not being used for duration translations Jul 31, 2023
tests/IntegrationTest.php Outdated Show resolved Hide resolved
$this->assertStringContainsString("Less than a second: < 1 second\n", $result);
$this->assertStringContainsString("One second: 1 second\n", $result);
$this->assertStringContainsString("Multiple seconds: 59 seconds\n", $result);
$this->assertStringContainsString("One minute: 1 minute\n", $result);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about 61 seconds? Does that still say 1 minute? Same for 1 hour and 1 minute (e.g. 3660 seconds)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that still say 1 minute?

Yes, I added some tests for this.

@weaverryan
Copy link
Collaborator

Thanks Kevin!

@weaverryan weaverryan merged commit af3aa65 into KnpLabs:main Jul 31, 2023
10 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