use greyblake/whatlang-rs to autodect locale

This commit is contained in:
Lonexw 2022-03-23 18:20:10 +08:00 committed by Dmitriy Pleshevskiy
parent da71482813
commit c647b193f3
2 changed files with 9 additions and 0 deletions

View file

@ -17,6 +17,7 @@ readme = "README.md"
[dependencies]
lazy_static = "1.4.0"
regex = "1.3.4"
whatlang = "0.12.0"
[features]
default = ["search"]

View file

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