Skip to content

Commit

Permalink
i18n translations
Browse files Browse the repository at this point in the history
  • Loading branch information
luxluth committed Dec 14, 2024
1 parent 90dfd00 commit 13f0b2b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
14 changes: 14 additions & 0 deletions locales/app.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 24 additions & 20 deletions src/conf.rs
Original file line number Diff line number Diff line change
@@ -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");

Expand All @@ -23,6 +12,7 @@ pub struct GeneralConf {
pub theme: String,
pub terminal: String,
pub args: Vec<String>,
pub search_placeholder: String,
}

impl Default for GeneralConf {
Expand All @@ -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(),
}
}
}
Expand Down Expand Up @@ -75,31 +66,40 @@ 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 {
key: "terminal",
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();
}
}
_ => {}
}
}
Expand All @@ -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(),
);
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/default.conf
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit 13f0b2b

Please sign in to comment.