-
-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
684 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
pub fn init_lang_detect() { | ||
use lingua::{Language, LanguageDetectorBuilder}; | ||
let languages = vec![ | ||
Language::Chinese, | ||
Language::Japanese, | ||
Language::English, | ||
Language::Korean, | ||
Language::French, | ||
Language::Spanish, | ||
Language::German, | ||
Language::Russian, | ||
Language::Italian, | ||
Language::Portuguese, | ||
Language::Turkish, | ||
Language::Arabic, | ||
Language::Vietnamese, | ||
Language::Thai, | ||
Language::Indonesian, | ||
Language::Malay, | ||
Language::Hindi, | ||
Language::Mongolian, | ||
]; | ||
let detector = LanguageDetectorBuilder::from_languages(&languages) | ||
.with_preloaded_language_models() | ||
.build(); | ||
let _ = detector.detect_language_of("Hello Language"); | ||
} | ||
#[tauri::command] | ||
pub fn lang_detect(text: &str) -> Result<&str, ()> { | ||
use lingua::{Language, LanguageDetectorBuilder}; | ||
let languages = vec![ | ||
Language::Chinese, | ||
Language::Japanese, | ||
Language::English, | ||
Language::Korean, | ||
Language::French, | ||
Language::Spanish, | ||
Language::German, | ||
Language::Russian, | ||
Language::Italian, | ||
Language::Portuguese, | ||
Language::Turkish, | ||
Language::Arabic, | ||
Language::Vietnamese, | ||
Language::Thai, | ||
Language::Indonesian, | ||
Language::Malay, | ||
Language::Hindi, | ||
Language::Mongolian, | ||
]; | ||
let detector = LanguageDetectorBuilder::from_languages(&languages) | ||
.with_preloaded_language_models() | ||
.build(); | ||
if let Some(lang) = detector.detect_language_of(text) { | ||
match lang { | ||
Language::Chinese => Ok("zh_cn"), | ||
Language::Japanese => Ok("ja"), | ||
Language::English => Ok("en"), | ||
Language::Korean => Ok("ko"), | ||
Language::French => Ok("fr"), | ||
Language::Spanish => Ok("es"), | ||
Language::German => Ok("de"), | ||
Language::Russian => Ok("ru"), | ||
Language::Italian => Ok("it"), | ||
Language::Portuguese => Ok("pt_pt"), | ||
Language::Turkish => Ok("tr"), | ||
Language::Arabic => Ok("ar"), | ||
Language::Vietnamese => Ok("vi"), | ||
Language::Thai => Ok("th"), | ||
Language::Indonesian => Ok("id"), | ||
Language::Malay => Ok("ms"), | ||
Language::Hindi => Ok("hi"), | ||
Language::Mongolian => Ok("mn_cy"), | ||
} | ||
} else { | ||
return Ok(""); | ||
} | ||
} |
Oops, something went wrong.
a5f9e65
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#231