Skip to content

Commit

Permalink
Fix language detecting.
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Aug 13, 2023
1 parent bd1bb49 commit 6b6149d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jarvis"
version = "0.7.6"
version = "0.7.7"
edition = "2021"
rust-version = "1.64"
description = ""
Expand Down
11 changes: 5 additions & 6 deletions src/lang.rs
Original file line number Diff line number Diff line change
@@ -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,
}
Expand All @@ -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(),
}
Expand Down

0 comments on commit 6b6149d

Please sign in to comment.