diff --git a/locales/app.yml b/locales/app.yml index 17e3bb2..b7d41bb 100644 --- a/locales/app.yml +++ b/locales/app.yml @@ -1,8 +1,22 @@ _version: 2 + +search_placeholder: + en: Search + fr: Recherche + zh: 搜索 + ja: 検索 + es: Buscar + apps: en: Applications fr: Applications + zh: 应用程序 + ja: アプリケーション + es: Aplicaciones expr_eval: en: Expression evaluation fr: Évaluation de l'expression + zh: 表达式评估 + ja: 式評価 + es: Evaluación de expresiones diff --git a/src/conf.rs b/src/conf.rs index 79e279c..90eed14 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -1,20 +1,9 @@ +use rust_i18n::t; use std::io::{Read, Write}; - use tracing::{debug, warn}; pub const APP_ID: &str = "dev.luxluth.seekr"; -pub const DEFAULT_CONFIG: &str = r#"# General seekr application config -[general] - -# icon theme -theme = Adwaita - -# terminal used to run shell based programs -terminal = kitty - -# terminal launch args -args = -e -"#; +pub const DEFAULT_CONFIG: &str = include_str!("./default.conf"); pub const DEFAULT_CSS: &str = include_str!("./style.css"); @@ -23,6 +12,7 @@ pub struct GeneralConf { pub theme: String, pub terminal: String, pub args: Vec, + pub search_placeholder: String, } impl Default for GeneralConf { @@ -31,6 +21,7 @@ impl Default for GeneralConf { theme: "Adwaita".to_string(), terminal: "kitty".to_string(), args: vec!["-e".to_string()], + search_placeholder: t!("search_placeholder").to_string(), } } } @@ -75,8 +66,8 @@ impl Config { ini_roundtrip::Item::Property { key: "theme", val, .. } => { - if is_in_general { - general.theme = val.unwrap_or("Adwaita").trim().to_string(); + if is_in_general && val.is_some() { + general.theme = val.unwrap().trim().to_string(); } } ini_roundtrip::Item::Property { @@ -84,22 +75,31 @@ impl Config { val, .. } => { - if is_in_general { - general.terminal = val.unwrap_or("kitty").trim().to_string(); + if is_in_general && val.is_some() { + general.terminal = val.unwrap().trim().to_string(); } } ini_roundtrip::Item::Property { key: "args", val, .. } => { - if is_in_general { + if is_in_general && val.is_some() { general.args = val - .unwrap_or("-e") + .unwrap() .trim() .split(' ') .map(|x| x.to_string()) .collect(); } } + ini_roundtrip::Item::Property { + key: "search_placeholder", + val, + .. + } => { + if is_in_general && val.is_some() { + general.search_placeholder = val.unwrap().to_string(); + } + } _ => {} } } @@ -126,7 +126,11 @@ pub fn init_config_dir() -> std::path::PathBuf { if !config_file.exists() { if let Ok(mut f) = std::fs::File::create(&config_file) { - let _ = f.write(DEFAULT_CONFIG.as_bytes()); + let _ = f.write( + DEFAULT_CONFIG + .replace("%PLACEHOLDER%", &t!("search_placeholder").to_string()) + .as_bytes(), + ); } } diff --git a/src/default.conf b/src/default.conf new file mode 100644 index 0000000..3c2aa11 --- /dev/null +++ b/src/default.conf @@ -0,0 +1,14 @@ +# General seekr application config +[general] + +# search placeholder text +# search_placeholder = %PLACEHOLDER% + +# icon theme +theme = Adwaita + +# terminal used to run shell based programs +terminal = kitty + +# terminal launch args +args = -e diff --git a/src/main.rs b/src/main.rs index dfd63b0..34eb5f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,7 +73,7 @@ fn activate(config: conf::Config, app: &Application) { .hexpand(true) .css_name("input") .activates_default(true) - .placeholder_text("Search with Seekr") + .placeholder_text(&config.general.search_placeholder) .build(); entry.connect_changed(glib::clone!(