Skip to content

Commit

Permalink
feat: allow including lemmas to replace in language template
Browse files Browse the repository at this point in the history
  • Loading branch information
BrewingWeasel committed Jul 26, 2024
1 parent 45a8853 commit f98c9ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions data/language_templates/lithuanian.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 16 additions & 8 deletions src-tauri/src/new_language_template.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fs;
use std::{collections::HashMap, fs};

use reqwest::Client;
use serde::Deserialize;
Expand All @@ -15,6 +15,7 @@ struct TemplateDetails {
spyglys_details: bool,
run_on_lemmas: Vec<String>,
suggest_on_lemmas: Vec<String>,
replace_lemmas: HashMap<String, String>,
}

#[tauri::command]
Expand Down Expand Up @@ -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
Expand All @@ -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(())
}

0 comments on commit f98c9ad

Please sign in to comment.