Skip to content

Commit

Permalink
feat: proper source lang selection
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiErikNiermann committed Sep 9, 2023
1 parent ea8089b commit 3ca7fcb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ This is kind of the absolute basic use case I imagined, of just being able to ca

- There is no downloading or uploading images anywhere and you don't need to pull out your phone, you just select exactly what you want to translate.

With the core idea here being that you can translate anything anywhere on your desktop with the click of a button. Also a neat addition is the fact that this does not trigger the security black out you get with traditional tools like snipping tool in websites like crunchyroll, everything on the screen is unaffected even though you are still capturing screenshots.
With the core idea here being that you can translate anything anywhere on your desktop with the click of a button. Also a neat addition is the fact that this does not trigger the security black-out during capture you get with traditional software like snipping tool in websites using EME for DRM, everything on the screen is unaffected even though you are still capturing screenshots.

The final image of the videoplayer is still black but for our purposes; since we only want the subtitles; this is basically to our benefit.

### Whats next ?

Expand Down
Binary file added assets/placeholder_de.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
21 changes: 13 additions & 8 deletions libs/lib_gui/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn take_sc() {
}
}

fn get_lang_choices(deepl: &lib_translator::DeepL) -> HashMap<String, MenuItem> {
fn get_target_langs(deepl: &lib_translator::DeepL) -> HashMap<String, MenuItem> {
let res: Vec<lib_translator::Language> = match deepl.get_supported() {
Ok(res) => res,
Err(_) => panic!("Error getting supported languages"),
Expand All @@ -67,8 +67,7 @@ fn get_lang_choices(deepl: &lib_translator::DeepL) -> HashMap<String, MenuItem>
.collect::<HashMap<String, MenuItem>>()
}

fn get_lang_dropdown(deepl: &lib_translator::DeepL, lang_choice: &Label) -> Menu {
let lang_choices = get_lang_choices(deepl);
fn get_lang_dropdown(deepl: &lib_translator::DeepL, lang_choice: &Label, lang_choices: HashMap<String, MenuItem>) -> Menu {
let lang_menu = Menu::new();
for (lang_code_str, lang_choice_item) in lang_choices {
lang_menu.append(&lang_choice_item);
Expand All @@ -82,6 +81,13 @@ fn get_lang_dropdown(deepl: &lib_translator::DeepL, lang_choice: &Label) -> Menu
lang_menu
}

fn get_src_langs() -> HashMap<String, MenuItem> {
lib_ocr::get_tesseract_supported()
.into_iter()
.map(|lang_code| (lang_code.clone(), MenuItem::with_label(&lang_code)))
.collect::<HashMap<String, MenuItem>>()
}

pub fn build_ui(
application: &Application,
mainwindow: &ApplicationWindow,
Expand Down Expand Up @@ -156,8 +162,8 @@ pub fn build_ui(
api_key_label.set_text(&api_key);
let deepl = &mut lib_translator::DeepL::new(String::from(api_key));

source.set_submenu(Some(&get_lang_dropdown(&deepl, &source_lang_choice)));
target.set_submenu(Some(&get_lang_dropdown(&deepl, &target_lang_choice)));
source.set_submenu(Some(&get_lang_dropdown(&deepl, &source_lang_choice, get_src_langs())));
target.set_submenu(Some(&get_lang_dropdown(&deepl, &target_lang_choice, get_target_langs(deepl))));

mainwindow.show_all();
textwindow.show_all();
Expand All @@ -182,15 +188,14 @@ fn add_actions(

take_sc();

// let from_lang = source_lang_choice.text();
let from_lang = "eng";
let from_lang = source_lang_choice.text();
let to_lang = target_lang_choice.text();

#[cfg(target_os = "windows")]
let text = lib_ocr::run_ocr("./screenshot.png", &from_lang);

#[cfg(target_os = "linux")]
let text = lib_ocr::run_ocr("./placeholder.png", &from_lang);
let text = lib_ocr::run_ocr("./assets/placeholder_de.png", &from_lang);

let api_key = api_key_label.text().to_string();
let deepl = lib_translator::DeepL::new(api_key);
Expand Down
5 changes: 5 additions & 0 deletions libs/lib_ocr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ pub mod image;
pub mod text;
pub mod win_sc;

pub fn get_tesseract_supported() -> Vec<String> {
rusty_tesseract::get_tesseract_langs()
.unwrap()
}

pub fn run_ocr(path: &str, lang: &str) -> String {
let img = image::get_image(path);
return text::clean_text(&image::text_from_image(
Expand Down

0 comments on commit 3ca7fcb

Please sign in to comment.