Skip to content

Use formatting functions with interpolation and plurals in the nesting "t" function #2323

@otomad

Description

@otomad

🚀 Feature Proposal

Use formatting functions with interpolation and plurals in the nesting "$t" function.

Motivation

This is useful if you need to reference other keys in a translation and need to change both the pluralization and the formatting simultaneously.

Example

{
    "boy": "Boy",
    "boy_other": "Boys",
    "girl": "Girl",
    "girl_other": "Girls",
    "girlsAndBoys": "They have {{girls}} $t(girl, { \"count\": {{girls}} }, lowercase) and {{boys}} $t(boy, { \"count\": {{boys}} }, lowercase)",
}

Result:

i18next.t("girlsAndBoys", { girls: 3, boys: 2 }); // -> "They have 3 girls and 2 boys"

Currently, both $t(girl, { \"count\": {{girls}} }, lowercase) and $t($t(boy, { \"count\": {{boys}} }), lowercase) will not work. The error message of the latter: i18next::translator: missingKey en $t(boy $t(boy

I can PR based on #1419.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions