From 13ef5bef00637111bca394bd0574fab327f15d9f Mon Sep 17 00:00:00 2001 From: Baptistemontan Date: Tue, 10 Dec 2024 22:31:42 +0100 Subject: [PATCH 01/13] split routing in it's own crate --- Cargo.toml | 22 +++++++- leptos_i18n/Cargo.toml | 21 ++++---- leptos_i18n/src/context.rs | 22 ++------ leptos_i18n/src/fetch_locale.rs | 44 +++------------ leptos_i18n/src/lib.rs | 5 +- leptos_i18n/src/macros.rs | 12 ----- leptos_i18n_build/Cargo.toml | 6 +-- leptos_i18n_build/src/lib.rs | 2 +- leptos_i18n_macro/Cargo.toml | 5 +- leptos_i18n_macro/src/load_locales/mod.rs | 54 ++----------------- leptos_i18n_parser/Cargo.toml | 5 +- leptos_i18n_parser/src/parse_locales/error.rs | 6 +-- .../src/parse_locales/plurals.rs | 4 +- leptos_i18n_router/.gitignore | 2 + leptos_i18n_router/Cargo.toml | 25 +++++++++ leptos_i18n_router/src/components.rs | 33 ++++++++++++ leptos_i18n_router/src/lib.rs | 31 +++++++++++ .../src/routing.rs | 26 ++++----- 18 files changed, 166 insertions(+), 159 deletions(-) create mode 100644 leptos_i18n_router/.gitignore create mode 100644 leptos_i18n_router/Cargo.toml create mode 100644 leptos_i18n_router/src/components.rs create mode 100644 leptos_i18n_router/src/lib.rs rename {leptos_i18n => leptos_i18n_router}/src/routing.rs (99%) diff --git a/Cargo.toml b/Cargo.toml index 42126f11..447dd02b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "tests/json", "tests/common", "tests/namespaces", + "leptos_i18n_router", ] exclude = ["examples", "tests"] @@ -19,5 +20,24 @@ version = "0.5.0-rc1" leptos_i18n_macro = { path = "./leptos_i18n_macro", default-features = false, version = "=0.5.0-rc1" } leptos_i18n_parser = { path = "./leptos_i18n_parser", default-features = false, version = "=0.5.0-rc1" } leptos_i18n = { path = "./leptos_i18n", version = "0.5.0-rc1" } -tests_common = { path = "./tests/common", version = "0.1.0" } +leptos_i18n_router = { path = "./leptos_i18n_router", version = "0.5.0-rc1" } + +# leptos leptos = { version = "0.7.0-rc1" } +leptos_router = { version = "0.7.0-rc1" } +leptos_meta = { version = "0.7.0-rc1" } + +# icu +icu_locid = { version = "1.5" } +icu_provider = { version = "1.5" } +fixed_decimal = { version = "0.5" } +icu_datagen = { version = "1.5" } +icu_plurals = { version = "1.5", default-features = false } +icu_datetime = { version = "1.5", default-features = false } +icu_calendar = { version = "1.5", default-features = false } +icu_list = { version = "1.5", default-features = false } +icu_decimal = { version = "1.5", default-features = false } +icu_locid_transform = { version = "1.5", default-features = false } + +# internal use +tests_common = { path = "./tests/common", version = "0.1.0" } diff --git a/leptos_i18n/Cargo.toml b/leptos_i18n/Cargo.toml index 0dc58a1c..f2d0cf83 100644 --- a/leptos_i18n/Cargo.toml +++ b/leptos_i18n/Cargo.toml @@ -17,19 +17,17 @@ leptos-use = { version = "0.14.0-rc1", default-features = false, features = [ ] } leptos_i18n_macro = { workspace = true } leptos = { workspace = true } -leptos_meta = { version = "0.7.0-rc1" } -leptos_router = { version = "0.7.0-rc1" } +leptos_meta = { workspace = true } codee = "0.2" -# icu = { version = "1.5", features = ["sync"] } -icu_locid = { version = "1.5" } -icu_provider = { version = "1.5", optional = true, features = ["sync"] } -icu_plurals = { version = "1.5", optional = true, default-features = false } -icu_datetime = { version = "1.5", optional = true } -icu_calendar = { version = "1.5", optional = true } -icu_list = { version = "1.5", optional = true } -icu_decimal = { version = "1.5", optional = true } +icu_locid = { workspace = true } +icu_provider = { workspace = true, optional = true, features = ["sync"] } +icu_plurals = { workspace = true, optional = true } +icu_datetime = { workspace = true, optional = true } +icu_calendar = { workspace = true, optional = true } +icu_list = { workspace = true, optional = true } +icu_decimal = { workspace = true, optional = true } typed-builder = "0.20" -fixed_decimal = { version = "0.5", optional = true, features = ["ryu"] } +fixed_decimal = { workspace = true, optional = true, features = ["ryu"] } writeable = "0.5" serde = "1.0" wasm-bindgen = "0.2.93" @@ -86,7 +84,6 @@ ssr = [ "leptos/ssr", "leptos_meta/ssr", "leptos-use/ssr", - "leptos_router/ssr", "leptos_i18n_macro/ssr", ] experimental-islands = [ diff --git a/leptos_i18n/src/context.rs b/leptos_i18n/src/context.rs index 34dd0b40..89d0e956 100644 --- a/leptos_i18n/src/context.rs +++ b/leptos_i18n/src/context.rs @@ -166,10 +166,6 @@ where cookie_options: CookieOptions, /// Options to pass to `leptos_use::use_locales`. ssr_lang_header_getter: UseLocalesOptions, - /// Try to parse the locale from the URL pathname, expect the basepath. (default to `None`). - /// If `None` do nothing, if `Some(base_path)` strip the URL from `base_path` then expect to found a path segment that represent a locale. - /// This is usefull when using the `I18nRoute` with usage of the context outside the router. - parse_locale_from_path: Option>, } impl Default for I18nContextOptions<'_, L> { @@ -179,7 +175,6 @@ impl Default for I18nContextOptions<'_, L> { cookie_name: Cow::Borrowed(COOKIE_PREFERED_LANG), cookie_options: Default::default(), ssr_lang_header_getter: Default::default(), - parse_locale_from_path: None, } } } @@ -192,7 +187,6 @@ pub fn init_i18n_context_with_options(options: I18nContextOptions) cookie_name, cookie_options, ssr_lang_header_getter, - parse_locale_from_path, } = options; let (lang_cookie, set_lang_cookie) = if ENABLE_COOKIE && enable_cookie { leptos_use::use_cookie_with_options::(&cookie_name, cookie_options) @@ -201,11 +195,8 @@ pub fn init_i18n_context_with_options(options: I18nContextOptions) (lang_cookie.into(), set_lang_cookie) }; - let initial_locale = fetch_locale::fetch_locale( - lang_cookie.get_untracked(), - ssr_lang_header_getter, - parse_locale_from_path, - ); + let initial_locale = + fetch_locale::fetch_locale(lang_cookie.get_untracked(), ssr_lang_header_getter); init_context_inner::(set_lang_cookie, initial_locale) } @@ -277,7 +268,7 @@ fn init_subcontext_with_options( }; let fetch_locale_memo = - fetch_locale::fetch_locale(None, ssr_lang_header_getter.unwrap_or_default(), None); + fetch_locale::fetch_locale(None, ssr_lang_header_getter.unwrap_or_default()); let parent_locale = use_context::>().map(|ctx| ctx.get_locale_untracked()); @@ -456,7 +447,6 @@ fn provide_i18n_context_component_inner( cookie_name: Option>, cookie_options: Option>, ssr_lang_header_getter: Option, - parse_locale_from_path: Option>, children: impl FnOnce() -> Chil, ) -> impl IntoView { #[cfg(all(feature = "dynamic_load", feature = "hydrate", not(feature = "ssr")))] @@ -464,7 +454,7 @@ fn provide_i18n_context_component_inner( #[cfg(all(feature = "dynamic_load", feature = "ssr"))] let reg_ctx = crate::fetch_translations::RegisterCtx::::provide_context(); let options = fill_options!( - I18nContextOptions::::default().parse_locale_from_path(parse_locale_from_path), + I18nContextOptions::::default(), enable_cookie, cookie_name, cookie_options, @@ -501,7 +491,6 @@ pub fn provide_i18n_context_component( cookie_name: Option>, cookie_options: Option>, ssr_lang_header_getter: Option, - parse_locale_from_path: Option>, children: TypedChildren, ) -> impl IntoView { provide_i18n_context_component_inner( @@ -511,7 +500,6 @@ pub fn provide_i18n_context_component( cookie_name, cookie_options, ssr_lang_header_getter, - parse_locale_from_path, children.into_inner(), ) } @@ -523,7 +511,6 @@ pub fn provide_i18n_context_component_island( set_dir_attr_on_html: Option, enable_cookie: Option, cookie_name: Option>, - parse_locale_from_path: Option>, children: children::Children, ) -> impl IntoView { provide_i18n_context_component_inner::( @@ -533,7 +520,6 @@ pub fn provide_i18n_context_component_island( cookie_name, None, None, - parse_locale_from_path, children, ) } diff --git a/leptos_i18n/src/fetch_locale.rs b/leptos_i18n/src/fetch_locale.rs index 6683baa4..fdd203c5 100644 --- a/leptos_i18n/src/fetch_locale.rs +++ b/leptos_i18n/src/fetch_locale.rs @@ -1,44 +1,22 @@ -use std::borrow::Cow; - use leptos::prelude::*; -use leptos_router::location::{BrowserUrl, LocationProvider, RequestUrl}; use leptos_use::UseLocalesOptions; use crate::Locale; -pub fn fetch_locale( - current_cookie: Option, - options: UseLocalesOptions, - parse_locale_from_path: Option>, -) -> Memo { +pub fn fetch_locale(current_cookie: Option, options: UseLocalesOptions) -> Memo { let accepted_locales = leptos_use::use_locales_with_options(options); let accepted_locale = Memo::new(move |_| accepted_locales.with(|accepted| L::find_locale(accepted))); - let url_locale = get_locale_from_path::(parse_locale_from_path); - if cfg!(feature = "ssr") { - fetch_locale_ssr(current_cookie, accepted_locale, url_locale) + fetch_locale_ssr(current_cookie, accepted_locale) } else if cfg!(feature = "hydrate") { fetch_locale_hydrate(current_cookie, accepted_locale) } else { - fetch_locale_csr(current_cookie, accepted_locale, url_locale) + fetch_locale_csr(current_cookie, accepted_locale) } } -fn get_locale_from_path(parse_locale_from_path: Option>) -> Option { - let base_path = parse_locale_from_path?; - let url = if cfg!(feature = "ssr") { - let req = use_context::().expect("no RequestUrl provided"); - req.parse().expect("could not parse RequestUrl") - } else { - let location = BrowserUrl::new().expect("could not access browser navigation"); - location.as_url().get_untracked() - }; - - crate::routing::get_locale_from_path(url.path(), &base_path) -} - pub fn signal_once_then( start: T, then: Memo, @@ -64,12 +42,8 @@ pub fn signal_maybe_once_then( } // ssr fetch -fn fetch_locale_ssr( - current_cookie: Option, - accepted_locale: Memo, - url_locale: Option, -) -> Memo { - signal_maybe_once_then(url_locale.or(current_cookie), accepted_locale) +fn fetch_locale_ssr(current_cookie: Option, accepted_locale: Memo) -> Memo { + signal_maybe_once_then(current_cookie, accepted_locale) } // hydrate fetch @@ -90,10 +64,6 @@ fn fetch_locale_hydrate(current_cookie: Option, accepted_locale: M } // csr fetch -fn fetch_locale_csr( - current_cookie: Option, - accepted_locale: Memo, - url_locale: Option, -) -> Memo { - signal_maybe_once_then(url_locale.or(current_cookie), accepted_locale) +fn fetch_locale_csr(current_cookie: Option, accepted_locale: Memo) -> Memo { + signal_maybe_once_then(current_cookie, accepted_locale) } diff --git a/leptos_i18n/src/lib.rs b/leptos_i18n/src/lib.rs index d729c067..583daa3d 100644 --- a/leptos_i18n/src/lib.rs +++ b/leptos_i18n/src/lib.rs @@ -131,7 +131,7 @@ mod langid; mod locale_traits; mod macro_helpers; mod macros; -mod routing; +// mod routing; mod scopes; pub mod display; @@ -165,10 +165,10 @@ pub mod __private { pub mod fetch_translations { pub use crate::fetch_translations::*; } + // pub use crate::fetch_locale::get_locale_from_path_inner; #[cfg(feature = "plurals")] pub use crate::formatting::get_plural_rules; pub use crate::macro_helpers::*; - pub use crate::routing::{i18n_routing, make_i18n_segment, BaseRoute, I18nSegment}; pub use leptos_i18n_macro as macros_reexport; } @@ -208,7 +208,6 @@ pub mod reexports { pub use icu_locid as locid; } pub use leptos; - pub use leptos_router; pub use serde; pub use typed_builder; pub use wasm_bindgen; diff --git a/leptos_i18n/src/macros.rs b/leptos_i18n/src/macros.rs index 11689aac..9c29b64d 100644 --- a/leptos_i18n/src/macros.rs +++ b/leptos_i18n/src/macros.rs @@ -944,15 +944,3 @@ macro_rules! tu_plural_ordinal { $crate::__private::macros_reexport::tu_plural_ordinal!{$($tt)*} }; } - -/// Create a route segment that is possible to define based on a locale. -/// -/// ```rust, ignore -/// -/// ``` -#[macro_export] -macro_rules! i18n_path { - ($t:ty, $func:expr) => {{ - leptos_i18n::__private::make_i18n_segment::<$t, _>($func) - }}; -} diff --git a/leptos_i18n_build/Cargo.toml b/leptos_i18n_build/Cargo.toml index 1f1ffa53..09517edd 100644 --- a/leptos_i18n_build/Cargo.toml +++ b/leptos_i18n_build/Cargo.toml @@ -10,9 +10,9 @@ readme = "../README.md" [dependencies] leptos_i18n_parser = { workspace = true } -icu_datagen = { version = "1.5" } -icu = { version = "1.5" } -icu_provider = { version = "1.5" } +icu_datagen = { workspace = true } +icu_provider = { workspace = true } +icu_locid = { workspace = true } [features] default = ["json_files"] diff --git a/leptos_i18n_build/src/lib.rs b/leptos_i18n_build/src/lib.rs index 77adc2f3..87845cf7 100644 --- a/leptos_i18n_build/src/lib.rs +++ b/leptos_i18n_build/src/lib.rs @@ -8,10 +8,10 @@ use std::path::PathBuf; use std::rc::Rc; pub use datakey::Options; -use icu::locid::LanguageIdentifier; use icu_datagen::baked_exporter::BakedExporter; use icu_datagen::prelude::DataKey; use icu_datagen::{DatagenDriver, DatagenProvider}; +use icu_locid::LanguageIdentifier; use icu_provider::DataError; use leptos_i18n_parser::parse_locales; use leptos_i18n_parser::parse_locales::error::Result; diff --git a/leptos_i18n_macro/Cargo.toml b/leptos_i18n_macro/Cargo.toml index ad17f44f..864786bd 100644 --- a/leptos_i18n_macro/Cargo.toml +++ b/leptos_i18n_macro/Cargo.toml @@ -21,8 +21,9 @@ proc-macro2 = "1" quote = "1" syn = "2.0" toml = "0.8" -icu = "1.5" -fixed_decimal = { version = "0.5", features = ["ryu"] } +icu_locid = { workspace = true } +icu_locid_transform = { workspace = true, features = ["compiled_data"] } +fixed_decimal = { workspace = true, features = ["ryu"] } json5 = { version = "0.4", optional = true } leptos_i18n_parser = { workspace = true, features = ["quote"] } diff --git a/leptos_i18n_macro/src/load_locales/mod.rs b/leptos_i18n_macro/src/load_locales/mod.rs index 98f11271..08672237 100644 --- a/leptos_i18n_macro/src/load_locales/mod.rs +++ b/leptos_i18n_macro/src/load_locales/mod.rs @@ -9,7 +9,7 @@ pub mod ranges; pub mod tracking; pub mod warning; -use icu::locid::LanguageIdentifier; +use icu_locid::LanguageIdentifier; use interpolate::Interpolation; use leptos_i18n_parser::{ parse_locales::{ @@ -140,11 +140,6 @@ fn load_locales_inner( /// Specify a name for the cookie, default to the library default. #[prop(optional, into)] cookie_name: Option>, - /// Try to parse the locale from the URL pathname, expect the basepath. (default to `None`). - /// If `None` do nothing, if `Some(base_path)` strip the URL from `base_path` then expect to found a path segment that represent a locale. - /// This is usefull when using the `I18nRoute` with usage of the context outside the router. - #[prop(optional, into)] - parse_locale_from_path: Option>, children: Children ) -> impl IntoView { l_i18n_crate::context::provide_i18n_context_component_island::<#enum_ident>( @@ -152,7 +147,6 @@ fn load_locales_inner( set_dir_attr_on_html, enable_cookie, cookie_name, - parse_locale_from_path, children ) } @@ -206,11 +200,6 @@ fn load_locales_inner( /// Options for getting the Accept-Language header, see `leptos_use::UseLocalesOptions`. #[prop(optional)] ssr_lang_header_getter: Option, - /// Try to parse the locale from the URL pathname, expect the basepath. (default to `None`). - /// If `None` do nothing, if `Some(base_path)` strip the URL from `base_path` then expect to found a path segment that represent a locale. - /// This is usefull when using the `I18nRoute` with usage of the context outside the router. - #[prop(optional, into)] - parse_locale_from_path: Option>, children: TypedChildren ) -> impl IntoView { l_i18n_crate::context::provide_i18n_context_component::<#enum_ident, Chil>( @@ -220,7 +209,6 @@ fn load_locales_inner( cookie_name, cookie_options, ssr_lang_header_getter, - parse_locale_from_path, children ) } @@ -293,41 +281,7 @@ fn load_locales_inner( #providers } - mod routing { - use super::{l_i18n_crate, #enum_ident}; - use l_i18n_crate::reexports::leptos_router; - use l_i18n_crate::reexports::leptos; - use leptos::prelude::IntoView; - use leptos_router::{SsrMode, MatchNestedRoutes, ChooseView, components::RouteChildren}; - - #[l_i18n_crate::reexports::leptos::component(transparent)] - #[allow(non_snake_case)] - pub fn I18nRoute( - /// The base path of this application. - /// If you setup your i18n route such that the path is `/foo/:locale/bar`, - /// the expected base path is `"foo"`, `"/foo"`, `"foo/"` or `"/foo/"`. - /// Defaults to `"/"`. - #[prop(default = "/")] - base_path: &'static str, - /// The view that should be shown when this route is matched. This can be any function - /// that returns a type that implements [`IntoView`] (like `|| view! {

"Show this"

})` - /// or `|| view! { ` } or even, for a component with no props, `MyComponent`). - /// If you use nested routes you can just set it to `view=Outlet` - view: View, - /// The mode that this route prefers during server-side rendering. Defaults to out-of-order streaming. - #[prop(optional)] - ssr: SsrMode, - /// `children` may be empty or include nested routes. - children: RouteChildren, - ) -> impl MatchNestedRoutes + 'static + Send + Sync + Clone - where View: ChooseView + 'static + Send + Sync, Chil: MatchNestedRoutes + 'static + Send + Sync + Clone, - { - l_i18n_crate::__private::i18n_routing::<#enum_ident, View, Chil>(base_path, children, ssr, view) - } - } - pub use providers::{I18nContextProvider, I18nSubContextProvider}; - pub use routing::I18nRoute; pub use l_i18n_crate::Locale as I18nLocaleTrait; #macros_reexport @@ -425,7 +379,7 @@ fn create_locales_enum( } else { quote!() }; - let ld = icu::locid_transform::LocaleDirectionality::new(); + let ld = icu_locid_transform::LocaleDirectionality::new(); let locids = locales .iter() @@ -440,8 +394,8 @@ fn create_locales_enum( let direction_match_arms = locids.iter().map(|(locale, locid)| { let dir = match ld.get(locid) { - Some(icu::locid_transform::Direction::LeftToRight) => quote!(LeftToRight), - Some(icu::locid_transform::Direction::RightToLeft) => quote!(RightToLeft), + Some(icu_locid_transform::Direction::LeftToRight) => quote!(LeftToRight), + Some(icu_locid_transform::Direction::RightToLeft) => quote!(RightToLeft), _ => quote!(Auto), }; diff --git a/leptos_i18n_parser/Cargo.toml b/leptos_i18n_parser/Cargo.toml index 853440a2..1c346815 100644 --- a/leptos_i18n_parser/Cargo.toml +++ b/leptos_i18n_parser/Cargo.toml @@ -9,12 +9,13 @@ description = "parser for the leptos_i18n crate" readme = "../README.md" [dependencies] -icu = "1.5" +icu_locid = { workspace = true } +icu_plurals = { workspace = true, features = ["compiled_data"] } serde = { version = "1", features = ["rc"] } serde_json = { version = "1" } serde_yaml = { version = "0.9" } toml = "0.8" -fixed_decimal = { version = "0.5", features = ["ryu"] } +fixed_decimal = { workspace = true, features = ["ryu"] } json5 = { version = "0.4" } quote = { version = "1", optional = true } syn = { version = "2.0", optional = true } diff --git a/leptos_i18n_parser/src/parse_locales/error.rs b/leptos_i18n_parser/src/parse_locales/error.rs index a5c3964b..7a9c7a1a 100644 --- a/leptos_i18n_parser/src/parse_locales/error.rs +++ b/leptos_i18n_parser/src/parse_locales/error.rs @@ -1,7 +1,7 @@ +use icu_locid::Error as LocidError; +use icu_plurals::Error as PluralsError; use std::{collections::BTreeSet, fmt::Display, num::TryFromIntError, path::PathBuf, rc::Rc}; -use icu::{locid::Error as ParserError, plurals::Error as PluralsError}; - use super::{locale::SerdeError, ranges::RangeType}; use crate::utils::key::{Key, KeyPath}; @@ -9,7 +9,7 @@ use crate::utils::key::{Key, KeyPath}; pub enum Error { InvalidLocale { locale: Rc, - err: ParserError, + err: LocidError, }, PluralRulesError(PluralsError), CargoDirEnvNotPresent(std::env::VarError), diff --git a/leptos_i18n_parser/src/parse_locales/plurals.rs b/leptos_i18n_parser/src/parse_locales/plurals.rs index 67c14b4d..246130ba 100644 --- a/leptos_i18n_parser/src/parse_locales/plurals.rs +++ b/leptos_i18n_parser/src/parse_locales/plurals.rs @@ -4,7 +4,7 @@ use std::{ }; use fixed_decimal::{FixedDecimal, FloatPrecision}; -use icu::plurals::{PluralCategory, PluralOperands, PluralRuleType as IcuRuleType, PluralRules}; +use icu_plurals::{PluralCategory, PluralOperands, PluralRuleType as IcuRuleType, PluralRules}; use super::{ error::{Error, Result}, @@ -82,7 +82,7 @@ impl Plurals { let locale = locale .name - .parse::() + .parse::() .map_err(|err| Error::InvalidLocale { locale: locale.name.clone(), err, diff --git a/leptos_i18n_router/.gitignore b/leptos_i18n_router/.gitignore new file mode 100644 index 00000000..4fffb2f8 --- /dev/null +++ b/leptos_i18n_router/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/leptos_i18n_router/Cargo.toml b/leptos_i18n_router/Cargo.toml new file mode 100644 index 00000000..ed5067d8 --- /dev/null +++ b/leptos_i18n_router/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "leptos_i18n_router" +version = { workspace = true } +edition = "2021" +authors = ["Baptiste de Montangon"] +license = "MIT" +repository = "https://github.com/Baptistemontan/leptos_i18n" +description = "Translations integration helper for the Leptos web framework" +readme = "../README.md" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +leptos_i18n = { workspace = true } +leptos = { workspace = true } +leptos_router = { workspace = true } + +[features] +ssr = ["leptos_router/ssr", "leptos_i18n/ssr"] + + +[package.metadata.cargo-all-features] +denylist = [] +skip_feature_sets = [] +always_include_features = [] diff --git a/leptos_i18n_router/src/components.rs b/leptos_i18n_router/src/components.rs new file mode 100644 index 00000000..ab3e4973 --- /dev/null +++ b/leptos_i18n_router/src/components.rs @@ -0,0 +1,33 @@ +use std::marker::PhantomData; + +use leptos::component; +use leptos_i18n::Locale; +use leptos_router::{components::RouteChildren, ChooseView, MatchNestedRoutes, SsrMode}; + +#[component] +pub fn I18nRoute( + /// The base path of this application. + /// If you setup your i18n route such that the path is `/foo/:locale/bar`, + /// the expected base path is `"foo"`, `"/foo"`, `"foo/"` or `"/foo/"`. + /// Defaults to `"/"`. + #[prop(default = "/")] + base_path: &'static str, + /// The view that should be shown when this route is matched. This can be any function + /// that returns a type that implements [`IntoView`] (like `|| view! {

"Show this"

})` + /// or `|| view! { ` } or even, for a component with no props, `MyComponent`). + /// If you use nested routes you can just set it to `view=Outlet` + view: View, + /// The mode that this route prefers during server-side rendering. Defaults to out-of-order streaming + #[prop(optional)] + ssr: SsrMode, + /// `children` may be empty or include nested routes. + children: RouteChildren, + #[prop(optional)] _marker: PhantomData, +) -> impl MatchNestedRoutes + 'static + Send + Sync + Clone +where + View: ChooseView + 'static + Send + Sync, + Chil: MatchNestedRoutes + 'static + Send + Sync + Clone, + L: Locale, +{ + crate::routing::i18n_routing::(base_path, children, ssr, view) +} diff --git a/leptos_i18n_router/src/lib.rs b/leptos_i18n_router/src/lib.rs new file mode 100644 index 00000000..9d36a867 --- /dev/null +++ b/leptos_i18n_router/src/lib.rs @@ -0,0 +1,31 @@ +#![deny(missing_docs)] +#![forbid(unsafe_code)] +#![deny(warnings)] +//! edzdz +//! +//! +//! +//! +//! + +mod components; +mod routing; + +pub use components::I18nRoute; + +/// Create a route segment that is possible to define based on a locale. +/// +/// ```rust, ignore +/// +/// ``` +#[macro_export] +macro_rules! i18n_path { + ($t:ty, $func:expr) => {{ + $crate::__private::make_i18n_segment::<$t, _>($func) + }}; +} + +#[doc(hidden)] +pub mod __private { + pub use crate::routing::make_i18n_segment; +} diff --git a/leptos_i18n/src/routing.rs b/leptos_i18n_router/src/routing.rs similarity index 99% rename from leptos_i18n/src/routing.rs rename to leptos_i18n_router/src/routing.rs index ca2e3f98..1fc2f4a6 100644 --- a/leptos_i18n/src/routing.rs +++ b/leptos_i18n_router/src/routing.rs @@ -16,7 +16,7 @@ use leptos_router::{ PathSegment, PossibleRouteMatch, SsrMode, StaticSegment, }; -use crate::{use_i18n_context, I18nContext, Locale}; +use leptos_i18n::{use_i18n_context, I18nContext, Locale}; // this whole file is a hack into `leptos_router`, it absolutely should'nt be used like that, but eh I'm a professional (or not.) @@ -81,6 +81,18 @@ fn match_path_segments(segments: &[&str], old_segments: &[PathSegment]) -> Optio segments_iter.next().is_none().then_some(optionals) } +fn get_locale_from_path(path: &str, base_path: &str) -> Option { + let base_path = base_path.trim_start_matches('/'); + let stripped_path = path + .trim_start_matches('/') + .strip_prefix(base_path)? + .trim_start_matches('/'); + L::get_all() + .iter() + .copied() + .find(|l| stripped_path.starts_with(l.as_str())) +} + fn construct_path_segments<'b, 'p: 'b>( segments: &[&'p str], new_segments: &'p [PathSegment], @@ -313,18 +325,6 @@ fn correct_locale_prefix_effect( } } -pub(crate) fn get_locale_from_path(path: &str, base_path: &str) -> Option { - let base_path = base_path.trim_start_matches('/'); - let stripped_path = path - .trim_start_matches('/') - .strip_prefix(base_path)? - .trim_start_matches('/'); - L::get_all() - .iter() - .copied() - .find(|l| stripped_path.starts_with(l.as_str())) -} - fn check_history_change( i18n: I18nContext, base_path: &'static str, From 6eaae3c1bc20badad86326a66d6d6a41619748f7 Mon Sep 17 00:00:00 2001 From: Baptistemontan Date: Tue, 10 Dec 2024 23:16:24 +0100 Subject: [PATCH 02/13] update examples --- docs/book/src/usage/07_router.md | 20 ++++++++++---------- examples/csr/routing_csr/Cargo.toml | 1 + examples/csr/routing_csr/src/app.rs | 5 +++-- examples/ssr/routing_ssr/Cargo.toml | 2 ++ examples/ssr/routing_ssr/src/app.rs | 5 +++-- leptos_i18n_router/Cargo.toml | 2 +- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/docs/book/src/usage/07_router.md b/docs/book/src/usage/07_router.md index f4855a1c..a9080f9a 100644 --- a/docs/book/src/usage/07_router.md +++ b/docs/book/src/usage/07_router.md @@ -13,10 +13,10 @@ use leptos_router::*; view! { - + view=Outlet> - + > } @@ -70,9 +70,9 @@ You can use inside the `i18nRoute` the `i18n_path!` to create localized path seg ```rust use leptos_i18n::i18n_path; - + view=Outlet> - +> ``` If you have `segment_path_name = "search"` for english, and `segment_path_name = "rechercher"` for french, the `I18nRoute` will produce 3 paths: @@ -93,9 +93,9 @@ view! { - + view=Outlet> - + > @@ -112,12 +112,12 @@ view! { - view=|| view! { }> - + > @@ -132,9 +132,9 @@ view! { - + view=Outlet> - + > diff --git a/examples/csr/routing_csr/Cargo.toml b/examples/csr/routing_csr/Cargo.toml index a2176d8a..19e8d643 100644 --- a/examples/csr/routing_csr/Cargo.toml +++ b/examples/csr/routing_csr/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" leptos = { version = "0.7.0-rc1", features = ["csr"] } leptos_meta = { version = "0.7.0-rc1" } leptos_i18n = { path = "../../../leptos_i18n", features = ["csr"] } +leptos_i18n_router = { path = "../../../leptos_i18n_router" } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1" } wasm-bindgen = { version = "0.2" } diff --git a/examples/csr/routing_csr/src/app.rs b/examples/csr/routing_csr/src/app.rs index be241b9b..3be33e25 100644 --- a/examples/csr/routing_csr/src/app.rs +++ b/examples/csr/routing_csr/src/app.rs @@ -1,5 +1,6 @@ use crate::i18n::*; use leptos::prelude::*; +use leptos_i18n_router::I18nRoute; use leptos_router::{components::*, path}; #[component] @@ -11,10 +12,10 @@ pub fn App() -> impl IntoView { - }> + view=|| view! { }> - + >
diff --git a/examples/ssr/routing_ssr/Cargo.toml b/examples/ssr/routing_ssr/Cargo.toml index de368d95..8b82eb65 100644 --- a/examples/ssr/routing_ssr/Cargo.toml +++ b/examples/ssr/routing_ssr/Cargo.toml @@ -16,6 +16,7 @@ leptos_axum = { version = "0.7.0-rc1", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", ] } +leptos_i18n_router = { path = "../../../leptos_i18n_router" } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } wasm-bindgen = { version = "0.2", optional = true } @@ -45,6 +46,7 @@ ssr = [ "leptos_meta/ssr", "leptos_i18n/axum", "leptos_router/ssr", + "leptos_i18n_router/ssr", ] [package.metadata.leptos-i18n] diff --git a/examples/ssr/routing_ssr/src/app.rs b/examples/ssr/routing_ssr/src/app.rs index f22b797a..2fd13758 100644 --- a/examples/ssr/routing_ssr/src/app.rs +++ b/examples/ssr/routing_ssr/src/app.rs @@ -1,5 +1,6 @@ use crate::i18n::*; use leptos::prelude::*; +use leptos_i18n_router::I18nRoute; use leptos_router::{components::*, path}; #[component] @@ -11,10 +12,10 @@ pub fn App() -> impl IntoView { - }> + view=|| view! { }> - + >
diff --git a/leptos_i18n_router/Cargo.toml b/leptos_i18n_router/Cargo.toml index ed5067d8..ea7aef0b 100644 --- a/leptos_i18n_router/Cargo.toml +++ b/leptos_i18n_router/Cargo.toml @@ -16,7 +16,7 @@ leptos = { workspace = true } leptos_router = { workspace = true } [features] -ssr = ["leptos_router/ssr", "leptos_i18n/ssr"] +ssr = ["leptos/ssr", "leptos_router/ssr", "leptos_i18n/ssr"] [package.metadata.cargo-all-features] From 0d9bc5842833bae6a8062a468885d25b30d003d7 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 11 Dec 2024 15:16:52 +0100 Subject: [PATCH 03/13] update to leptos v0.7 --- Cargo.toml | 6 +++--- examples/csr/counter/Cargo.toml | 4 ++-- examples/csr/counter_icu_datagen/Cargo.toml | 4 ++-- examples/csr/counter_plurals/Cargo.toml | 4 ++-- examples/csr/counter_ranges/Cargo.toml | 4 ++-- examples/csr/interpolation/Cargo.toml | 4 ++-- examples/csr/namespaces/Cargo.toml | 4 ++-- examples/csr/routing_csr/Cargo.toml | 6 +++--- examples/csr/subcontext/Cargo.toml | 4 ++-- examples/csr/subkeys/Cargo.toml | 4 ++-- examples/csr/yaml/Cargo.toml | 4 ++-- examples/dynamic_load/hello_world_actix/Cargo.toml | 6 +++--- examples/dynamic_load/hello_world_axum/Cargo.toml | 4 ++-- examples/dynamic_load/namespaces/Cargo.toml | 4 ++-- examples/ssr/axum_island/Cargo.toml | 6 +++--- examples/ssr/hello_world_actix/Cargo.toml | 6 +++--- examples/ssr/hello_world_axum/Cargo.toml | 6 +++--- examples/ssr/routing_ssr/Cargo.toml | 8 ++++---- examples/ssr/workspace/client/Cargo.toml | 6 +++--- examples/ssr/workspace/server/Cargo.toml | 6 +++--- leptos_i18n/Cargo.toml | 11 +++-------- tests/json5/Cargo.toml | 2 +- tests/yaml/Cargo.toml | 2 +- 23 files changed, 55 insertions(+), 60 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 447dd02b..8a85d8c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,9 +23,9 @@ leptos_i18n = { path = "./leptos_i18n", version = "0.5.0-rc1" } leptos_i18n_router = { path = "./leptos_i18n_router", version = "0.5.0-rc1" } # leptos -leptos = { version = "0.7.0-rc1" } -leptos_router = { version = "0.7.0-rc1" } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0" } +leptos_router = { version = "0.7.0" } +leptos_meta = { version = "0.7.0" } # icu icu_locid = { version = "1.5" } diff --git a/examples/csr/counter/Cargo.toml b/examples/csr/counter/Cargo.toml index 1dd35fe8..d35ebea6 100644 --- a/examples/csr/counter/Cargo.toml +++ b/examples/csr/counter/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", features = ["csr"] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1" } diff --git a/examples/csr/counter_icu_datagen/Cargo.toml b/examples/csr/counter_icu_datagen/Cargo.toml index 07dba1d0..9a6c0246 100644 --- a/examples/csr/counter_icu_datagen/Cargo.toml +++ b/examples/csr/counter_icu_datagen/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", default-features = false, features = [ "json_files", "csr", diff --git a/examples/csr/counter_plurals/Cargo.toml b/examples/csr/counter_plurals/Cargo.toml index fae1140f..4b9abd57 100644 --- a/examples/csr/counter_plurals/Cargo.toml +++ b/examples/csr/counter_plurals/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", features = ["csr", "plurals"] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1" } diff --git a/examples/csr/counter_ranges/Cargo.toml b/examples/csr/counter_ranges/Cargo.toml index 3a8edaf6..a6656d86 100644 --- a/examples/csr/counter_ranges/Cargo.toml +++ b/examples/csr/counter_ranges/Cargo.toml @@ -4,8 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", features = ["csr"] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1" } diff --git a/examples/csr/interpolation/Cargo.toml b/examples/csr/interpolation/Cargo.toml index 980ad8cc..d3494816 100644 --- a/examples/csr/interpolation/Cargo.toml +++ b/examples/csr/interpolation/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", features = ["csr"] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1" } diff --git a/examples/csr/namespaces/Cargo.toml b/examples/csr/namespaces/Cargo.toml index 82fdaf75..cac3c96d 100644 --- a/examples/csr/namespaces/Cargo.toml +++ b/examples/csr/namespaces/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", features = ["csr"] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1" } diff --git a/examples/csr/routing_csr/Cargo.toml b/examples/csr/routing_csr/Cargo.toml index 19e8d643..6ae0b582 100644 --- a/examples/csr/routing_csr/Cargo.toml +++ b/examples/csr/routing_csr/Cargo.toml @@ -6,15 +6,15 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", features = ["csr"] } leptos_i18n_router = { path = "../../../leptos_i18n_router" } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1" } wasm-bindgen = { version = "0.2" } -leptos_router = { version = "0.7.0-rc1" } +leptos_router = { version = "0.7.0" } [package.metadata.leptos-i18n] default = "en" diff --git a/examples/csr/subcontext/Cargo.toml b/examples/csr/subcontext/Cargo.toml index 08cfada5..6f24b412 100644 --- a/examples/csr/subcontext/Cargo.toml +++ b/examples/csr/subcontext/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", features = ["csr"] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1" } diff --git a/examples/csr/subkeys/Cargo.toml b/examples/csr/subkeys/Cargo.toml index 995f8aaf..88421f3b 100644 --- a/examples/csr/subkeys/Cargo.toml +++ b/examples/csr/subkeys/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", features = ["csr"] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1" } diff --git a/examples/csr/yaml/Cargo.toml b/examples/csr/yaml/Cargo.toml index 3bff3232..3f5f841b 100644 --- a/examples/csr/yaml/Cargo.toml +++ b/examples/csr/yaml/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.7.0-rc1", features = ["csr"] } -leptos_meta = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["csr"] } +leptos_meta = { version = "0.7.0" } leptos_i18n = { path = "../../../leptos_i18n", default-features = false, features = [ "csr", "cookie", diff --git a/examples/dynamic_load/hello_world_actix/Cargo.toml b/examples/dynamic_load/hello_world_actix/Cargo.toml index 6dc9c068..dcf6e01a 100644 --- a/examples/dynamic_load/hello_world_actix/Cargo.toml +++ b/examples/dynamic_load/hello_world_actix/Cargo.toml @@ -11,9 +11,9 @@ crate-type = ["cdylib", "rlib"] [dependencies] actix-files = { version = "0.6", optional = true } actix-web = { version = "4.4", optional = true, features = ["macros"] } -leptos = { version = "0.7.0-rc1" } -leptos_meta = { version = "0.7.0-rc1" } -leptos_actix = { version = "0.7.0-rc1", optional = true } +leptos = { version = "0.7.0" } +leptos_meta = { version = "0.7.0" } +leptos_actix = { version = "0.7.0", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", "dynamic_load", diff --git a/examples/dynamic_load/hello_world_axum/Cargo.toml b/examples/dynamic_load/hello_world_axum/Cargo.toml index a13f0c01..42ea1ff6 100644 --- a/examples/dynamic_load/hello_world_axum/Cargo.toml +++ b/examples/dynamic_load/hello_world_axum/Cargo.toml @@ -11,8 +11,8 @@ crate-type = ["cdylib", "rlib"] [dependencies] axum = { version = "0.7", optional = true } leptos = { version = "0.7.0-beta" } -leptos_meta = { version = "0.7.0-rc1" } -leptos_axum = { version = "0.7.0-rc1", optional = true } +leptos_meta = { version = "0.7.0" } +leptos_axum = { version = "0.7.0", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", "dynamic_load", diff --git a/examples/dynamic_load/namespaces/Cargo.toml b/examples/dynamic_load/namespaces/Cargo.toml index 7f0928cd..71d04dbc 100644 --- a/examples/dynamic_load/namespaces/Cargo.toml +++ b/examples/dynamic_load/namespaces/Cargo.toml @@ -11,8 +11,8 @@ crate-type = ["cdylib", "rlib"] [dependencies] axum = { version = "0.7", optional = true } leptos = { version = "0.7.0-beta" } -leptos_meta = { version = "0.7.0-rc1" } -leptos_axum = { version = "0.7.0-rc1", optional = true } +leptos_meta = { version = "0.7.0" } +leptos_axum = { version = "0.7.0", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", "dynamic_load", diff --git a/examples/ssr/axum_island/Cargo.toml b/examples/ssr/axum_island/Cargo.toml index aea0be7c..2960f477 100644 --- a/examples/ssr/axum_island/Cargo.toml +++ b/examples/ssr/axum_island/Cargo.toml @@ -10,9 +10,9 @@ crate-type = ["cdylib", "rlib"] [dependencies] axum = { version = "0.7", optional = true } -leptos = { version = "0.7.0-rc1", features = ["experimental-islands"] } -leptos_meta = { version = "0.7.0-rc1" } -leptos_axum = { version = "0.7.0-rc1", optional = true } +leptos = { version = "0.7.0", features = ["experimental-islands"] } +leptos_meta = { version = "0.7.0" } +leptos_axum = { version = "0.7.0", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", "experimental-islands", diff --git a/examples/ssr/hello_world_actix/Cargo.toml b/examples/ssr/hello_world_actix/Cargo.toml index c7ad42a0..5cd1b37c 100644 --- a/examples/ssr/hello_world_actix/Cargo.toml +++ b/examples/ssr/hello_world_actix/Cargo.toml @@ -11,9 +11,9 @@ crate-type = ["cdylib", "rlib"] [dependencies] actix-files = { version = "0.6", optional = true } actix-web = { version = "4.4", optional = true, features = ["macros"] } -leptos = { version = "0.7.0-rc1" } -leptos_meta = { version = "0.7.0-rc1" } -leptos_actix = { version = "0.7.0-rc1", optional = true } +leptos = { version = "0.7.0" } +leptos_meta = { version = "0.7.0" } +leptos_actix = { version = "0.7.0", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", ] } diff --git a/examples/ssr/hello_world_axum/Cargo.toml b/examples/ssr/hello_world_axum/Cargo.toml index 1d93f51a..8899540c 100644 --- a/examples/ssr/hello_world_axum/Cargo.toml +++ b/examples/ssr/hello_world_axum/Cargo.toml @@ -10,9 +10,9 @@ crate-type = ["cdylib", "rlib"] [dependencies] axum = { version = "0.7", optional = true } -leptos = { version = "0.7.0-rc1" } -leptos_meta = { version = "0.7.0-rc1" } -leptos_axum = { version = "0.7.0-rc1", optional = true } +leptos = { version = "0.7.0" } +leptos_meta = { version = "0.7.0" } +leptos_axum = { version = "0.7.0", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", ] } diff --git a/examples/ssr/routing_ssr/Cargo.toml b/examples/ssr/routing_ssr/Cargo.toml index 8b82eb65..9fba709d 100644 --- a/examples/ssr/routing_ssr/Cargo.toml +++ b/examples/ssr/routing_ssr/Cargo.toml @@ -10,9 +10,9 @@ crate-type = ["cdylib", "rlib"] [dependencies] axum = { version = "0.7", optional = true } -leptos = { version = "0.7.0-rc1" } -leptos_meta = { version = "0.7.0-rc1" } -leptos_axum = { version = "0.7.0-rc1", optional = true } +leptos = { version = "0.7.0" } +leptos_meta = { version = "0.7.0" } +leptos_axum = { version = "0.7.0", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", ] } @@ -26,7 +26,7 @@ log = "0.4" tower = { version = "0.5.1", optional = true } tower-http = { version = "0.6.1", features = ["fs"], optional = true } -leptos_router = { version = "0.7.0-rc1" } +leptos_router = { version = "0.7.0" } [features] default = ["hydrate", "ssr"] diff --git a/examples/ssr/workspace/client/Cargo.toml b/examples/ssr/workspace/client/Cargo.toml index f236d861..a9bdff64 100644 --- a/examples/ssr/workspace/client/Cargo.toml +++ b/examples/ssr/workspace/client/Cargo.toml @@ -10,9 +10,9 @@ crate-type = ["cdylib", "rlib"] [dependencies] actix-web = { version = "4.4", optional = true, features = ["macros"] } -leptos = { version = "0.7.0-rc1" } -leptos_meta = { version = "0.7.0-rc1" } -leptos_actix = { version = "0.7.0-rc1", optional = true } +leptos = { version = "0.7.0" } +leptos_meta = { version = "0.7.0" } +leptos_actix = { version = "0.7.0", optional = true } leptos_i18n = { workspace = true, features = ["track_locale_files"] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } diff --git a/examples/ssr/workspace/server/Cargo.toml b/examples/ssr/workspace/server/Cargo.toml index 14671ef6..3d77ad9f 100644 --- a/examples/ssr/workspace/server/Cargo.toml +++ b/examples/ssr/workspace/server/Cargo.toml @@ -8,8 +8,8 @@ edition = "2021" [dependencies] actix-files = "0.6" actix-web = { version = "4.4", features = ["macros"] } -leptos = { version = "0.7.0-rc1", features = ["ssr"] } -leptos_meta = { version = "0.7.0-rc1", features = ["ssr"] } -leptos_actix = { version = "0.7.0-rc1" } +leptos = { version = "0.7.0", features = ["ssr"] } +leptos_meta = { version = "0.7.0", features = ["ssr"] } +leptos_actix = { version = "0.7.0" } serde = { version = "1", features = ["derive"] } client = { path = "../client", default-features = false, features = ["ssr"] } diff --git a/leptos_i18n/Cargo.toml b/leptos_i18n/Cargo.toml index f2d0cf83..66452040 100644 --- a/leptos_i18n/Cargo.toml +++ b/leptos_i18n/Cargo.toml @@ -11,7 +11,7 @@ readme = "../README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos-use = { version = "0.14.0-rc1", default-features = false, features = [ +leptos-use = { version = "0.14.0", default-features = false, features = [ "use_locales", "use_cookie", ] } @@ -30,7 +30,6 @@ typed-builder = "0.20" fixed_decimal = { workspace = true, optional = true, features = ["ryu"] } writeable = "0.5" serde = "1.0" -wasm-bindgen = "0.2.93" async-once-cell = { version = "0.5.3", optional = true } js-sys = { version = "0.3.70", optional = true } serde-wasm-bindgen = { version = "0.6.5", optional = true } @@ -38,10 +37,6 @@ futures = { version = "0.3.30", optional = true } noop-waker = { version = "0.1.0", optional = true } default-struct-builder = "0.5" -# FIXME -leptos_actix = { version = "0.7.0-rc1", optional = true } -leptos_axum = { version = "0.7.0-rc1", optional = true } - [features] default = ["cookie", "json_files", "icu_compiled_data"] cookie = [] @@ -71,8 +66,8 @@ format_nums = [ "dep:icu_provider", "leptos_i18n_macro/format_nums", ] -actix = ["ssr", "leptos-use/actix", "dep:leptos_actix"] -axum = ["ssr", "leptos-use/axum", "dep:leptos_axum"] +actix = ["ssr", "leptos-use/actix"] +axum = ["ssr", "leptos-use/axum"] hydrate = [ "leptos/hydrate", "leptos_i18n_macro/hydrate", diff --git a/tests/json5/Cargo.toml b/tests/json5/Cargo.toml index 96d047ae..278a970e 100644 --- a/tests/json5/Cargo.toml +++ b/tests/json5/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib", "rlib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.7.0-rc1", features = ["ssr"] } +leptos = { version = "0.7.0", features = ["ssr"] } tests_common = { path = "../common" } leptos_i18n = { path = "../../leptos_i18n", default-features = false, features = [ "json5_files", diff --git a/tests/yaml/Cargo.toml b/tests/yaml/Cargo.toml index bbdaa48e..5fbf6cba 100644 --- a/tests/yaml/Cargo.toml +++ b/tests/yaml/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib", "rlib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -leptos = { version = "0.7.0-rc1", features = ["ssr"] } +leptos = { version = "0.7.0", features = ["ssr"] } tests_common = { path = "../common" } leptos_i18n = { path = "../../leptos_i18n", default-features = false, features = [ "yaml_files", From 383efa3caa43df45999b71dbdf2a86dace9014b9 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 11 Dec 2024 15:19:00 +0100 Subject: [PATCH 04/13] replaced "experimental-islands" by "islands" --- docs/book/src/06_features.md | 2 +- docs/book/src/usage/02_context.md | 2 +- examples/dynamic_load/axum_island/Cargo.toml | 4 ++-- examples/ssr/axum_island/Cargo.toml | 4 ++-- leptos_i18n/Cargo.toml | 6 +++--- leptos_i18n/src/lib.rs | 4 ++-- leptos_i18n_macro/Cargo.toml | 2 +- leptos_i18n_macro/src/load_locales/mod.rs | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/book/src/06_features.md b/docs/book/src/06_features.md index 1203515e..5f6071bb 100644 --- a/docs/book/src/06_features.md +++ b/docs/book/src/06_features.md @@ -26,7 +26,7 @@ This feature must be enabled when building the client in csr mode Set a cookie to remember the last chosen locale. -#### `experimental-islands` +#### `islands` This feature is, as it's name says, experimental. This make this lib somewhat usable when using `islands` with Leptos. diff --git a/docs/book/src/usage/02_context.md b/docs/book/src/usage/02_context.md index 95647feb..f3f1d0d8 100644 --- a/docs/book/src/usage/02_context.md +++ b/docs/book/src/usage/02_context.md @@ -126,7 +126,7 @@ The `I18nContextProvider` component accept multiple props, all optionnal (except ## Note on island -If you use the `experimental-islands` feature from Leptos the `I18nContextProvider` loose two props: `cookie_options` and `ssr_lang_header_getter`, because they are not serializable. If you need them you can use the `init_context_with_options` function and provide the context yourself: +If you use the `islands` feature from Leptos the `I18nContextProvider` loose two props: `cookie_options` and `ssr_lang_header_getter`, because they are not serializable. If you need them you can use the `init_context_with_options` function and provide the context yourself: ```rust use leptos_i18n::init_i18n_context_with_options; diff --git a/examples/dynamic_load/axum_island/Cargo.toml b/examples/dynamic_load/axum_island/Cargo.toml index f7098c36..1a0945c8 100644 --- a/examples/dynamic_load/axum_island/Cargo.toml +++ b/examples/dynamic_load/axum_island/Cargo.toml @@ -10,12 +10,12 @@ crate-type = ["cdylib", "rlib"] [dependencies] axum = { version = "0.7", optional = true } -leptos = { version = "0.7.0-beta", features = ["experimental-islands"] } +leptos = { version = "0.7.0-beta", features = ["islands"] } leptos_meta = { version = "0.7.0-beta" } leptos_axum = { version = "0.7.0-beta", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", - "experimental-islands", + "islands", "dynamic_load", ] } serde = { version = "1", features = ["derive"] } diff --git a/examples/ssr/axum_island/Cargo.toml b/examples/ssr/axum_island/Cargo.toml index 2960f477..840ba329 100644 --- a/examples/ssr/axum_island/Cargo.toml +++ b/examples/ssr/axum_island/Cargo.toml @@ -10,12 +10,12 @@ crate-type = ["cdylib", "rlib"] [dependencies] axum = { version = "0.7", optional = true } -leptos = { version = "0.7.0", features = ["experimental-islands"] } +leptos = { version = "0.7.0", features = ["islands"] } leptos_meta = { version = "0.7.0" } leptos_axum = { version = "0.7.0", optional = true } leptos_i18n = { path = "../../../leptos_i18n", features = [ "track_locale_files", - "experimental-islands", + "islands", ] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } diff --git a/leptos_i18n/Cargo.toml b/leptos_i18n/Cargo.toml index 66452040..78f1fdd3 100644 --- a/leptos_i18n/Cargo.toml +++ b/leptos_i18n/Cargo.toml @@ -81,9 +81,9 @@ ssr = [ "leptos-use/ssr", "leptos_i18n_macro/ssr", ] -experimental-islands = [ - "leptos/experimental-islands", - "leptos_i18n_macro/experimental-islands", +islands = [ + "leptos/islands", + "leptos_i18n_macro/islands", ] nightly = ["leptos/nightly", "leptos_i18n_macro/nightly"] diff --git a/leptos_i18n/src/lib.rs b/leptos_i18n/src/lib.rs index 583daa3d..67d1752d 100644 --- a/leptos_i18n/src/lib.rs +++ b/leptos_i18n/src/lib.rs @@ -253,7 +253,7 @@ pub mod reexports { /// Also note that this macro does NOT take the context as the first argument, instead it takes the name for the generated island. /// /// If you need to pass variable args, you will have to make yourself an island that take those args. -#[cfg(feature = "experimental-islands")] +#[cfg(feature = "islands")] #[macro_export] macro_rules! ti { ($island_name: ident, $($tt:tt)*) => { @@ -315,7 +315,7 @@ macro_rules! ti { /// } /// } /// ``` -#[cfg(feature = "experimental-islands")] +#[cfg(feature = "islands")] #[macro_export] macro_rules! make_i18n_island { ($island_name: ident, $($tt:tt)*) => { diff --git a/leptos_i18n_macro/Cargo.toml b/leptos_i18n_macro/Cargo.toml index 864786bd..a0d94a0f 100644 --- a/leptos_i18n_macro/Cargo.toml +++ b/leptos_i18n_macro/Cargo.toml @@ -36,7 +36,7 @@ yaml_files = ["dep:serde_yaml", "leptos_i18n_parser/yaml_files"] json5_files = ["dep:json5", "leptos_i18n_parser/json5_files"] interpolate_display = [] track_locale_files = [] -experimental-islands = [] +islands = [] show_keys_only = [] dynamic_load = [] hydrate = [] diff --git a/leptos_i18n_macro/src/load_locales/mod.rs b/leptos_i18n_macro/src/load_locales/mod.rs index 08672237..10690256 100644 --- a/leptos_i18n_macro/src/load_locales/mod.rs +++ b/leptos_i18n_macro/src/load_locales/mod.rs @@ -117,7 +117,7 @@ fn load_locales_inner( quote!(td_display), ]; - let providers = if cfg!(feature = "experimental-islands") { + let providers = if cfg!(feature = "islands") { macros_reexport.push(quote!(ti)); quote! { use leptos::children::Children; From b09218bc35866f77758df8908cbcc2b64a755a21 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 11 Dec 2024 15:23:14 +0100 Subject: [PATCH 05/13] reverse removal of wasm-bindgen as a dep --- leptos_i18n/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/leptos_i18n/Cargo.toml b/leptos_i18n/Cargo.toml index 78f1fdd3..f46b6c37 100644 --- a/leptos_i18n/Cargo.toml +++ b/leptos_i18n/Cargo.toml @@ -36,6 +36,7 @@ serde-wasm-bindgen = { version = "0.6.5", optional = true } futures = { version = "0.3.30", optional = true } noop-waker = { version = "0.1.0", optional = true } default-struct-builder = "0.5" +wasm-bindgen = "0.2.99" [features] default = ["cookie", "json_files", "icu_compiled_data"] From d144da0e45ad9b2ccade3c64facd0a670da576d9 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 11 Dec 2024 15:43:00 +0100 Subject: [PATCH 06/13] pin wasm-bindgen for CI --- leptos_i18n/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/leptos_i18n/Cargo.toml b/leptos_i18n/Cargo.toml index f46b6c37..d09d2628 100644 --- a/leptos_i18n/Cargo.toml +++ b/leptos_i18n/Cargo.toml @@ -36,7 +36,8 @@ serde-wasm-bindgen = { version = "0.6.5", optional = true } futures = { version = "0.3.30", optional = true } noop-waker = { version = "0.1.0", optional = true } default-struct-builder = "0.5" -wasm-bindgen = "0.2.99" +# FIXME: unpin +wasm-bindgen = "=0.2.95" [features] default = ["cookie", "json_files", "icu_compiled_data"] From d23f1083bf53ddc2e9a151df6e47547a10568d1a Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 11 Dec 2024 15:46:05 +0100 Subject: [PATCH 07/13] unpin wasm-bindgen and update cargo-leptos --- .github/workflows/ci.yml | 2 +- leptos_i18n/Cargo.toml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80cc2534..a62ca05f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: - master env: CARGO_TERM_COLOR: always - CARGO_LEPTOS_VERSION: 0.2.21 + CARGO_LEPTOS_VERSION: 0.2.22 jobs: lib_test: name: Test leptos_i18n package diff --git a/leptos_i18n/Cargo.toml b/leptos_i18n/Cargo.toml index d09d2628..f46b6c37 100644 --- a/leptos_i18n/Cargo.toml +++ b/leptos_i18n/Cargo.toml @@ -36,8 +36,7 @@ serde-wasm-bindgen = { version = "0.6.5", optional = true } futures = { version = "0.3.30", optional = true } noop-waker = { version = "0.1.0", optional = true } default-struct-builder = "0.5" -# FIXME: unpin -wasm-bindgen = "=0.2.95" +wasm-bindgen = "0.2.99" [features] default = ["cookie", "json_files", "icu_compiled_data"] From c117a7bbe4d0962d0140a2b62336a5d208e6d397 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 11 Dec 2024 16:03:41 +0100 Subject: [PATCH 08/13] unlocked cargo-leptos --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a62ca05f..7b2a3da0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: toolchain: "stable" targets: "wasm32-unknown-unknown" - name: "Install cargo-leptos" - run: cargo install cargo-leptos@${{ env.CARGO_LEPTOS_VERSION }} --locked + run: cargo install cargo-leptos@${{ env.CARGO_LEPTOS_VERSION }} - name: "Build ${{ matrix.examples }} example" working-directory: examples/ssr/${{ matrix.examples }} run: cargo leptos build @@ -109,7 +109,7 @@ jobs: toolchain: "stable" targets: "wasm32-unknown-unknown" - name: "Install cargo-leptos" - run: cargo install cargo-leptos@${{ env.CARGO_LEPTOS_VERSION }} --locked + run: cargo install cargo-leptos@${{ env.CARGO_LEPTOS_VERSION }} - name: "Build ${{ matrix.examples }} example" working-directory: examples/dynamic_load/${{ matrix.examples }} run: cargo leptos build From d8c3d13828f6876983051a38e0d5940becfd9f04 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 11 Dec 2024 16:13:39 +0100 Subject: [PATCH 09/13] re-lock cargo-leptos and pin wasm-bindgen --- .github/workflows/ci.yml | 4 ++-- leptos_i18n/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b2a3da0..a62ca05f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,7 +66,7 @@ jobs: toolchain: "stable" targets: "wasm32-unknown-unknown" - name: "Install cargo-leptos" - run: cargo install cargo-leptos@${{ env.CARGO_LEPTOS_VERSION }} + run: cargo install cargo-leptos@${{ env.CARGO_LEPTOS_VERSION }} --locked - name: "Build ${{ matrix.examples }} example" working-directory: examples/ssr/${{ matrix.examples }} run: cargo leptos build @@ -109,7 +109,7 @@ jobs: toolchain: "stable" targets: "wasm32-unknown-unknown" - name: "Install cargo-leptos" - run: cargo install cargo-leptos@${{ env.CARGO_LEPTOS_VERSION }} + run: cargo install cargo-leptos@${{ env.CARGO_LEPTOS_VERSION }} --locked - name: "Build ${{ matrix.examples }} example" working-directory: examples/dynamic_load/${{ matrix.examples }} run: cargo leptos build diff --git a/leptos_i18n/Cargo.toml b/leptos_i18n/Cargo.toml index f46b6c37..ae3a7f2d 100644 --- a/leptos_i18n/Cargo.toml +++ b/leptos_i18n/Cargo.toml @@ -36,7 +36,7 @@ serde-wasm-bindgen = { version = "0.6.5", optional = true } futures = { version = "0.3.30", optional = true } noop-waker = { version = "0.1.0", optional = true } default-struct-builder = "0.5" -wasm-bindgen = "0.2.99" +wasm-bindgen = "=0.2.96" [features] default = ["cookie", "json_files", "icu_compiled_data"] From af0807aa348b627842128816a6fb6c91d93a3c0a Mon Sep 17 00:00:00 2001 From: Baptistemontan Date: Wed, 11 Dec 2024 20:53:24 +0100 Subject: [PATCH 10/13] lock wasm-bindgen in the examples instead --- examples/dynamic_load/axum_island/Cargo.toml | 3 ++- examples/dynamic_load/hello_world_actix/Cargo.toml | 3 ++- examples/dynamic_load/hello_world_axum/Cargo.toml | 3 ++- examples/dynamic_load/namespaces/Cargo.toml | 3 ++- examples/ssr/axum_island/Cargo.toml | 3 ++- examples/ssr/hello_world_actix/Cargo.toml | 3 ++- examples/ssr/hello_world_axum/Cargo.toml | 3 ++- examples/ssr/routing_ssr/Cargo.toml | 4 ++-- examples/ssr/workspace/client/Cargo.toml | 3 ++- leptos_i18n/Cargo.toml | 7 ++----- 10 files changed, 20 insertions(+), 15 deletions(-) diff --git a/examples/dynamic_load/axum_island/Cargo.toml b/examples/dynamic_load/axum_island/Cargo.toml index 1a0945c8..4143cebe 100644 --- a/examples/dynamic_load/axum_island/Cargo.toml +++ b/examples/dynamic_load/axum_island/Cargo.toml @@ -20,12 +20,13 @@ leptos_i18n = { path = "../../../leptos_i18n", features = [ ] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2", optional = true } +# wasm-bindgen = { version = "0.2", optional = true } simple_logger = "4" tokio = { version = "1.35", features = ["rt-multi-thread"], optional = true } log = "0.4" tower = { version = "0.5.1", optional = true } tower-http = { version = "0.6.1", features = ["fs"], optional = true } +wasm-bindgen = "=0.2.96" [features] default = ["hydrate", "ssr"] diff --git a/examples/dynamic_load/hello_world_actix/Cargo.toml b/examples/dynamic_load/hello_world_actix/Cargo.toml index dcf6e01a..33cef02c 100644 --- a/examples/dynamic_load/hello_world_actix/Cargo.toml +++ b/examples/dynamic_load/hello_world_actix/Cargo.toml @@ -20,7 +20,8 @@ leptos_i18n = { path = "../../../leptos_i18n", features = [ ] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2", optional = true } +# wasm-bindgen = { version = "0.2", optional = true } +wasm-bindgen = "=0.2.96" [features] default = ["hydrate", "ssr"] diff --git a/examples/dynamic_load/hello_world_axum/Cargo.toml b/examples/dynamic_load/hello_world_axum/Cargo.toml index 42ea1ff6..668f6d11 100644 --- a/examples/dynamic_load/hello_world_axum/Cargo.toml +++ b/examples/dynamic_load/hello_world_axum/Cargo.toml @@ -19,12 +19,13 @@ leptos_i18n = { path = "../../../leptos_i18n", features = [ ] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2", optional = true } +# wasm-bindgen = { version = "0.2", optional = true } simple_logger = "4" tokio = { version = "1.35", features = ["rt-multi-thread"], optional = true } log = "0.4" tower = { version = "0.5.1", optional = true } tower-http = { version = "0.6.1", features = ["fs"], optional = true } +wasm-bindgen = "=0.2.96" [features] default = ["hydrate", "ssr"] diff --git a/examples/dynamic_load/namespaces/Cargo.toml b/examples/dynamic_load/namespaces/Cargo.toml index 71d04dbc..7d9efd20 100644 --- a/examples/dynamic_load/namespaces/Cargo.toml +++ b/examples/dynamic_load/namespaces/Cargo.toml @@ -19,12 +19,13 @@ leptos_i18n = { path = "../../../leptos_i18n", features = [ ] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2", optional = true } +# wasm-bindgen = { version = "0.2", optional = true } simple_logger = "4" tokio = { version = "1.35", features = ["rt-multi-thread"], optional = true } log = "0.4" tower = { version = "0.5.1", optional = true } tower-http = { version = "0.6.1", features = ["fs"], optional = true } +wasm-bindgen = "=0.2.96" [features] default = ["hydrate", "ssr"] diff --git a/examples/ssr/axum_island/Cargo.toml b/examples/ssr/axum_island/Cargo.toml index 840ba329..9d0569f5 100644 --- a/examples/ssr/axum_island/Cargo.toml +++ b/examples/ssr/axum_island/Cargo.toml @@ -19,12 +19,13 @@ leptos_i18n = { path = "../../../leptos_i18n", features = [ ] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2", optional = true } +# wasm-bindgen = { version = "0.2", optional = true } simple_logger = "4" tokio = { version = "1.35", features = ["rt-multi-thread"], optional = true } log = "0.4" tower = { version = "0.5.1", optional = true } tower-http = { version = "0.6.1", features = ["fs"], optional = true } +wasm-bindgen = "=0.2.96" [features] default = ["hydrate", "ssr"] diff --git a/examples/ssr/hello_world_actix/Cargo.toml b/examples/ssr/hello_world_actix/Cargo.toml index 5cd1b37c..90b4118d 100644 --- a/examples/ssr/hello_world_actix/Cargo.toml +++ b/examples/ssr/hello_world_actix/Cargo.toml @@ -19,7 +19,8 @@ leptos_i18n = { path = "../../../leptos_i18n", features = [ ] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2", optional = true } +# wasm-bindgen = { version = "0.2", optional = true } +wasm-bindgen = "=0.2.96" [features] default = ["hydrate", "ssr"] diff --git a/examples/ssr/hello_world_axum/Cargo.toml b/examples/ssr/hello_world_axum/Cargo.toml index 8899540c..b6d3f7ad 100644 --- a/examples/ssr/hello_world_axum/Cargo.toml +++ b/examples/ssr/hello_world_axum/Cargo.toml @@ -18,12 +18,13 @@ leptos_i18n = { path = "../../../leptos_i18n", features = [ ] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2", optional = true } +# wasm-bindgen = { version = "0.2", optional = true } simple_logger = "4" tokio = { version = "1.35", features = ["rt-multi-thread"], optional = true } log = "0.4" tower = { version = "0.5.1", optional = true } tower-http = { version = "0.6.1", features = ["fs"], optional = true } +wasm-bindgen = "=0.2.96" [features] default = ["hydrate", "ssr"] diff --git a/examples/ssr/routing_ssr/Cargo.toml b/examples/ssr/routing_ssr/Cargo.toml index 9fba709d..22ff332a 100644 --- a/examples/ssr/routing_ssr/Cargo.toml +++ b/examples/ssr/routing_ssr/Cargo.toml @@ -19,14 +19,14 @@ leptos_i18n = { path = "../../../leptos_i18n", features = [ leptos_i18n_router = { path = "../../../leptos_i18n_router" } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2", optional = true } +# wasm-bindgen = { version = "0.2", optional = true } simple_logger = "4" tokio = { version = "1.35", features = ["rt-multi-thread"], optional = true } log = "0.4" tower = { version = "0.5.1", optional = true } tower-http = { version = "0.6.1", features = ["fs"], optional = true } - leptos_router = { version = "0.7.0" } +wasm-bindgen = "=0.2.96" [features] default = ["hydrate", "ssr"] diff --git a/examples/ssr/workspace/client/Cargo.toml b/examples/ssr/workspace/client/Cargo.toml index a9bdff64..983779fe 100644 --- a/examples/ssr/workspace/client/Cargo.toml +++ b/examples/ssr/workspace/client/Cargo.toml @@ -16,7 +16,8 @@ leptos_actix = { version = "0.7.0", optional = true } leptos_i18n = { workspace = true, features = ["track_locale_files"] } serde = { version = "1", features = ["derive"] } console_error_panic_hook = { version = "0.1", optional = true } -wasm-bindgen = { version = "0.2", optional = true } +# wasm-bindgen = { version = "0.2", optional = true } +wasm-bindgen = "=0.2.96" [features] default = ["hydrate", "ssr"] diff --git a/leptos_i18n/Cargo.toml b/leptos_i18n/Cargo.toml index ae3a7f2d..91f955a2 100644 --- a/leptos_i18n/Cargo.toml +++ b/leptos_i18n/Cargo.toml @@ -36,7 +36,7 @@ serde-wasm-bindgen = { version = "0.6.5", optional = true } futures = { version = "0.3.30", optional = true } noop-waker = { version = "0.1.0", optional = true } default-struct-builder = "0.5" -wasm-bindgen = "=0.2.96" +wasm-bindgen = "0.2.96" [features] default = ["cookie", "json_files", "icu_compiled_data"] @@ -82,10 +82,7 @@ ssr = [ "leptos-use/ssr", "leptos_i18n_macro/ssr", ] -islands = [ - "leptos/islands", - "leptos_i18n_macro/islands", -] +islands = ["leptos/islands", "leptos_i18n_macro/islands"] nightly = ["leptos/nightly", "leptos_i18n_macro/nightly"] dynamic_load = [ From 7b9e55cbf8cd7a7903cbbf4de1489c8d92475b85 Mon Sep 17 00:00:00 2001 From: Baptistemontan Date: Wed, 11 Dec 2024 20:58:02 +0100 Subject: [PATCH 11/13] update book --- docs/book/src/usage/07_router.md | 29 +++++------------------------ leptos_i18n_router/src/lib.rs | 2 +- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/docs/book/src/usage/07_router.md b/docs/book/src/usage/07_router.md index a9080f9a..5718eaef 100644 --- a/docs/book/src/usage/07_router.md +++ b/docs/book/src/usage/07_router.md @@ -1,12 +1,13 @@ # `I18nRoute` -The `i18n` module generated from the `load_locales!()` macro export the `I18nRoute` component, +You can use the `leptos_i18n_router` crate that export the `I18nRoute` component, this component act exactly like a `leptos_router::Route` and take the same args, except for the path. What it does is manage a prefix on the URL such that ```rust -use crate::i18n::I18nRoute; +use crate::i18n::Locale; +use leptos_i18n_router::I118nRoute; use leptos::prelude::*; use leptos_router::*; @@ -68,7 +69,7 @@ and the history will look like you directly navigated from `"/fr/counter"` to `" You can use inside the `i18nRoute` the `i18n_path!` to create localized path segments: ```rust -use leptos_i18n::i18n_path; +use leptos_i18n_router::i18n_path; view=Outlet> @@ -105,7 +106,7 @@ view! { And the `Menu` component use localization, you could be suprised to see that sometimes there is a mismatch beetween the locale used by the `Menu` and the one inside the router. This is due to the locale being read from the URL only when the `i18nRoute` is rendered. So the context may be initialized with another locale, and then hit the router that update it. -You have multiple solutions, you can either use the `Menu` component inside the `i18nRoute`: +One solution would be to use the `Menu` component inside the `i18nRoute`: ```rust view! { @@ -123,23 +124,3 @@ view! {
} ``` - -Or you can use the `parse_locale_from_path` option on the `I18nContextProvider`: - -```rust -view! { - - - - - view=Outlet> - - > - - - -} -``` - -This option force the context to initialize itself with the locale from the URL. It is not enabled by default because the only time it is neededis this particular case. -It expect the base_path argument you would pass to the `I18nRoute`. diff --git a/leptos_i18n_router/src/lib.rs b/leptos_i18n_router/src/lib.rs index 9d36a867..1a471588 100644 --- a/leptos_i18n_router/src/lib.rs +++ b/leptos_i18n_router/src/lib.rs @@ -1,7 +1,7 @@ #![deny(missing_docs)] #![forbid(unsafe_code)] #![deny(warnings)] -//! edzdz +//! WIP //! //! //! From e083a226ffa248eee2da42bdfb7f19773023231e Mon Sep 17 00:00:00 2001 From: Baptistemontan Date: Wed, 11 Dec 2024 21:20:55 +0100 Subject: [PATCH 12/13] fix optionnal dep --- examples/dynamic_load/axum_island/Cargo.toml | 2 +- examples/dynamic_load/hello_world_actix/Cargo.toml | 2 +- examples/dynamic_load/hello_world_axum/Cargo.toml | 2 +- examples/dynamic_load/namespaces/Cargo.toml | 2 +- examples/ssr/axum_island/Cargo.toml | 2 +- examples/ssr/hello_world_actix/Cargo.toml | 2 +- examples/ssr/hello_world_axum/Cargo.toml | 2 +- examples/ssr/routing_ssr/Cargo.toml | 2 +- examples/ssr/workspace/client/Cargo.toml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/dynamic_load/axum_island/Cargo.toml b/examples/dynamic_load/axum_island/Cargo.toml index 4143cebe..47ef6f43 100644 --- a/examples/dynamic_load/axum_island/Cargo.toml +++ b/examples/dynamic_load/axum_island/Cargo.toml @@ -32,7 +32,7 @@ wasm-bindgen = "=0.2.96" default = ["hydrate", "ssr"] hydrate = [ "dep:console_error_panic_hook", - "dep:wasm-bindgen", + # "dep:wasm-bindgen", "leptos/hydrate", "leptos_i18n/hydrate", ] diff --git a/examples/dynamic_load/hello_world_actix/Cargo.toml b/examples/dynamic_load/hello_world_actix/Cargo.toml index 33cef02c..9c276394 100644 --- a/examples/dynamic_load/hello_world_actix/Cargo.toml +++ b/examples/dynamic_load/hello_world_actix/Cargo.toml @@ -27,7 +27,7 @@ wasm-bindgen = "=0.2.96" default = ["hydrate", "ssr"] hydrate = [ "dep:console_error_panic_hook", - "dep:wasm-bindgen", + # "dep:wasm-bindgen", "leptos/hydrate", "leptos_i18n/hydrate", ] diff --git a/examples/dynamic_load/hello_world_axum/Cargo.toml b/examples/dynamic_load/hello_world_axum/Cargo.toml index 668f6d11..d78f8aa3 100644 --- a/examples/dynamic_load/hello_world_axum/Cargo.toml +++ b/examples/dynamic_load/hello_world_axum/Cargo.toml @@ -31,7 +31,7 @@ wasm-bindgen = "=0.2.96" default = ["hydrate", "ssr"] hydrate = [ "dep:console_error_panic_hook", - "dep:wasm-bindgen", + # "dep:wasm-bindgen", "leptos/hydrate", "leptos_i18n/hydrate", ] diff --git a/examples/dynamic_load/namespaces/Cargo.toml b/examples/dynamic_load/namespaces/Cargo.toml index 7d9efd20..544b0504 100644 --- a/examples/dynamic_load/namespaces/Cargo.toml +++ b/examples/dynamic_load/namespaces/Cargo.toml @@ -31,7 +31,7 @@ wasm-bindgen = "=0.2.96" default = ["hydrate", "ssr"] hydrate = [ "dep:console_error_panic_hook", - "dep:wasm-bindgen", + # "dep:wasm-bindgen", "leptos/hydrate", "leptos_i18n/hydrate", ] diff --git a/examples/ssr/axum_island/Cargo.toml b/examples/ssr/axum_island/Cargo.toml index 9d0569f5..6ec0ca1d 100644 --- a/examples/ssr/axum_island/Cargo.toml +++ b/examples/ssr/axum_island/Cargo.toml @@ -31,7 +31,7 @@ wasm-bindgen = "=0.2.96" default = ["hydrate", "ssr"] hydrate = [ "dep:console_error_panic_hook", - "dep:wasm-bindgen", + # "dep:wasm-bindgen", "leptos/hydrate", "leptos_i18n/hydrate", ] diff --git a/examples/ssr/hello_world_actix/Cargo.toml b/examples/ssr/hello_world_actix/Cargo.toml index 90b4118d..6567d401 100644 --- a/examples/ssr/hello_world_actix/Cargo.toml +++ b/examples/ssr/hello_world_actix/Cargo.toml @@ -26,7 +26,7 @@ wasm-bindgen = "=0.2.96" default = ["hydrate", "ssr"] hydrate = [ "dep:console_error_panic_hook", - "dep:wasm-bindgen", + # "dep:wasm-bindgen", "leptos/hydrate", "leptos_i18n/hydrate", ] diff --git a/examples/ssr/hello_world_axum/Cargo.toml b/examples/ssr/hello_world_axum/Cargo.toml index b6d3f7ad..c200bb38 100644 --- a/examples/ssr/hello_world_axum/Cargo.toml +++ b/examples/ssr/hello_world_axum/Cargo.toml @@ -30,7 +30,7 @@ wasm-bindgen = "=0.2.96" default = ["hydrate", "ssr"] hydrate = [ "dep:console_error_panic_hook", - "dep:wasm-bindgen", + # "dep:wasm-bindgen", "leptos/hydrate", "leptos_i18n/hydrate", ] diff --git a/examples/ssr/routing_ssr/Cargo.toml b/examples/ssr/routing_ssr/Cargo.toml index 22ff332a..3300626a 100644 --- a/examples/ssr/routing_ssr/Cargo.toml +++ b/examples/ssr/routing_ssr/Cargo.toml @@ -32,7 +32,7 @@ wasm-bindgen = "=0.2.96" default = ["hydrate", "ssr"] hydrate = [ "dep:console_error_panic_hook", - "dep:wasm-bindgen", + # "dep:wasm-bindgen", "leptos/hydrate", "leptos_i18n/hydrate", ] diff --git a/examples/ssr/workspace/client/Cargo.toml b/examples/ssr/workspace/client/Cargo.toml index 983779fe..b99d80d9 100644 --- a/examples/ssr/workspace/client/Cargo.toml +++ b/examples/ssr/workspace/client/Cargo.toml @@ -23,7 +23,7 @@ wasm-bindgen = "=0.2.96" default = ["hydrate", "ssr"] hydrate = [ "dep:console_error_panic_hook", - "dep:wasm-bindgen", + # "dep:wasm-bindgen", "leptos/hydrate", "leptos_i18n/hydrate", ] From 72b274ffd35a0b2a6c4b17e7691f7f6679b5828b Mon Sep 17 00:00:00 2001 From: Baptistemontan Date: Wed, 11 Dec 2024 23:04:34 +0100 Subject: [PATCH 13/13] crate doc --- leptos_i18n_router/src/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/leptos_i18n_router/src/lib.rs b/leptos_i18n_router/src/lib.rs index 1a471588..c0665d08 100644 --- a/leptos_i18n_router/src/lib.rs +++ b/leptos_i18n_router/src/lib.rs @@ -1,12 +1,7 @@ #![deny(missing_docs)] #![forbid(unsafe_code)] #![deny(warnings)] -//! WIP -//! -//! -//! -//! -//! +//! This crate contain anything related to routing for the `leptos_i18n` crate. mod components; mod routing;