diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79119c45..0da997ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -374,7 +374,7 @@ jobs: id: version uses: ./.github/actions/get-version - name: Update version - run: sed -i "s/^leptos-fluent-macros = .*/leptos-fluent-macros = \"${{ steps.version.outputs.version }}\"/" leptos-fluent/Cargo.toml + run: sed -i "s/^leptos-fluent-macros = .*/leptos-fluent-macros = \"=${{ steps.version.outputs.version }}\"/" leptos-fluent/Cargo.toml - name: Publish run: | cargo login ${{ secrets.CRATES_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 1750642b..9a08e4b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,28 @@ # CHANGELOG -## Unreleased - [0.2.6] +## 2025-03-07 - [0.2.6] ### New features - Add a new parameter `fill_translations` to `leptos_fluent!` macro to add messages found in `tr!` and `move_tr!` macros to Fluent translations files. +- Add next new parameters to `leptos_fluent!` macro to use browser's session + storage: + - `sessionstorage_key` to set the key to store the current language. + - `initial_language_from_sessionstorage` to set the initial language from + session storage. + - `set_language_to_sessionstorage` to set the current language to session + storage. + - `initial_language_from_sessionstorage_to_cookie` to set the initial + language from session storage to a cookie. + - `initial_language_from_sessionstorage_to_localstorage` to set the initial + language from session storage to local storage. + - `initial_language_from_sessionstorage_to_server_function` to set the + initial language from session storage to a server function. + - `initial_language_from_localstorage_to_sessionstorage` to set the initial + language from local storage to session storage. + - `initial_language_from_navigator_to_sessionstorage` to set the initial + language from the browser `navigator.languages` to session storage. ## 2025-03-06 - [0.2.5] @@ -661,7 +678,7 @@ version to `0.1` during installation. - Added all ISO-639-1 and ISO-639-2 languages. -[0.2.6]: https://github.com/mondeja/leptos-fluent/compare/v0.2.5...master +[0.2.6]: https://github.com/mondeja/leptos-fluent/compare/v0.2.5...v0.2.6 [0.2.5]: https://github.com/mondeja/leptos-fluent/compare/v0.2.4...v0.2.5 [0.2.4]: https://github.com/mondeja/leptos-fluent/compare/v0.2.3...v0.2.4 [0.2.3]: https://github.com/mondeja/leptos-fluent/compare/v0.2.2...v0.2.3 diff --git a/Cargo.lock b/Cargo.lock index 1695ed6a..f7c2bdd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,16 +267,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41058deaa38c9d9dd933d6d238d825227cffa668e2839b52879f6619c63eee3b" dependencies = [ "futures", - "thiserror 2.0.11", + "thiserror 2.0.12", "tokio", "wasm-bindgen-futures", ] [[package]] name = "anyhow" -version = "1.0.96" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b964d184e89d9b6b67dd2715bc8e74cf3107fb2b529990c90cf517326150bf4" +checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" [[package]] name = "async-lock" @@ -291,9 +291,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.86" +version = "0.1.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644dd749086bf3771a2fbc5f256fdb982d53f011c7d5d560304eafeecebce79d" +checksum = "d556ec1359574147ec0c4fc5eb525f3f23263a592b1a9c07e0a75b427de55c97" dependencies = [ "proc-macro2", "quote", @@ -479,9 +479,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f61dac84819c6588b558454b194026eb1f09c293b9036ae9b159e74e73ab6cf9" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "bytestring" @@ -532,7 +532,7 @@ checksum = "0f18d705321923b1a9358e3fc3c57c3b50171196827fc7f5f10b053242aca627" dependencies = [ "serde", "serde_json", - "thiserror 2.0.11", + "thiserror 2.0.12", ] [[package]] @@ -793,15 +793,15 @@ checksum = "669a445ee724c5c69b1b06fe0b63e70a1c84bc9bb7d9696cd4f4e3ec45050408" [[package]] name = "dyn-clone" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "feeef44e73baff3a26d371801df019877a9866a8c493d315ab00177843314f35" +checksum = "1c7a8fb8a9fbf66c1f703fe16184d10ca0ee9d23be5b4436400408ba54a95005" [[package]] name = "either" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7914353092ddf589ad78f25c5c1c21b7f80b0ff8621e7c814c3485b5306da9d" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "either_of" @@ -1244,9 +1244,9 @@ checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c" [[package]] name = "httparse" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2d708df4e7140240a16cd6ab0ab65c972d7433ab77819ea693fde9c43811e2a" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] name = "httpdate" @@ -1503,9 +1503,9 @@ dependencies = [ [[package]] name = "inventory" -version = "0.3.19" +version = "0.3.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b12ebb6799019b044deaf431eadfe23245b259bba5a2c0796acec3943a3cdb" +checksum = "ab08d7cd2c5897f2c949e5383ea7c7db03fb19130ffcfbf7eda795137ae3cb83" dependencies = [ "rustversion", ] @@ -1521,9 +1521,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "jobserver" @@ -1591,7 +1591,7 @@ dependencies = [ "server_fn", "slotmap", "tachys", - "thiserror 2.0.11", + "thiserror 2.0.12", "throw_error", "typed-builder", "typed-builder-macro", @@ -1672,6 +1672,19 @@ dependencies = [ "wasm-bindgen-test", ] +[[package]] +name = "leptos-fluent-end2end-set-language-to-sessionstorage-tests" +version = "0.1.0" +dependencies = [ + "fluent-templates", + "leptos", + "leptos-fluent", + "leptos-fluent-csr-minimal-example", + "tests-helpers", + "wasm-bindgen", + "wasm-bindgen-test", +] + [[package]] name = "leptos-fluent-end2end-tests" version = "0.1.0" @@ -1811,7 +1824,7 @@ dependencies = [ "config", "regex", "serde", - "thiserror 2.0.11", + "thiserror 2.0.12", "typed-builder", ] @@ -1920,7 +1933,7 @@ dependencies = [ "reactive_graph", "send_wrapper", "tachys", - "thiserror 2.0.11", + "thiserror 2.0.12", "url", "wasm-bindgen", "web-sys", @@ -2285,7 +2298,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror 2.0.11", + "thiserror 2.0.12", "ucd-trie", ] @@ -2325,18 +2338,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.9" +version = "1.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfe2e71e1471fe07709406bf725f710b02927c9c54b2b5b2ec0e8087d97c327d" +checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.9" +version = "1.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6e859e6e5bd50440ab63c47e3ebabc90f26251f7c73c3d3e837b74a1cc3fa67" +checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", @@ -2357,9 +2370,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "powerfmt" @@ -2378,9 +2391,9 @@ dependencies = [ [[package]] name = "prettyplease" -version = "0.2.29" +version = "0.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6924ced06e1f7dfe3fa48d57b9f74f55d8915f5036121bef647ef4b204895fac" +checksum = "f1ccf34da56fc294e7d4ccf69a85992b7dfb826b7cf57bac6a70bba3494cc08a" dependencies = [ "proc-macro2", "syn", @@ -2427,9 +2440,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" dependencies = [ "unicode-ident", ] @@ -2449,9 +2462,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.38" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801" dependencies = [ "proc-macro2", ] @@ -2525,7 +2538,7 @@ dependencies = [ "send_wrapper", "serde", "slotmap", - "thiserror 2.0.11", + "thiserror 2.0.12", "web-sys", ] @@ -2559,9 +2572,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82b568323e98e49e2a0899dcee453dd679fae22d69adf9b11dd508d1549b7e2f" +checksum = "0b8c0c260b63a8219631167be35e6a988e9554dbd323f8bd08439c8ed1302bd1" dependencies = [ "bitflags", ] @@ -2624,7 +2637,7 @@ dependencies = [ "quote", "syn", "syn_derive", - "thiserror 2.0.11", + "thiserror 2.0.12", ] [[package]] @@ -2656,15 +2669,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.19" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" [[package]] name = "ryu" -version = "1.0.19" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "same-file" @@ -2698,9 +2711,9 @@ checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe" [[package]] name = "semver" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f79dfe2d285b0488816f30e700a7438c5a73d816b5b7d3ac72fbc48b0d185e03" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" [[package]] name = "send_wrapper" @@ -2733,9 +2746,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.139" +version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44f86c3acccc9c65b153fe1b85a3be07fe5515274ec9f0653b4a0875731c72a6" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" dependencies = [ "itoa", "memchr", @@ -2745,9 +2758,9 @@ dependencies = [ [[package]] name = "serde_path_to_error" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a" dependencies = [ "itoa", "serde", @@ -2823,7 +2836,7 @@ dependencies = [ "serde_json", "serde_qs", "server_fn_macro_default", - "thiserror 2.0.11", + "thiserror 2.0.12", "throw_error", "tower", "tower-layer", @@ -2944,9 +2957,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "syn" -version = "2.0.98" +version = "2.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" +checksum = "e02e925281e18ffd9d640e234264753c43edc62d64b2d4cf898f1bc5e75f3fc2" dependencies = [ "proc-macro2", "quote", @@ -3054,11 +3067,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.11" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" dependencies = [ - "thiserror-impl 2.0.11", + "thiserror-impl 2.0.12", ] [[package]] @@ -3074,9 +3087,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.11" +version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" dependencies = [ "proc-macro2", "quote", @@ -3094,9 +3107,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.37" +version = "0.3.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" +checksum = "dad298b01a40a23aac4580b67e3dbedb7cc8402f3592d7f49469de2ea4aecdd8" dependencies = [ "deranged", "itoa", @@ -3109,15 +3122,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" +checksum = "765c97a5b985b7c11d7bc27fa927dc4fe6af3a6dfb021d28deb60d3bf51e76ef" [[package]] name = "time-macros" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" +checksum = "e8093bc3e81c3bc5f7879de09619d06c9a5a5e45ca44dfeeb7225bae38005c5c" dependencies = [ "num-conv", "time-core", @@ -3296,9 +3309,9 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.103" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b812699e0c4f813b872b373a4471717d9eb550da14b311058a4d9cf4173cbca6" +checksum = "6ae08be68c056db96f0e6c6dd820727cca756ced9e1f4cc7fdd20e2a55e23898" dependencies = [ "glob", "serde", @@ -3401,9 +3414,9 @@ checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" [[package]] name = "unicode-ident" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00e2473a93778eb0bad35909dff6a10d28e63f792f16ed15e404fca9d5eeedbe" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unicode-segmentation" diff --git a/Cargo.toml b/Cargo.toml index 68ca2a28..c3d22a20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ members = [ "tests/end2end/initial-language-from-navigator", "tests/end2end/set-language-to-cookie", "tests/end2end/set-language-to-localstorage", + "tests/end2end/set-language-to-sessionstorage", ] resolver = "2" diff --git a/book/src/leptos_fluent.md b/book/src/leptos_fluent.md index 629f4e9f..28c261ed 100644 --- a/book/src/leptos_fluent.md +++ b/book/src/leptos_fluent.md @@ -460,6 +460,17 @@ leptos_fluent! { } ``` +### CSR | `initial_language_from_localstorage_to_sessionstorage` + +Get initial language from [local storage] and save it to [session storage]. + +```rust +leptos_fluent! { + // ... + initial_language_from_localstorage_to_sessionstorage: true, +} +``` + ### CSR | `set_language_to_localstorage` Set the current language to [local storage]. @@ -471,6 +482,65 @@ leptos_fluent! { } ``` + + +### CSR | `sessionstorage_key: `"lang" + + + +[Session storage] key to manage the current language. + +```rust +leptos_fluent! { + // ... + sessionstorage_key: "lang", +} +``` + +### CSR | `initial_language_from_sessionstorage` + +Get initial language from [session storage]. + +```rust +leptos_fluent! { + // ... + initial_language_from_sessionstorage: true, +} +``` + +### CSR | `initial_language_from_sessionstorage_to_cookie` + +Get initial language from [session storage] and save it to a [cookie]. + +```rust +leptos_fluent! { + // ... + initial_language_from_sessionstorage_to_cookie: true, +} +``` + +### CSR | `initial_language_from_sessionstorage_to_localstorage` + +Get initial language from [session storage] and save it to [local storage]. + +```rust +leptos_fluent! { + // ... + initial_language_from_sessionstorage_to_localstorage: true, +} +``` + +### CSR | `set_language_to_sessionstorage` + +Set the current language to [session storage]. + +```rust +leptos_fluent! { + // ... + set_language_to_sessionstorage: true, +} +``` + ### CSR | `initial_language_from_navigator` Get the initial language from [`navigator.languages`]. @@ -484,7 +554,7 @@ leptos_fluent! { ### CSR | `initial_language_from_navigator_to_localstorage` -Get the initial language from [`navigator.languages`] and save it in the [local storage]. +Get the initial language from [`navigator.languages`] and save it in [local storage]. ```rust leptos_fluent! { @@ -493,6 +563,17 @@ leptos_fluent! { } ``` +### CSR | `initial_language_from_navigator_to_sessionstorage` + +Get the initial language from [`navigator.languages`] and save it in [session storage]. + +```rust +leptos_fluent! { + // ... + initial_language_from_navigator_to_sessionstorage: true, +} +``` + ### CSR | `initial_language_from_navigator_to_cookie` Get the initial language from [`navigator.languages`] and save it in a [cookie]. @@ -581,7 +662,7 @@ leptos_fluent! { ### CSR | `initial_language_from_cookie_to_localstorage` -Get the initial language from the cookie and save it in the [local storage]. +Get the initial language from the cookie and save it in [local storage]. ```rust leptos_fluent! { @@ -762,6 +843,26 @@ pub async fn set_language_server_function( } ``` +### `initial_language_from_sessionstorage_to_server_function` + +Get the initial language from [session storage] and set it to a +[server function]. + +```rust +leptos_fluent! { + // ... + initial_language_from_sessionstorage_to_server_function: set_language_server_function, +} + +#[server(SetLanguage, "/api")] +pub async fn set_language_server_function( + language: String, +) -> Result<(), ServerFnError> { + // .. replace with your own logic + Ok(()) +} +``` + ### `initial_language_from_cookie_to_server_function` Get the initial language from a [cookie] and set it to a @@ -869,6 +970,7 @@ leptos_fluent! { [`` attribute]: https://developer.mozilla.org/docs/Web/HTML/Global_attributes/lang [`` attribute]: https://developer.mozilla.org/docs/Web/HTML/Global_attributes/dir [local storage]: https://developer.mozilla.org/docs/Web/API/Window/localStorage +[session storage]: https://developer.mozilla.org/docs/Web/API/Window/sessionStorage [`navigator.languages`]: https://developer.mozilla.org/docs/Web/API/Navigator/languages [`Effect::new`]: https://docs.rs/leptos/latest/leptos/prelude/struct.Effect.html [cookie attributes]: https://developer.mozilla.org/docs/Web/API/Document/cookie#write_a_new_cookie diff --git a/book/src/strategies.md b/book/src/strategies.md index a276928a..1ce59dfc 100644 --- a/book/src/strategies.md +++ b/book/src/strategies.md @@ -18,6 +18,7 @@ The initial language of the user can be set in different ways: | [Cookie] | ✅ | ✅ | ❌ | `initial_language_from_cookie` | | [Server function] | ✅ | ✅ | ❌ | `initial_language_from_server_function` | | Browser [local storage] | ✅ | ❌ | ❌ | `initial_language_from_localstorage` | +| Browser [session storage] | ✅ | ❌ | ❌ | `initial_language_from_sessionstorage` | | Browser [`navigator.languages`] | ✅ | ❌ | ❌ | `initial_language_from_navigator` | | [`Accept-Language`] header | ❌ | ✅ | ❌ | `initial_language_from_accept_language_header` | | [System language] | ❌ | ❌ | ✅ | `initial_language_from_system` | @@ -39,6 +40,7 @@ The order of precedence is: 1. [URL path] 1. [Cookie] 1. Browser [local storage] + 1. Browser [session storage] 1. Browser [`navigator.languages`] - **Desktop** ([`system` feature][desktop-applications]) 1. Data file @@ -50,12 +52,13 @@ When the user changes the language and `I18n::language.set` is called, the framework can perform a side effect to update the language in the client. The following strategies are available: -| Strategy | [`leptos_fluent!`] | -| :---------------------- | :-------------------------------- | -| [URL parameter] | `set_language_to_url_param` | -| [Cookie] | `set_language_to_cookie` | -| Browser [local storage] | `set_language_to_localstorage` | -| [Server function] | `set_language_to_server_function` | +| Strategy | [`leptos_fluent!`] | +| :------------------------ | :-------------------------------- | +| [URL parameter] | `set_language_to_url_param` | +| [Cookie] | `set_language_to_cookie` | +| Browser [local storage] | `set_language_to_localstorage` | +| Browser [session storage] | `set_language_to_sessionstorage` | +| [Server function] | `set_language_to_server_function` | When the user changes the language in the browser settings, the framework can perform a side effect to reflect the language change in the client. @@ -77,19 +80,24 @@ When a language is loaded from initialization, the framework can perform a side effect to persistently storage the language in the client. The following strategies are available: -| Strategy | [`leptos_fluent!`] | -| :------------------------------------------- | :------------------------------------------------------ | -| [URL parameter] to [cookie] | `initial_language_from_url_param_to_cookie` | -| [URL parameter] to [local storage] | `initial_language_from_url_param_to_localstorage` | -| [URL path] to [cookie] | `initial_language_from_url_path_to_cookie` | -| [URL path] to [local storage] | `initial_language_from_url_path_to_localstorage` | -| [Cookie] to [local storage] | `initial_language_from_cookie_to_localstorage` | -| [Local storage] to [cookie] | `initial_language_from_localstorage_to_cookie` | -| [Local storage] to [server function] | `initial_language_from_localstorage_to_server_function` | -| [`navigator.languages`] to [cookie] | `initial_language_from_navigator_to_cookie` | -| [`navigator.languages`] to [local storage] | `initial_language_from_navigator_to_localstorage` | -| [`navigator.languages`] to [server function] | `initial_language_from_navigator_to_server_function` | -| [Server function] to [local storage] | `initial_language_from_server_function_to_localstorage` | +| Strategy | [`leptos_fluent!`] | +| :------------------------------------------- | :-------------------------------------------------------- | +| [URL parameter] to [cookie] | `initial_language_from_url_param_to_cookie` | +| [URL parameter] to [local storage] | `initial_language_from_url_param_to_localstorage` | +| [URL path] to [cookie] | `initial_language_from_url_path_to_cookie` | +| [URL path] to [local storage] | `initial_language_from_url_path_to_localstorage` | +| [Cookie] to [local storage] | `initial_language_from_cookie_to_localstorage` | +| [Local storage] to [cookie] | `initial_language_from_localstorage_to_cookie` | +| [Local storage] to [session storage] | `initial_language_from_localstorage_to_sessionstorage` | +| [Local storage] to [server function] | `initial_language_from_localstorage_to_server_function` | +| [Session storage] to [cookie] | `initial_language_from_sessionstorage_to_cookie` | +| [Session storage] to [local storage] | `initial_language_from_sessionstorage_to_localstorage` | +| [Session storage] to [server function] | `initial_language_from_sessionstorage_to_server_function` | +| [`navigator.languages`] to [cookie] | `initial_language_from_navigator_to_cookie` | +| [`navigator.languages`] to [local storage] | `initial_language_from_navigator_to_localstorage` | +| [`navigator.languages`] to [session storage] | `initial_language_from_navigator_to_sessionstorage` | +| [`navigator.languages`] to [server function] | `initial_language_from_navigator_to_server_function` | +| [Server function] to [local storage] | `initial_language_from_server_function_to_localstorage` | ### CSR + SSR @@ -123,13 +131,14 @@ update the language in the client. The following side effects are available: The names of the settings can be configured using the following parameters: -| Strategy | [`leptos_fluent!`] | Default value | -| :---------------------- | :----------------- | :-----------: | -| [Cookie] | `cookie_name` | `"lf-lang"` | -| [Cookie attributes] | `cookie_attrs` | `""` | -| Browser [local storage] | `localstorage_key` | `"lang"` | -| [URL parameter] | `url_param` | `"lang"` | -| [URL path] extractor fn | `url_path` | ❌ | +| Strategy | [`leptos_fluent!`] | Default value | +| :------------------------ | :------------------- | :-----------: | +| [Cookie] | `cookie_name` | `"lf-lang"` | +| [Cookie attributes] | `cookie_attrs` | `""` | +| Browser [local storage] | `localstorage_key` | `"lang"` | +| Browser [session storage] | `sessionstorage_key` | `"lang"` | +| [URL parameter] | `url_param` | `"lang"` | +| [URL path] extractor fn | `url_path` | ❌ | ### featsystem | Desktop applications @@ -139,6 +148,7 @@ The names of the settings can be configured using the following parameters: [`leptos_fluent!`]: https://mondeja.github.io/leptos-fluent/leptos_fluent.html [local storage]: https://developer.mozilla.org/docs/Web/API/Window/localStorage +[session storage]: https://developer.mozilla.org/docs/Web/API/Window/sessionStorage [`navigator.languages`]: https://developer.mozilla.org/docs/Web/API/Navigator/languages [`Accept-Language`]: https://developer.mozilla.org/docs/Web/HTTP/Headers/Accept-Language [Cookie]: https://developer.mozilla.org/docs/Web/API/Document/cookie diff --git a/examples/csr-complete/src/lib.rs b/examples/csr-complete/src/lib.rs index 97158da3..f2eb86ac 100644 --- a/examples/csr-complete/src/lib.rs +++ b/examples/csr-complete/src/lib.rs @@ -33,6 +33,11 @@ fn I18n(children: Children) -> impl IntoView { initial_language_from_localstorage: true, initial_language_from_localstorage_to_cookie: true, set_language_to_localstorage: true, + sessionstorage_key: "language", + initial_language_from_sessionstorage: true, + initial_language_from_sessionstorage_to_cookie: true, + initial_language_from_sessionstorage_to_localstorage: true, + set_language_to_sessionstorage: true, initial_language_from_navigator: true, initial_language_from_navigator_to_cookie: true, initial_language_from_navigator_to_localstorage: true, @@ -54,11 +59,9 @@ fn LanguageSelector() -> impl IntoView { view! {

{move_tr!("select-a-language")}

- {move || { expect_i18n().languages.iter().map(|lang| render_language(lang)).collect::>() }} -