Put the lang in front of url (WIP)
authorGreg Burri <greg.burri@gmail.com>
Wed, 26 Mar 2025 01:08:20 +0000 (02:08 +0100)
committerGreg Burri <greg.burri@gmail.com>
Wed, 26 Mar 2025 01:08:20 +0000 (02:08 +0100)
backend/src/main.rs
backend/templates/recipes_list_fragment.html
backend/templates/title.html
frontend/src/pages/home.rs

index 06ff7c4..e901e96 100644 (file)
@@ -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);
index ca89a18..cec2dcc 100644 (file)
@@ -1,6 +1,6 @@
 {% macro recipe_item(id, title, is_current) %}
     <li>
-        <a href="/recipe/view/{{ id }}" class="recipe-item
+        <a href="/{{ tr.current_lang_code() }}/recipe/view/{{ id }}" class="recipe-item
             {%~ if is_current %}
                 current
             {% endif %}" id="recipe-{{ id }}"
index 4387ee2..334df85 100644 (file)
@@ -1 +1 @@
-<a class="title" href="/"><img class="logo" src="/static/logo.svg" alt="logo">{{ tr.t(Sentence::MainTitle) }}</a>
\ No newline at end of file
+<a class="title" href="/{{ tr.current_lang_code() }}/"><img class="logo" src="/static/logo.svg" alt="logo">{{ tr.t(Sentence::MainTitle) }}</a>
\ No newline at end of file
index 986bd9f..4dabbd2 100644 (file)
@@ -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();
             }