diff --git a/common/src/comp/chat.rs b/common/src/comp/chat.rs index 56cd6664c4..88218a38e4 100644 --- a/common/src/comp/chat.rs +++ b/common/src/comp/chat.rs @@ -196,7 +196,7 @@ pub enum Content { /// deterministic (but pseudorandom) localised output seed: u16, /// i18n arguments - args: HashMap, + args: HashMap, }, } @@ -219,16 +219,16 @@ impl Content { } } - pub fn localized_with_args<'a, S: ToString>( + pub fn localized_with_args<'a, A: Into>( key: impl ToString, - args: impl IntoIterator, + args: impl IntoIterator, ) -> Self { Self::Localized { key: key.to_string(), seed: rand::random(), args: args .into_iter() - .map(|(k, v)| (k.to_string(), v.to_string())) + .map(|(k, v)| (k.to_string(), v.into())) .collect(), } } @@ -242,7 +242,7 @@ impl Content { pub fn localize(&self, i18n_variation: F) -> String where - F: Fn(&str, u16, &HashMap) -> String, + F: Fn(&str, u16, &HashMap) -> String, { match self { Content::Plain(text) => text.to_string(), diff --git a/voxygen/i18n-helpers/src/lib.rs b/voxygen/i18n-helpers/src/lib.rs index dd6df72e39..32614a3c46 100644 --- a/voxygen/i18n-helpers/src/lib.rs +++ b/voxygen/i18n-helpers/src/lib.rs @@ -8,13 +8,32 @@ use hashbrown::HashMap; use i18n::Localization; pub fn make_localizer( - localisation: &Localization, -) -> impl Fn(&str, u16, &HashMap) -> String + Copy + '_ { - move |key: &str, seed: u16, args: &HashMap| { - localisation - .get_variation_ctx(key, seed, &args.iter().collect()) + localization: &Localization, +) -> impl Fn(&str, u16, &HashMap) -> String + Copy + '_ { + fn get( + localization: &Localization, + key: &str, + seed: u16, + args: &HashMap, + ) -> String { + localization + .get_variation_ctx( + key, + seed, + &args + .iter() + .map(|(k, v)| { + ( + k, + v.localize(move |key, seed, args| get(localization, key, seed, args)), + ) + }) + .collect(), + ) .into_owned() } + + move |key: &str, seed: u16, args: &HashMap| get(localization, key, seed, args) } pub fn localize_chat_message( diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 990347d6ff..b1cd3cc503 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -384,7 +384,8 @@ impl SessionState { .new_message(ChatType::CommandError.into_msg(match time { 0 => Content::localized("hud-chat-goodbye"), _ => Content::localized_with_args("hud-chat-connection_lost", [( - "time", time, + "time", + time.to_string(), )]), })); }, @@ -987,7 +988,7 @@ impl PlayState for SessionState { self.hud.new_message(ChatType::Meta.into_msg( Content::localized_with_args( "hud-trade-invite_sent", - [("playername", &name)], + [("playername", name.as_str())], ), )); client.send_invite(uid, InviteKind::Trade)