From: Greg Burri Date: Wed, 26 Mar 2025 01:08:20 +0000 (+0100) Subject: Put the lang in front of url (WIP) X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=b39cb1c067ccea9bdbbc4d5a304ebfd7b61fa5d2;p=recipes.git Put the lang in front of url (WIP) --- diff --git a/backend/src/main.rs b/backend/src/main.rs index 06ff7c4..e901e96 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -335,7 +335,7 @@ fn url_rewriting(mut req: Request) -> Request { if let Some(lang) = parts.next() { let available_codes = translation::available_codes(); if available_codes.contains(&lang) { - let mut rest: String = String::from(""); + let mut rest = String::from(""); for part in parts { rest.push('/'); rest.push_str(part); diff --git a/backend/templates/recipes_list_fragment.html b/backend/templates/recipes_list_fragment.html index ca89a18..cec2dcc 100644 --- a/backend/templates/recipes_list_fragment.html +++ b/backend/templates/recipes_list_fragment.html @@ -1,6 +1,6 @@ {% macro recipe_item(id, title, is_current) %}
  • - {{ tr.t(Sentence::MainTitle) }} \ No newline at end of file +{{ tr.t(Sentence::MainTitle) }} \ No newline at end of file diff --git a/frontend/src/pages/home.rs b/frontend/src/pages/home.rs index 986bd9f..4dabbd2 100644 --- a/frontend/src/pages/home.rs +++ b/frontend/src/pages/home.rs @@ -7,7 +7,7 @@ use crate::{ calendar, recipe_scheduler::RecipeScheduler, shopping_list::ShoppingList, - utils::{SelectorExt, by_id, get_locale, selector}, + utils::{SelectorExt, by_id, get_current_lang, get_locale, selector}, }; pub fn setup_page(is_user_logged: bool) { @@ -25,6 +25,8 @@ pub fn setup_page(is_user_logged: bool) { let shopping_list = ShoppingList::new(!is_user_logged); spawn_local(async move { + let lang = get_current_lang(); + let local = get_locale(); let item_template: Element = selector("#hidden-templates .shopping-item"); let container: Element = by_id("shopping-list"); let container_checked: Element = by_id("shopping-list-checked"); @@ -53,10 +55,10 @@ pub fn setup_page(is_user_logged: bool) { recipe_element.set_inner_html(&format!( "{} @ {}", recipe_title, - date.format_localized(&date_format, get_locale()), + date.format_localized(&date_format, local), )); recipe_element - .set_attribute("href", &format!("/recipe/view/{}", recipe_id)) + .set_attribute("href", &format!("/{}/recipe/view/{}", lang, recipe_id)) .unwrap(); }