Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

use_locales

Reactive locales.

If called on the client-side this function returns the value of navigator.languages and listens for changes to that property.

See “Server-Side Rendering” below.

Demo

Usage

use leptos::*;
use leptos_use_locales::use_locales;

#[component]
fn Demo() -> impl IntoView {
let locales = use_locales();

view! { }
}

Server-Side Rendering

Make sure you follow the instructions in Server-Side Rendering.

On the server this returns the parsed value of the accept-language header.

If you’re using axum you have to enable the "axum" feature in your Cargo.toml. In case it’s actix-web enable the feature "actix".

Bring your own header

In case you’re neither using Axum nor Actix or the default implementation is not to your liking, you can provide your own way of reading the language header value using the option UseLocalesOptions::ssr_lang_header_getter.

Installation

cargo add leptos-use-locales

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.

Source

Source • Demo • Docs