mondeja / leptos-fluent

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

Language from URL path #192

Closed mondeja closed 3 months ago

mondeja commented 4 months ago

It would be great to allow extracting the initial value. This is inspired by https://github.com/Baptistemontan/leptos_i18n/issues/31

My proposal is that the API should accept a closure or function for a new option url_path that would return the locale string. For example, extract from first subdirectory:

// "/en/path/to/resource?foo=bar" -> "en"
fn extract(path: &str) -> &str {
    if let Some(language) = path.split('/').nth(1) {
        return language;
    }
    ""
}

leptos_fluent! {{
    // ...
    url_path: extract,
    initial_value_from_url_path: true,
}};