Skip to content

Commit

Permalink
Add examples of leptos_fluent! invocations to book (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored Jun 25, 2024
1 parent 5d5dfe6 commit 1cd7025
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions book/src/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ The i18n context has the following fields:
- [`translations`]: A signal to the vector of [fluent-templates] loaders that stores
the translations.

### Update language

To update the language, use `set` method of `language` field or just
[`lang.activate()`] (new in v0.1.1):

Expand All @@ -203,6 +205,8 @@ let i18n = leptos_fluent::expect_i18n();
i18n(lang);
```

### Get active language

To get the current active language, use `get` method of `language` field:

```rust
Expand All @@ -211,12 +215,16 @@ i18n.language.get()
i18n() // features = ["nightly"]
```

### Get available languages

To get the available languages, iterate over the `languages` field:

```rust
i18n.languages.iter()
```

### Check if a language is active

To check if a language is the active one, use `is_active` method of a
[`leptos_fluent::Language`] struct:

Expand Down
35 changes: 35 additions & 0 deletions book/src/strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,38 @@ The names of the settings can be configured using the following parameters:
[Cookie]: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
[Cookie attributes]: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#write_a_new_cookie
[URL parameter]: https://developer.mozilla.org/es/docs/Web/API/URLSearchParams

# Common configurations

## Local storage from navigator (CSR)

```rust
leptos_fluent! {{
locales: "./locales",
translations: [TRANSLATIONS],

set_language_to_localstorage: true,
initial_language_from_localstorage: true,
initial_language_from_navigator: true,
initial_language_from_navigator_to_localstorage: true,
initial_language_from_url_param: true,
initial_language_from_url_param_to_localstorage: true,
}}
```

## Cookie from navigator and header (SSR + CSR)

```rust
leptos_fluent! {{
locales: "./locales",
translations: [TRANSLATIONS],

set_language_to_cookie: true,
initial_language_from_cookie: true,
initial_language_from_navigator: true,
initial_language_from_navigator_to_cookie: true,
initial_language_from_url_param: true,
initial_language_from_url_param_to_cookie: true,
initial_language_from_accept_language_header: true,
}}
```

0 comments on commit 1cd7025

Please sign in to comment.