Skip to content

Commit 5e29e73

Browse files
authored
Accept configuration conditional checks directly for most leptos_fluent! parameters (#176)
1 parent 460475a commit 5e29e73

File tree

7 files changed

+537
-95
lines changed

7 files changed

+537
-95
lines changed

CHANGELOG.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CHANGELOG
22

3-
## Unreleased - [0.1.6]
3+
## 2024-06-27 - [0.1.6]
44

55
### New features
66

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

14+
### Bug fixes
15+
16+
- Accept [configuration conditional checks] directly in most macro parameters:
17+
18+
```rust
19+
leptos_fluent! {{
20+
// ...
21+
#[cfg(debug_assertions)]
22+
initial_language_from_url_param: true,
23+
#[cfg(debug_assertions)]
24+
set_language_to_url_param: true,
25+
}}
26+
```
27+
28+
[configuration conditional checks]: https://doc.rust-lang.org/rust-by-example/attribute/cfg.html
29+
1430
## 2024-06-26 - [0.1.5]
1531

1632
### New features
@@ -321,7 +337,7 @@ version to `0.1` during installation.
321337

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

324-
[0.1.6]: https://github.com/mondeja/leptos-fluent/compare/v0.1.5...master
340+
[0.1.6]: https://github.com/mondeja/leptos-fluent/compare/v0.1.5...v0.1.6
325341
[0.1.5]: https://github.com/mondeja/leptos-fluent/compare/v0.1.4...v0.1.5
326342
[0.1.4]: https://github.com/mondeja/leptos-fluent/compare/v0.1.3...v0.1.4
327343
[0.1.3]: https://github.com/mondeja/leptos-fluent/compare/v0.1.2...v0.1.3

Cargo.lock

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book/src/faqs.md

+14
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ pub fn App() -> impl IntoView {
156156
fn LanguageSelector() -> impl IntoView { ... }
157157
```
158158

159+
### How to get values of `leptos_fluent!` macro at runtime?
160+
161+
Use `provide_meta_context` at the macro initialization and get them
162+
with the method `I18n::meta`:
163+
164+
```rust
165+
let i18n = leptos_fluent! {{
166+
// ...
167+
provide_meta_context: true,
168+
}};
169+
170+
println!("Macro parameters: {:?}", i18n.meta().unwrap());
171+
```
172+
159173
[`<For/>`]: https://docs.rs/leptos/latest/leptos/fn.For.html
160174
[`leptos_fluent::SsrHtmlTag`]: https://docs.rs/leptos-fluent/latest/leptos_fluent/fn.SsrHtmlTag.html
161175
[`leptos_fluent::Language`]: https://docs.rs/leptos-fluent/latest/leptos_fluent/struct.Language.html

book/src/leptos_fluent.md

+14
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,20 @@ leptos_fluent! {{
605605
}}
606606
```
607607

608+
### `provide_meta_context`
609+
610+
Provide the macro meta information at runtime as a context.
611+
Get it using `I18n::meta`:
612+
613+
```rust
614+
let i18n = leptos_fluent! {{
615+
// ...
616+
provide_meta_context: true,
617+
}};
618+
619+
println!("Macro parameters: {:?}", i18n.meta().unwrap());
620+
```
621+
608622
[`fluent_templates::static_loader!`]: https://docs.rs/fluent-templates/latest/fluent_templates/macro.static_loader.html
609623
[`once_cell:sync::Lazy`]: https://docs.rs/once_cell/latest/once_cell/sync/struct.Lazy.html
610624
[`<html lang="...">` attribute]: https://developer.mozilla.org/es/docs/Web/HTML/Global_attributes/lang

examples/csr-minimal/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub fn App() -> impl IntoView {
1515
translations: [TRANSLATIONS],
1616
locales: "./locales",
1717
check_translations: "./src/**/*.rs",
18+
#[cfg(debug_assertions)]
19+
initial_language_from_url_param: true,
20+
#[cfg(debug_assertions)]
21+
set_language_to_url_param: true,
1822
}};
1923

2024
view! { <LanguageSelector/> }

0 commit comments

Comments
 (0)