From 682cc039a39c373815cec45bb00b766791a850a2 Mon Sep 17 00:00:00 2001 From: Elisabeth Henry Date: Sat, 19 Aug 2023 02:37:24 +0200 Subject: [PATCH] Start replacing crowbook-int in lib --- lang/lib/en.yml | 11 +++++++++++ src/lib/book_bars.rs | 17 +++-------------- src/lib/bookoption.rs | 16 +++++++++------- src/lib/lib.rs | 8 +++----- 4 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 lang/lib/en.yml diff --git a/lang/lib/en.yml b/lang/lib/en.yml new file mode 100644 index 0000000..70e2941 --- /dev/null +++ b/lang/lib/en.yml @@ -0,0 +1,11 @@ +ui: + rendering: Rendering... + waiting: waiting... +error: + no_string: "%{s} is not a string" + no_string_vector: "%{s} is not a string vector" + no_path: "%{s} is not a path" + no_bool: "%{s} is not a boolean" + no_char: "%{s} is not a char" + no_i32: "%{s} is not an i32" + no_f32: "%{s} is not a f32" diff --git a/src/lib/book_bars.rs b/src/lib/book_bars.rs index 7528852..8b6b37e 100644 --- a/src/lib/book_bars.rs +++ b/src/lib/book_bars.rs @@ -21,6 +21,7 @@ use crate::book::{Book, Crowbar, CrowbarState}; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; +use rust_i18n::t; use std::sync::Arc; use std::time::Duration; @@ -79,19 +80,7 @@ impl Book<'_> { .add(ProgressBar::new_spinner()); b.enable_steady_tick(Duration::from_millis(200)); self.bars.mainbar = Some(b); - // let sty = ProgressStyle::default_spinner() - // .tick_chars("πŸ•›πŸ•πŸ•‘πŸ•’πŸ•“πŸ•”πŸ•”πŸ••πŸ•–πŸ•—πŸ•˜πŸ•˜πŸ•™πŸ•šV") - // .tick_chars("/|\\-V") - // .template("{spinner:.dim.bold.yellow} {prefix} {wide_msg}"); self.bar_set_style(Crowbar::Main, CrowbarState::Running); - // self.bars.guard = Some(thread::spawn(move || { - // if let Err(_) = multibar.join() { - // error!( - // "{}", - // lformat!("could not display fancy UI, try running crowbook with --no-fancy") - // ); - // } - // })); } /// Sets a finished message to the progress bar, if it is set @@ -148,12 +137,12 @@ impl Book<'_> { pub fn add_spinner_to_multibar(&mut self, key: &str) -> usize { if let Some(ref multibar) = self.bars.multibar { if let Some(ref mainbar) = self.bars.mainbar { - mainbar.set_message(lformat!("Rendering...")); + mainbar.set_message(t!("ui.rendering")); } let bar = multibar.add(ProgressBar::new_spinner()); bar.enable_steady_tick(Duration::from_millis(200)); - bar.set_message(lformat!("waiting...")); + bar.set_message(t!("ui.waiting")); bar.set_prefix(format!("{key}:")); let i = self.bars.spinners.len(); self.bars.spinners.push(bar); diff --git a/src/lib/bookoption.rs b/src/lib/bookoption.rs index bdc1ca0..1229176 100644 --- a/src/lib/bookoption.rs +++ b/src/lib/bookoption.rs @@ -1,3 +1,5 @@ +use rust_i18n::t; + use crate::error::{Error, Result, Source}; /// Structure for storing a book option @@ -50,7 +52,7 @@ impl BookOption { BookOption::String(ref s) => Ok(s), _ => Err(Error::book_option( Source::empty(), - lformat!("{:?} is not a string", self), + t!("error.no_string", s = format!("{:?}", self)), )), } } @@ -61,7 +63,7 @@ impl BookOption { BookOption::StringVec(ref v) => Ok(v), _ => Err(Error::book_option( Source::empty(), - lformat!("{:?} is not a string vector", self), + t!("error.no_string_vector", s = format!("{:?}", self)), )), } } @@ -72,7 +74,7 @@ impl BookOption { BookOption::Path(ref s) => Ok(s), _ => Err(Error::book_option( Source::empty(), - lformat!("{:?} is not a path", self), + t!("error.no_path", s = format!("{:?}", self)), )), } } @@ -83,7 +85,7 @@ impl BookOption { BookOption::Bool(b) => Ok(b), _ => Err(Error::book_option( Source::empty(), - lformat!("{:?} is not a bool", self), + t!("error.no_bool", s = format!("{:?}", self)), )), } } @@ -94,7 +96,7 @@ impl BookOption { BookOption::Char(c) => Ok(c), _ => Err(Error::book_option( Source::empty(), - lformat!("{:?} is not a char", self), + t!("error.no_char", s = format!("{:?}", self)), )), } } @@ -105,7 +107,7 @@ impl BookOption { BookOption::Int(i) => Ok(i), _ => Err(Error::book_option( Source::empty(), - lformat!("{:?} is not an i32", self), + t!("error.no_i32", s = format!("{:?}", self)), )), } } @@ -116,7 +118,7 @@ impl BookOption { BookOption::Float(f) => Ok(f), _ => Err(Error::book_option( Source::empty(), - lformat!("{:?} is not a f32", self), + t!("error.no_f32", s = format!("{:?}", self)), )), } } diff --git a/src/lib/lib.rs b/src/lib/lib.rs index dda059f..2f91222 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2016, 2017, 2018 Γ‰lisabeth HENRY. +// Copyright (C) 2016-2023 Γ‰lisabeth HENRY. // // This file is part of Crowbook. // @@ -109,10 +109,6 @@ extern crate log; #[macro_use] extern crate lazy_static; -#[cfg(feature = "proofread")] -#[macro_use] -extern crate serde_derive; - pub use book::Book; pub use book_renderer::BookRenderer; pub use bookoption::BookOption; @@ -127,6 +123,8 @@ pub use stats::Stats; pub use token::Data; pub use token::Token; +rust_i18n::i18n!("lang/lib", fallback="en"); + #[macro_use] #[doc(hidden)] mod localize_macros;