From f4b64e8475d1992eab95fce8033c46a4a37496ab Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Wed, 23 Mar 2022 23:51:57 +0300 Subject: [PATCH] feat: add auto detect locale for push command --- src/commands/push.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/commands/push.rs b/src/commands/push.rs index aa09825..01fc732 100644 --- a/src/commands/push.rs +++ b/src/commands/push.rs @@ -21,9 +21,21 @@ impl StreamCommand for PushCommand<'_> { self.object, remove_multiline(self.text) ); - if let Some(locale) = self.locale.as_ref() { + + let locale = self.locale.or_else(|| { + whatlang::detect(self.text).and_then(|info| { + if info.confidence() == 1.0 { + Some(info.lang().code()) + } else { + None + } + }) + }); + + if let Some(locale) = locale { message.push_str(&format!(" LANG({})", locale)); } + message.push_str("\r\n"); message }