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

[10.x] Officially support floats in trans_choice and Translator::choice #49693

Merged
merged 1 commit into from
Jan 15, 2024
Merged

[10.x] Officially support floats in trans_choice and Translator::choice #49693

merged 1 commit into from
Jan 15, 2024

Commits on Jan 15, 2024

  1. [10.x] Officially support floats in trans_choice

    This already works fine with no further changes needed, so I'm not
    sure if there's a reason that floats were never officially supported.
    This is how it is currently, which you can see works perfectly
    fine:
    
    Given:
    
        // lang/en/foo.php
        return [
            'hours' => 'A total of :hours hour|A total of :hours hours',
        ];
    
    Then:
    
        trans_choice('foo.hours', 1, ['hours' => 1]) === 'A total of 1 hour'
        trans_choice('foo.hours', 1.0, ['hours' => 1.0]) === 'A total of 1 hour'
        trans_choice('foo.hours', 1.1, ['hours' => 1.1]) === 'A total of 1.1 hours'
        trans_choice('foo.hours', 0.9, ['hours' => 0.9]) === 'A total of 0.9 hours'
    
    However, when running phpstan & larastan on a Laravel project that
    passes a float to trans_choice when wanting to display text similar
    to those examples ("A total of X hour[s]") it results in an error
    because the only documented allowed types are \Countable|int|array.
    philbates35 committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    9e17ba9 View commit details
    Browse the repository at this point in the history