commit ec87482009469602a5488c0ac3b23eb493bb7149
parent a077cae0eec82fb708c181bbdba9aed2509dce60
Author: William Casarin <jb55@jb55.com>
Date: Tue, 22 Jul 2025 13:01:53 -0700
args: add --locale option
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/crates/notedeck/src/app.rs b/crates/notedeck/src/app.rs
@@ -230,7 +230,12 @@ impl Notedeck {
let job_pool = JobPool::default();
// Initialize localization
- let i18n = Localization::new();
+ let mut i18n = Localization::new();
+ if let Some(locale) = &parsed_args.locale {
+ if let Err(err) = i18n.set_locale(locale.to_owned()) {
+ error!("{err}");
+ }
+ }
// Initialize global i18n context
//crate::i18n::init_global_i18n(i18n.clone());
diff --git a/crates/notedeck/src/args.rs b/crates/notedeck/src/args.rs
@@ -2,10 +2,12 @@ use std::collections::BTreeSet;
use enostr::{Keypair, Pubkey, SecretKey};
use tracing::error;
+use unic_langid::{LanguageIdentifier, LanguageIdentifierError};
pub struct Args {
pub relays: Vec<String>,
pub is_mobile: Option<bool>,
+ pub locale: Option<LanguageIdentifier>,
pub show_note_client: bool,
pub keys: Vec<Keypair>,
pub light: bool,
@@ -36,6 +38,7 @@ impl Args {
use_keystore: true,
dbpath: None,
datapath: None,
+ locale: None,
};
let mut i = 0;
@@ -47,6 +50,23 @@ impl Args {
res.is_mobile = Some(true);
} else if arg == "--light" {
res.light = true;
+ } else if arg == "--locale" {
+ i += 1;
+ let Some(locale) = args.get(i) else {
+ panic!("locale argument missing?");
+ };
+ let parsed: Result<LanguageIdentifier, LanguageIdentifierError> = locale.parse();
+ match parsed {
+ Err(err) => {
+ panic!("locale failed to parse: {err}");
+ }
+ Ok(locale) => {
+ tracing::info!(
+ "parsed locale '{locale}' from args, not sure if we have it yet though."
+ );
+ res.locale = Some(locale);
+ }
+ }
} else if arg == "--dark" {
res.light = false;
} else if arg == "--debug" {