use greyblake/whatlang-rs to autodect locale
This commit is contained in:
parent
da71482813
commit
c647b193f3
2 changed files with 9 additions and 0 deletions
|
@ -17,6 +17,7 @@ readme = "README.md"
|
|||
[dependencies]
|
||||
lazy_static = "1.4.0"
|
||||
regex = "1.3.4"
|
||||
whatlang = "0.12.0"
|
||||
|
||||
[features]
|
||||
default = ["search"]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue