Put the lang in front of url (WIP)

This commit is contained in:
Greg Burri 2025-03-26 02:08:20 +01:00
parent 418d31a127
commit b39cb1c067
4 changed files with 8 additions and 6 deletions

View file

@ -335,7 +335,7 @@ fn url_rewriting(mut req: Request) -> Request {
if let Some(lang) = parts.next() { if let Some(lang) = parts.next() {
let available_codes = translation::available_codes(); let available_codes = translation::available_codes();
if available_codes.contains(&lang) { if available_codes.contains(&lang) {
let mut rest: String = String::from(""); let mut rest = String::from("");
for part in parts { for part in parts {
rest.push('/'); rest.push('/');
rest.push_str(part); rest.push_str(part);

View file

@ -1,6 +1,6 @@
{% macro recipe_item(id, title, is_current) %} {% macro recipe_item(id, title, is_current) %}
<li> <li>
<a href="/recipe/view/{{ id }}" class="recipe-item <a href="/{{ tr.current_lang_code() }}/recipe/view/{{ id }}" class="recipe-item
{%~ if is_current %} {%~ if is_current %}
current current
{% endif %}" id="recipe-{{ id }}" {% endif %}" id="recipe-{{ id }}"

View file

@ -1 +1 @@
<a class="title" href="/"><img class="logo" src="/static/logo.svg" alt="logo">{{ tr.t(Sentence::MainTitle) }}</a> <a class="title" href="/{{ tr.current_lang_code() }}/"><img class="logo" src="/static/logo.svg" alt="logo">{{ tr.t(Sentence::MainTitle) }}</a>

View file

@ -7,7 +7,7 @@ use crate::{
calendar, calendar,
recipe_scheduler::RecipeScheduler, recipe_scheduler::RecipeScheduler,
shopping_list::ShoppingList, 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) { 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); let shopping_list = ShoppingList::new(!is_user_logged);
spawn_local(async move { spawn_local(async move {
let lang = get_current_lang();
let local = get_locale();
let item_template: Element = selector("#hidden-templates .shopping-item"); let item_template: Element = selector("#hidden-templates .shopping-item");
let container: Element = by_id("shopping-list"); let container: Element = by_id("shopping-list");
let container_checked: Element = by_id("shopping-list-checked"); 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_element.set_inner_html(&format!(
"{} @ {}", "{} @ {}",
recipe_title, recipe_title,
date.format_localized(&date_format, get_locale()), date.format_localized(&date_format, local),
)); ));
recipe_element recipe_element
.set_attribute("href", &format!("/recipe/view/{}", recipe_id)) .set_attribute("href", &format!("/{}/recipe/view/{}", lang, recipe_id))
.unwrap(); .unwrap();
} }