From c647b193f3ed469ec4ea02a3a85deb47a4253f9b Mon Sep 17 00:00:00 2001 From: Lonexw Date: Wed, 23 Mar 2022 18:20:10 +0800 Subject: [PATCH] use greyblake/whatlang-rs to autodect locale --- Cargo.toml | 1 + src/commands/query.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index efec271..e00c6f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ readme = "README.md" [dependencies] lazy_static = "1.4.0" regex = "1.3.4" +whatlang = "0.12.0" [features] default = ["search"] diff --git a/src/commands/query.rs b/src/commands/query.rs index 8823a7c..66b94f9 100644 --- a/src/commands/query.rs +++ b/src/commands/query.rs @@ -1,4 +1,5 @@ use super::StreamCommand; +use whatlang::{detect}; use crate::result::*; use regex::Regex; @@ -32,6 +33,13 @@ impl StreamCommand for QueryCommand<'_> { if let Some(offset) = self.offset.as_ref() { message.push_str(&format!(" OFFSET({})", offset)); } + + // use greyblake/whatlang-rs to autodect locale + let text = detect(self.terms).unwrap(); + if text.confidence() == 1.0 { + message.push_str(&format!(" LANG({})", text.lang().code())); + } + message.push_str("\r\n"); message }