feat: add auto detect locale for push command

This commit is contained in:
Dmitriy Pleshevskiy 2022-03-23 23:51:57 +03:00
parent fac102e6be
commit f4b64e8475

View file

@ -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
}