Skip to content

Commit

Permalink
Accept configuration conditional checks directly for most `leptos_flu…
Browse files Browse the repository at this point in the history
…ent!` parameters (#176)
  • Loading branch information
mondeja authored Jun 27, 2024
1 parent 460475a commit 5e29e73
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 95 deletions.
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CHANGELOG

## Unreleased - [0.1.6]
## 2024-06-27 - [0.1.6]

### New features

Expand All @@ -11,6 +11,22 @@
- Add `flag` field to `leptos_fluent::Language` storing emoji flag
automatic discovered for each language identifier with a country code.

### Bug fixes

- Accept [configuration conditional checks] directly in most macro parameters:

```rust
leptos_fluent! {{
// ...
#[cfg(debug_assertions)]
initial_language_from_url_param: true,
#[cfg(debug_assertions)]
set_language_to_url_param: true,
}}
```

[configuration conditional checks]: https://doc.rust-lang.org/rust-by-example/attribute/cfg.html

## 2024-06-26 - [0.1.5]

### New features
Expand Down Expand Up @@ -321,7 +337,7 @@ version to `0.1` during installation.

- Added all ISO-639-1 and ISO-639-2 languages.

[0.1.6]: https://github.com/mondeja/leptos-fluent/compare/v0.1.5...master
[0.1.6]: https://github.com/mondeja/leptos-fluent/compare/v0.1.5...v0.1.6
[0.1.5]: https://github.com/mondeja/leptos-fluent/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/mondeja/leptos-fluent/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/mondeja/leptos-fluent/compare/v0.1.2...v0.1.3
Expand Down
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions book/src/faqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@ pub fn App() -> impl IntoView {
fn LanguageSelector() -> impl IntoView { ... }
```

### How to get values of `leptos_fluent!` macro at runtime?

Use `provide_meta_context` at the macro initialization and get them
with the method `I18n::meta`:

```rust
let i18n = leptos_fluent! {{
// ...
provide_meta_context: true,
}};

println!("Macro parameters: {:?}", i18n.meta().unwrap());
```

[`<For/>`]: https://docs.rs/leptos/latest/leptos/fn.For.html
[`leptos_fluent::SsrHtmlTag`]: https://docs.rs/leptos-fluent/latest/leptos_fluent/fn.SsrHtmlTag.html
[`leptos_fluent::Language`]: https://docs.rs/leptos-fluent/latest/leptos_fluent/struct.Language.html
Expand Down
14 changes: 14 additions & 0 deletions book/src/leptos_fluent.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,20 @@ leptos_fluent! {{
}}
```

### `provide_meta_context`

Provide the macro meta information at runtime as a context.
Get it using `I18n::meta`:

```rust
let i18n = leptos_fluent! {{
// ...
provide_meta_context: true,
}};

println!("Macro parameters: {:?}", i18n.meta().unwrap());
```

[`fluent_templates::static_loader!`]: https://docs.rs/fluent-templates/latest/fluent_templates/macro.static_loader.html
[`once_cell:sync::Lazy`]: https://docs.rs/once_cell/latest/once_cell/sync/struct.Lazy.html
[`<html lang="...">` attribute]: https://developer.mozilla.org/es/docs/Web/HTML/Global_attributes/lang
Expand Down
4 changes: 4 additions & 0 deletions examples/csr-minimal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub fn App() -> impl IntoView {
translations: [TRANSLATIONS],
locales: "./locales",
check_translations: "./src/**/*.rs",
#[cfg(debug_assertions)]
initial_language_from_url_param: true,
#[cfg(debug_assertions)]
set_language_to_url_param: true,
}};

view! { <LanguageSelector/> }
Expand Down
Loading

0 comments on commit 5e29e73

Please sign in to comment.