Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptistemontan committed Nov 3, 2024
1 parent b3d2ae3 commit adadc5b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
13 changes: 11 additions & 2 deletions docs/book/src/declare/03_plurals.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This can be solved by defining 2 plural forms:
}
```

Providing the count to the `t!` macro with the `$`, this will result in:
Providing the count to the `t!` macro, this will result in:

```rust
let i18n = use_i18n();
Expand All @@ -33,7 +33,16 @@ t!(i18n, items, count = || 1) // -> "1 item"
t!(i18n, items, count = || 4) // -> "4 items"
```

`{{ count }}` is a special variable when using plurals, you don't supply it as `t!(i18n, key, count = ..)` but with the `$`.
`{{ count }}` is a special variable when using plurals, even if you don't interpolate it you ust supply it:

```json
{
"items_one": "one item",
"items_other": "some items"
}
```

This will still need you to supply the `count` variable: `t!(i18n, items, count = ...)`.

## Why bother ?

Expand Down
10 changes: 9 additions & 1 deletion docs/book/src/usage/04_t_macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,20 @@ Basically `<name .../>` expand to `move |children| view! { <name ...>{children}<

## Ranges

Ranges expect a variable `$` that implement `Fn() -> N + Clone + 'static` where `N` is the specified type of the range (default is `i32`).
Ranges expect a variable `count` that implement `Fn() -> N + Clone + 'static` where `N` is the specified type of the range (default is `i32`).

```rust
t!(i18n, key_to_range, count = count);
```

## Plurals

Plurals expect a variable `count` that implement `Fn() -> N + Clone + 'static` where `N` implement `Into<icu_plurals::PluralsOperands>` ([`PluralsOperands`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html)). Integers and unsigned primitives implements it, along with `FixedDecimal`.

```rust
t!(i18n, key_to_plurals, count = count);
```

## Access subkeys

You can access subkeys by simply separating the path with `.`:
Expand Down
16 changes: 8 additions & 8 deletions docs/book/src/usage/05_td_macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pub fn Foo() -> impl IntoView {

view! {
<For
each = || [Locale::en, Locale::fr]
key = |locale| *locale
view = move |locale| view! {
<button on:click = move|_| i18n.set_locale(locale)>
{td!(locale, set_locale)}
</button>
}
/>
each = Locale::get_all
key = |locale| **locale
let:locale
>
<button on:click = move|_| i18n.set_locale(*locale)>
{td!(*locale, set_locale)}
</button>
</For>
}
}
```
Expand Down

0 comments on commit adadc5b

Please sign in to comment.