use_locale
Reactive locale matching.
Returns the first matching locale given by use_locales that is also found in
the supported list. In case there is no match, then the first locale in supported will be
returned.
If
supportedis empty, this function will panic!
Matching is done by using the unic_langid::LanguageIdentifier::matches method.
Demo
Usage
use leptos::*;
use leptos_use_locale::use_locale;
use unic_langid::langid_slice;
#[component]
fn Demo() -> impl IntoView {
let locale = use_locale(langid_slice!["en", "de", "fr"]);
view! { }
}
Server-Side Rendering
Make sure you follow the instructions in Server-Side Rendering.
See use_locales
Installation
cargo add leptos-use-locale
Options
UseLocalesOptions
Options for use_locales_with_options.
Every option is set with a builder method of the same name, e.g. UseLocalesOptions::default().ssr_lang_header_getter(...). See also the API docs.
ssr_lang_header_getter
Type: Arc<dyn Fn() -> Option<String>>
Getter function to return the string value of the accept languange header.
When you use one of the features "axum" or "actix" there’s a valid default implementation provided.