From 6b6149d3b2ca213874b8c889a79a85e590031efa Mon Sep 17 00:00:00 2001 From: 0xZensh Date: Sun, 13 Aug 2023 17:02:56 +0800 Subject: [PATCH] Fix language detecting. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lang.rs | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 34c9852..a10f6a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1282,7 +1282,7 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jarvis" -version = "0.7.6" +version = "0.7.7" dependencies = [ "anyhow", "async-openai", diff --git a/Cargo.toml b/Cargo.toml index eb11588..ace3dcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jarvis" -version = "0.7.6" +version = "0.7.7" edition = "2021" rust-version = "1.64" description = "" diff --git a/src/lang.rs b/src/lang.rs index b06792f..d030b66 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -1,8 +1,7 @@ +pub use isolang::Language; use lingua::LanguageDetectorBuilder; +use std::str::FromStr; -// pub use lingua::IsoCode639_1; -// pub use lingua::Language; -pub use isolang::Language; pub struct LanguageDetector { detector: lingua::LanguageDetector, } @@ -22,9 +21,9 @@ impl LanguageDetector { pub fn detect_lang(&self, text: &str) -> Language { match self.detect(text) { - Some(lang) => match Language::from_name(lang.iso_code_639_3().to_string().as_str()) { - Some(lang) => lang, - None => Language::default(), + Some(lang) => match Language::from_str(lang.iso_code_639_3().to_string().as_str()) { + Ok(lang) => lang, + Err(_) => Language::default(), }, None => Language::default(), }