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

Plural translations #8

Open
rukshanfonseka opened this issue Sep 25, 2023 · 1 comment
Open

Plural translations #8

rukshanfonseka opened this issue Sep 25, 2023 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@rukshanfonseka
Copy link

There isn't an example of a plural translation using the Tr and bindings. How can I do this?

@codingseb codingseb added documentation Improvements or additions to documentation enhancement New feature or request labels Sep 28, 2023
@codingseb codingseb self-assigned this Sep 28, 2023
@codingseb
Copy link
Owner

codingseb commented Sep 28, 2023

Yes it need more documentation but in short : you can split a translation with | and specify an integer model to choose the translation to use. The translation can be split in 2 or in 3 depending if you want a specific text when the model is 0. you can also use {model} to inject the value in the text.

Example.loc.json

{
    "PluralizedTextIdWithZero": {
        "en": "No element found | One element found | {model} elements found",
        "...":"..."
    },
    "PluralizedTextId": {
        "en": "element | elements",
         "...":"..."
    }
}

In C#

Loc.Tr("PluralizedTextIdWithZero", 0); // --> No element found
Loc.Tr("PluralizedTextIdWithZero", 1); // --> One element found
Loc.Tr("PluralizedTextIdWithZero", 2); // --> 2 elements found
Loc.Tr("PluralizedTextIdWithZero", 10); // --> 10 elements found

Loc.Tr("PluralizedTextId", 0); // --> element
Loc.Tr("PluralizedTextId", 1); // --> element
Loc.Tr("PluralizedTextId", 2); // --> elements
Loc.Tr("PluralizedTextId", 10); // -->elements

In XAML

<!-- With static model -->
<TextBlock Text="{Tr PluralizedTextIdWithZero, Model=1}" />

<!-- With dynamic bindable model (DataContext) -->
<TextBlock Text="{Tr PluralizedTextIdWithZero, ModelBinding={Binding MyObservableCollection.Count}}" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants