Add DE/EN language toggle with bilingual descriptions
- Language switcher in sidebar (DE/EN buttons, persists to localStorage) - i18n module with pick_desc/pick_name helpers for language-aware fallback - All detail/list pages use language context for names and descriptions - Species/Cultivar types updated with description_de/description_en - Common Name column added to species/families lists
This commit is contained in:
@@ -3,8 +3,9 @@ use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::api;
|
||||
use crate::app::Route;
|
||||
use crate::app::{Lang, Route};
|
||||
use crate::components::table_controls::*;
|
||||
use crate::i18n::{pick_desc, pick_name};
|
||||
|
||||
/// Convert a month-number array (1=Jan..12=Dec) to a comma-separated string of abbreviations.
|
||||
fn months_display(months: &Option<Vec<i32>>) -> String {
|
||||
@@ -279,6 +280,7 @@ pub fn CultivarList() -> Element {
|
||||
|
||||
#[component]
|
||||
pub fn CultivarDetail(slug: String) -> Element {
|
||||
let lang = use_context::<Lang>().0;
|
||||
let slug_clone = slug.clone();
|
||||
let cultivar = use_resource(move || {
|
||||
let s = slug_clone.clone();
|
||||
@@ -326,11 +328,14 @@ pub fn CultivarDetail(slug: String) -> Element {
|
||||
None => rsx! { p { "Loading..." } },
|
||||
Some(Err(e)) => rsx! { p { class: "error", "Error: {e}" } },
|
||||
Some(Ok(c)) => {
|
||||
let current_lang = lang.read().clone();
|
||||
|
||||
// Pre-compute display strings outside of rsx
|
||||
let common_name = pick_name(¤t_lang, &c.name_de, &c.name_en, &c.name);
|
||||
let name_en = opt_str(&c.name_en);
|
||||
let name_de = opt_str(&c.name_de);
|
||||
let name_sci = opt_str(&c.name_scientific);
|
||||
let desc = opt_str(&c.description);
|
||||
let desc = pick_desc(¤t_lang, &c.description_de, &c.description_en, &c.description);
|
||||
let organic = bool_display(c.is_organic);
|
||||
let perennial = bool_display(c.perennial);
|
||||
|
||||
@@ -369,6 +374,9 @@ pub fn CultivarDetail(slug: String) -> Element {
|
||||
|
||||
rsx! {
|
||||
h1 { "{c.name}" }
|
||||
if common_name != c.name {
|
||||
p { class: "name-common", "{common_name}" }
|
||||
}
|
||||
|
||||
div { class: "detail-row",
|
||||
// === LEFT COLUMN ===
|
||||
@@ -383,6 +391,10 @@ pub fn CultivarDetail(slug: String) -> Element {
|
||||
th { "Name" }
|
||||
td { "{c.name}" }
|
||||
}
|
||||
tr {
|
||||
th { "Common Name" }
|
||||
td { "{common_name}" }
|
||||
}
|
||||
tr {
|
||||
th { "Name EN" }
|
||||
td { class: if name_en == "\u{2014}" { "placeholder" } else { "" }, "{name_en}" }
|
||||
|
||||
Reference in New Issue
Block a user