mondeja / leptos-fluent

Internationalization framework for Leptos using Fluent
https://mondeja.github.io/leptos-fluent/
MIT License
38 stars 10 forks source link

Fully qualify `window()` in `leptos_fluent!` #255

Closed ilyvion closed 3 weeks ago

ilyvion commented 3 weeks ago

This change avoids an error of this nature when invoking the macro:

error[E0425]: cannot find function `window` in this scope
   --> src\fluent.rs:29:5
    |
29  | /     leptos_fluent! {
30  | |         // Path to the locales directory, relative to Cargo.toml.
31  | |         locales: "./locales",
32  | |         // Static translations struct provided by fluent-templates.
...   |
117 | |         // set_language_to_data_file: true,
118 | |     };
    | |_____^ not found in this scope
    |
    = note: this error originates in the macro `leptos_fluent` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these functions
    |
1   + use leptos::window;
    |
1   + use web_sys::window;
    |
mondeja commented 3 weeks ago

I can't reproduce it. Are you using leptos v0.7? If that's the case you should try the leptos-v0.7 branch.

ilyvion commented 3 weeks ago

No, this is with leptos v0.6. It's important to note that this is with only use leptos_fluent::leptos_fluent; (plus whatever it takes to create/load the value needed for translations), if you have something like use leptos::* in your file, window will already be in scope, and you won't see the error.

Here's my full file for reference, imported in lib.rs with pub mod fluent; and used from my App component in app.rs with fluent::setup();.

Incidentally, if I put use leptos::* in my file, which does stop the error, I get

warning: unused import: `leptos`
 --> src\fluent.rs:5:5
  |
5 | use leptos::*;
  |     ^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

😅