···11+use crate::layout::layout;
22+use maud::html;
33+use maudit::route::prelude::*;
44+55+#[locales(
66+ en(path = "/en/about"),
77+ sv(path = "/sv/om-oss"),
88+ de(path = "/de/uber-uns")
99+)]
1010+#[route("/about")]
1111+pub struct About;
1212+1313+impl Route for About {
1414+ fn render(&self, _ctx: &mut PageContext) -> impl Into<RenderResult> {
1515+ layout(html! {
1616+ h1 { "About" }
1717+ p { "This route has both a base path and localized variants." }
1818+ nav {
1919+ ul {
2020+ li { a href="/about" { "Default" } }
2121+ li { a href="/en/about" { "English" } }
2222+ li { a href="/sv/om-oss" { "Swedish" } }
2323+ li { a href="/de/uber-uns" { "German" } }
2424+ }
2525+ }
2626+ })
2727+ }
2828+}
+48
examples/i18n/src/routes/articles.rs
···11+use crate::layout::layout;
22+use maud::html;
33+use maudit::route::prelude::*;
44+55+#[derive(Params, Clone)]
66+pub struct ArticleParams {
77+ pub slug: String,
88+}
99+1010+#[locales(en(path = "/en/articles/[slug]"), sv(path = "/sv/artiklar/[slug]"))]
1111+#[route("/articles/[slug]")]
1212+pub struct Article;
1313+1414+impl Route<ArticleParams> for Article {
1515+ fn pages(&self, _ctx: &mut DynamicRouteContext) -> Pages<ArticleParams> {
1616+ vec![
1717+ Page::from_params(ArticleParams {
1818+ slug: "hello-world".to_string(),
1919+ }),
2020+ Page::from_params(ArticleParams {
2121+ slug: "getting-started".to_string(),
2222+ }),
2323+ ]
2424+ }
2525+2626+ fn render(&self, ctx: &mut PageContext) -> impl Into<RenderResult> {
2727+ let params = ctx.params::<ArticleParams>();
2828+2929+ let variant_info = if let Some(variant) = &ctx.variant {
3030+ format!("Variant: {}", variant)
3131+ } else {
3232+ "Base route (no variant)".to_string()
3333+ };
3434+3535+ layout(html! {
3636+ h1 { "Article: " (params.slug) }
3737+ p { (variant_info) }
3838+ p { "This is a dynamic route with localized variants." }
3939+ nav {
4040+ ul {
4141+ li { a href="/articles/hello-world" { "Default" } }
4242+ li { a href="/en/articles/hello-world" { "English" } }
4343+ li { a href="/sv/artiklar/hello-world" { "Swedish" } }
4444+ }
4545+ }
4646+ })
4747+ }
4848+}
+23
examples/i18n/src/routes/index.rs
···11+use crate::layout::layout;
22+use maud::html;
33+use maudit::route::prelude::*;
44+55+#[locales(en(path = "/en"), sv(path = "/sv"), de(path = "/de"))]
66+#[route]
77+pub struct Index;
88+99+impl Route for Index {
1010+ fn render(&self, _ctx: &mut PageContext) -> impl Into<RenderResult> {
1111+ layout(html! {
1212+ h1 { "i18n Example" }
1313+ p { "This route only exists as variants - no base path!" }
1414+ nav {
1515+ ul {
1616+ li { a href="/en" { "English" } }
1717+ li { a href="/sv" { "Swedish" } }
1818+ li { a href="/de" { "German" } }
1919+ }
2020+ }
2121+ })
2222+ }
2323+}
+44
examples/i18n/src/routes/mixed.rs
···11+use crate::layout::layout;
22+use maud::html;
33+use maudit::route::prelude::*;
44+55+#[derive(Params, Clone)]
66+pub struct MixedParams {
77+ pub id: String,
88+}
99+1010+// Base route is static (/products)
1111+// But variants have dynamic parameters (/en/products/[id])
1212+#[locales(en(path = "/en/products/[id]"), sv(path = "/sv/produkter/[id]"))]
1313+#[route]
1414+pub struct Mixed;
1515+1616+impl Route<MixedParams> for Mixed {
1717+ fn pages(&self, _ctx: &mut DynamicRouteContext) -> Pages<MixedParams> {
1818+ vec![
1919+ Page::from_params(MixedParams {
2020+ id: "laptop".to_string(),
2121+ }),
2222+ Page::from_params(MixedParams {
2323+ id: "phone".to_string(),
2424+ }),
2525+ ]
2626+ }
2727+2828+ fn render(&self, ctx: &mut PageContext) -> impl Into<RenderResult> {
2929+ let params = ctx.params::<MixedParams>();
3030+3131+ layout(html! {
3232+ h1 { "Product: " (params.id) }
3333+ p { "This route has a static base path but dynamic variants!" }
3434+ nav {
3535+ ul {
3636+ li { a href="/en/products/laptop" { "English - Laptop" } }
3737+ li { a href="/en/products/phone" { "English - Phone" } }
3838+ li { a href="/sv/produkter/laptop" { "Swedish - Laptop" } }
3939+ li { a href="/sv/produkter/phone" { "Swedish - Phone" } }
4040+ }
4141+ }
4242+ })
4343+ }
4444+}
+9
examples/i18n/src/routes/mod.rs
···11+mod about;
22+mod articles;
33+mod index;
44+mod mixed;
55+66+pub use about::About;
77+pub use articles::Article;
88+pub use index::Index;
99+pub use mixed::Mixed;
+11-7
examples/library/src/build.rs
···3939 &mut page_assets,
4040 &url,
4141 &options.base_url,
4242+ None,
4243 );
43444445 let content = route.build(&mut ctx)?;
···6869 let mut dynamic_ctx = DynamicRouteContext {
6970 content: &content_sources,
7071 assets: &mut page_assets,
7272+ variant: None,
7173 };
72747375 let routes = route.get_pages(&mut dynamic_ctx);
···78807981 // Here the context is created from a dynamic route, as the context has to include the page parameters and properties.
8082 let url = route.url(params);
8181- let mut ctx = PageContext::from_dynamic_route(
8282- &page,
8383- &content_sources,
8484- &mut page_assets,
8585- &url,
8686- &options.base_url,
8787- );
8383+ let mut ctx = PageContext {
8484+ params: page.1.as_ref(),
8585+ props: page.2.as_ref(),
8686+ content: &content_sources,
8787+ assets: &mut page_assets,
8888+ current_path: &url,
8989+ base_url: &options.base_url,
9090+ variant: None,
9191+ };
88928993 // Everything below here is the same as for static routes.
9094