From 6e264a13ecc0284c5073d0fbe92e6d0bfeeee6bb Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 6 Oct 2025 18:37:14 +0200 Subject: Prepare for book locale --- book/locale/en.ini | 7 +------ server/protocol/src/book.rs | 2 ++ server/tools/src/book.rs | 8 ++++++-- server/tools/src/book_html.rs | 22 ++++++++++++---------- server/tools/src/diagram_dot.rs | 3 +-- server/tools/src/main.rs | 3 ++- server/tools/src/recipe_diagram.rs | 4 ++-- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/book/locale/en.ini b/book/locale/en.ini index 0f0a354f..2a278d97 100644 --- a/book/locale/en.ini +++ b/book/locale/en.ini @@ -1,9 +1,4 @@ [hurrycurry] -b.about.image_attrib=Background image attribution -b.about.image_attrib.name=Name -b.about.image_attrib.author=Author -b.about.name=The Hurry Curry! recipe book. -b.about=About this book b.bun.desc=The most saturating meal of them all. Best enjoyed with a tomato soup. b.bun.steps=Start by processing your flour in a food processor. Don’t mind the bag, it will be shredded into unnoticable pieces. Once the dough has a workable consistency take it out of the food processor and put it in the oven until baked. When you take out the loaf, wait for it to cool down, then slice it on a cutting board. b.bun=Bun @@ -39,7 +34,7 @@ b.nigiri=Nigiri b.strawberry_shake.desc=A tasty mix of coconut and strawberry b.strawberry_shake.steps=Both a singular strawberry as well as a uncut complete coconut are pureed using a food processor, afterwards, to ease consumption, transferred to a glass. b.strawberry_shake=Strawberry Shake -b.title=Recipes for when you are in a Hurry +b.title=Hurry Curry! Recipe Book b.tomato_soup.desc=A delicious, creamy tomato soup, made from hand-picked tomatoes. b.tomato_soup.steps=Firstly, take your fresh tomato and puree it in a light blue stainless-steel blender until it resembles a fine paste. Transfer said paste into a large cauldron of your choosing and add a fresh whole leek and season to taste. Let this simmer until the consistency homogenizes and the colour seems apetizing. Serve this mixture on a plate and enjoy! b.tomato_soup=Tomato Soup diff --git a/server/protocol/src/book.rs b/server/protocol/src/book.rs index 7c529f22..87b7e4fc 100644 --- a/server/protocol/src/book.rs +++ b/server/protocol/src/book.rs @@ -30,9 +30,11 @@ pub struct Book { pub enum BookPage { Cover, Contents { + title: Message, table: Vec<(Message, usize)>, }, Text { + title: Message, paragraphs: Vec, }, Recipe { diff --git a/server/tools/src/book.rs b/server/tools/src/book.rs index a125375b..3e04b54f 100644 --- a/server/tools/src/book.rs +++ b/server/tools/src/book.rs @@ -18,6 +18,7 @@ use crate::{diagram_layout::diagram_layout, recipe_diagram::recipe_diagram}; use anyhow::Result; +use hurrycurry_locale::trm; use hurrycurry_protocol::{ Gamedata, Message, book::{Book, BookPage}, @@ -54,7 +55,10 @@ static RECIPE_PAGES: &[RecipePageParams] = &[ pub fn book(data: &Gamedata, serverdata: &Serverdata) -> Result { let mut pages = Vec::new(); - pages.push(BookPage::Contents { table: vec![] }); + pages.push(BookPage::Contents { + title: trm!("b.toc"), + table: vec![], + }); let mut toc = Vec::new(); for &RecipePageParams { name, repr_items } in RECIPE_PAGES { @@ -75,7 +79,7 @@ pub fn book(data: &Gamedata, serverdata: &Serverdata) -> Result { }); } - if let BookPage::Contents { table } = &mut pages[0] { + if let BookPage::Contents { table, .. } = &mut pages[0] { *table = toc; } Ok(Book { pages }) diff --git a/server/tools/src/book_html.rs b/server/tools/src/book_html.rs index 089fc8f9..f915444b 100644 --- a/server/tools/src/book_html.rs +++ b/server/tools/src/book_html.rs @@ -16,6 +16,7 @@ */ +use hurrycurry_locale::Locale; use hurrycurry_protocol::{ Gamedata, Message, book::{Book, BookPage, Diagram}, @@ -23,12 +24,12 @@ use hurrycurry_protocol::{ use crate::diagram_svg::diagram_svg; -pub fn render_html_book(data: &Gamedata, book: &Book) -> String { - BookR { book, data }.to_string() +pub fn render_html_book(data: &Gamedata, book: &Book, locale: &Locale) -> String { + BookR { book, data, locale }.to_string() } markup::define! { - BookR<'a>(data: &'a Gamedata, book: &'a Book) { + BookR<'a>(data: &'a Gamedata, book: &'a Book, locale: &'a Locale) { @markup::doctype() html { head { @@ -37,12 +38,12 @@ markup::define! { } body { @for (index, page) in book.pages.iter().enumerate() { - @PageR { data, page, index } + @PageR { data, locale, page, index } } } } } - PageR<'a>(index: usize, data: &'a Gamedata, page: &'a BookPage) { + PageR<'a>(index: usize, data: &'a Gamedata, locale: &'a Locale, page: &'a BookPage) { section.pagegroup[id=format!("page{index}")] { @match page { BookPage::Cover => { @@ -51,8 +52,8 @@ markup::define! { } BookPage::Recipe { title, description, diagram } => { div.page { - h1 { @MessageR { data, message: title } } - p { @MessageR { data, message: description } } + h1 { @MessageR { data, locale, message: title } } + p { @MessageR { data, locale, message: description } } } div.page { @DiagramR { data, diagram } @@ -62,10 +63,11 @@ markup::define! { div.page {} div.page {} } - BookPage::Contents { table } => { + BookPage::Contents { title, table } => { div.page { + h1 { @MessageR { data, locale, message: title } } ol { @for (label, page) in table { - li { a[href=format!("#page{page}")] { @MessageR { data, message: label } } } + li { a[href=format!("#page{page}")] { @MessageR { data, locale, message: label } } } }} } div.page {} @@ -74,7 +76,7 @@ markup::define! { } } - MessageR<'a>(data: &'a Gamedata, message: &'a Message) { + MessageR<'a>(data: &'a Gamedata, locale: &'a Locale, message: &'a Message) { @match message { Message::Translation { id, params } => { @format!("{:?}", (id, params)) } Message::Text(t) => { @t } diff --git a/server/tools/src/diagram_dot.rs b/server/tools/src/diagram_dot.rs index f5c4714b..fb223dbf 100644 --- a/server/tools/src/diagram_dot.rs +++ b/server/tools/src/diagram_dot.rs @@ -16,6 +16,7 @@ */ +use crate::diagram_svg::node_color; use anyhow::{Result, bail}; use hurrycurry_protocol::{ Gamedata, Message, @@ -27,8 +28,6 @@ use std::{ process::{Command, Stdio}, }; -use crate::diagram_svg::node_color; - pub fn diagram_dot_svg(data: &Gamedata, diagram: &Diagram) -> Result { let mut child = Command::new("dot") .arg("-Tsvg") diff --git a/server/tools/src/main.rs b/server/tools/src/main.rs index 4a22cf8c..d7e5137a 100644 --- a/server/tools/src/main.rs +++ b/server/tools/src/main.rs @@ -39,6 +39,7 @@ use crate::{ }; use anyhow::Result; use clap::Parser; +use hurrycurry_locale::FALLBACK_LOCALE; use hurrycurry_server::data::DataIndex; #[derive(Parser)] @@ -106,7 +107,7 @@ fn main() -> Result<()> { index.reload()?; let (data, serverdata, _) = index.generate("5star")?; let book = book(&data, &serverdata)?; - println!("{}", render_html_book(&data, &book)) + println!("{}", render_html_book(&data, &book, &FALLBACK_LOCALE)) } Action::MapDemands { map } => { let mut index = DataIndex::default(); diff --git a/server/tools/src/recipe_diagram.rs b/server/tools/src/recipe_diagram.rs index b463e3b6..a1ac7efd 100644 --- a/server/tools/src/recipe_diagram.rs +++ b/server/tools/src/recipe_diagram.rs @@ -185,10 +185,10 @@ fn merge_combine_clusters(diag: &mut Diagram) { if outputs .iter() - .all(|&(ei, ni)| diag.nodes[ni].style.is_procuct()) + .all(|&(_, ni)| diag.nodes[ni].style.is_procuct()) && inputs .iter() - .all(|&(ei, ni)| diag.nodes[ni].style.is_procuct()) + .all(|&(_, ni)| diag.nodes[ni].style.is_procuct()) { let mut to_remove = inputs .iter() -- cgit v1.2.3-70-g09d2