Skip to content

trans_choice uses wrong pluralization rules for fallback #52341

Closed
@stefanvdlugt

Description

@stefanvdlugt

Laravel Version

11.8.0

PHP Version

8.2.18

Database Driver & Version

MySQL 8.0.32 for Linux on x86_64

Description

The trans_choice translation function always uses the pluralization rules of the selected locale. If the provided key is not translated in this locale, it falls back to the fallback locale, but it still uses the pluralization rules of the preferred locale.

For example, Czech has 3 forms, while English has 2. If the translator must fall back to English, it should use the English pluralization rules.

Steps To Reproduce

app('translator')->setLocale('cs_CZ');
$fallback = app('translator')->getFallback();
app('translator')->addLines(['strings.apple' => ':count apple|:count apples'], $fallback);
trans_choice('strings.apple', 1); // 1 apple
trans_choice('strings.apple', 2); // 2 apples
trans_choice('strings.apple', 10); // 10 apple - WRONG

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions