diff options
| -rw-r--r-- | server/src/message.rs | 27 | 
1 files changed, 25 insertions, 2 deletions
| diff --git a/server/src/message.rs b/server/src/message.rs index 069c2b0b..5a15c472 100644 --- a/server/src/message.rs +++ b/server/src/message.rs @@ -18,7 +18,12 @@  use anyhow::{anyhow, Result};  use hurrycurry_protocol::Message; -use std::{collections::HashMap, fmt::Debug, ops::Index, sync::LazyLock}; +use std::{ +    collections::HashMap, +    fmt::{Debug, Display}, +    ops::Index, +    sync::LazyLock, +};  #[macro_export]  macro_rules! trm { @@ -72,6 +77,24 @@ impl Debug for TrError {          }      }  } +impl Display for TrError { +    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +        match self { +            TrError::Tr { id, params } => { +                if params.is_empty() { +                    write!(f, "{}", tr(id)) +                } else { +                    let mut s = tr(id).to_string(); +                    for (i, p) in params.iter().enumerate() { +                        s = s.replace(&format!("{{{i}}}"), &format!("{p:?}")); +                    } +                    write!(f, "{s}") +                } +            } +            TrError::Plain(s) => write!(f, "{s}"), +        } +    } +}  #[macro_export]  macro_rules! tre { @@ -126,6 +149,6 @@ impl Strings {  }  static TR: LazyLock<Strings> = LazyLock::new(|| Strings::load().unwrap()); -pub fn tr<'a>(s: &'static str) -> &'a str { +pub fn tr(s: &'static str) -> &'static str {      &TR[s]  } | 
