mondeja / leptos-fluent

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

Follow `static_loader!` definition #90

Open mondeja opened 4 months ago

mondeja commented 4 months ago

AFAIK, seems possible the reading of the source code to search for the location of the fluent-templates static_loader! macro definition and parse its content:

static_loader! {
    static TRANSLATIONS = {
        locales: "./locales",
        fallback_language: "en",
    };
}

Because we are passing TRANSLATIONS to leptos_fluent! macro, we can know where is defined. Even if is not inside the current file, altough that case could be a bit difficult.

This will allow to not need to duplicate the locales: "..." argument and the future argument core_locales: "..." (see #89).

mondeja commented 3 months ago

To get the definition site or source file of a syn::Ident we need to pass RUSTFLAGS='--cfg procmacro2_semver_exempt' to proc-macro2. This is not ideal because it would force all consumers of this library to pass it.

So this issue is blocked until proc_macro2::Span implements def_site and/or source_file at least in nightly.

mondeja commented 2 months ago

Additionally, if we could follow definitions of things, the next code can be optimized to convert from an expression to a literal:

let name = "language";

leptos_fluent! {{
    ...
    cookie_name: name,
}}

It would be converted to:

leptos_fluent! {{
    ...
    cookie_name: "language",
}}