From f98c9ad92850b4dbad1d9b8f4242d7e1e41e4b47 Mon Sep 17 00:00:00 2001 From: Finn Brewer Date: Fri, 26 Jul 2024 16:03:23 -0700 Subject: [PATCH] feat: allow including lemmas to replace in language template --- data/language_templates/lithuanian.toml | 5 +++++ src-tauri/src/new_language_template.rs | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/data/language_templates/lithuanian.toml b/data/language_templates/lithuanian.toml index c858717..b5e08f6 100644 --- a/data/language_templates/lithuanian.toml +++ b/data/language_templates/lithuanian.toml @@ -27,3 +27,8 @@ fetch_by_default = false [dicts.specific_settings] t = "Wiktionary" c = ["en", "Lithuanian"] + +# Stanza gets these wrong for some reason +[replace_lemmas] +"s" = "nes" +"t" = "bet" diff --git a/src-tauri/src/new_language_template.rs b/src-tauri/src/new_language_template.rs index 61122dd..0ec7a43 100644 --- a/src-tauri/src/new_language_template.rs +++ b/src-tauri/src/new_language_template.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{collections::HashMap, fs}; use reqwest::Client; use serde::Deserialize; @@ -15,6 +15,7 @@ struct TemplateDetails { spyglys_details: bool, run_on_lemmas: Vec, suggest_on_lemmas: Vec, + replace_lemmas: HashMap, } #[tauri::command] @@ -76,7 +77,8 @@ pub async fn new_language_from_template( suggest_on_lemmas: details.suggest_on_lemmas, ..Default::default() }; - if state.settings.languages.contains_key(&language) { + let mut language_name = language.clone(); + if state.settings.languages.contains_key(&language_name) { let mut language_number = 2; while state .settings @@ -85,12 +87,18 @@ pub async fn new_language_from_template( { language_number += 1; } - state - .settings - .languages - .insert(format!("{language} {language_number}"), lang_settings); - } else { - state.settings.languages.insert(language, lang_settings); + language_name = format!("{language} {language_number}"); } + state + .settings + .languages + .insert(language_name.clone(), lang_settings); + state.to_save.language_specific.insert( + language_name, + crate::LanguageSpecficToSave { + lemmas_to_replace: details.replace_lemmas, + ..Default::default() + }, + ); Ok(()) }