args: add --locale option
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -230,7 +230,12 @@ impl Notedeck {
|
|||||||
let job_pool = JobPool::default();
|
let job_pool = JobPool::default();
|
||||||
|
|
||||||
// Initialize localization
|
// 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
|
// Initialize global i18n context
|
||||||
//crate::i18n::init_global_i18n(i18n.clone());
|
//crate::i18n::init_global_i18n(i18n.clone());
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ use std::collections::BTreeSet;
|
|||||||
|
|
||||||
use enostr::{Keypair, Pubkey, SecretKey};
|
use enostr::{Keypair, Pubkey, SecretKey};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
use unic_langid::{LanguageIdentifier, LanguageIdentifierError};
|
||||||
|
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
pub relays: Vec<String>,
|
pub relays: Vec<String>,
|
||||||
pub is_mobile: Option<bool>,
|
pub is_mobile: Option<bool>,
|
||||||
|
pub locale: Option<LanguageIdentifier>,
|
||||||
pub show_note_client: bool,
|
pub show_note_client: bool,
|
||||||
pub keys: Vec<Keypair>,
|
pub keys: Vec<Keypair>,
|
||||||
pub light: bool,
|
pub light: bool,
|
||||||
@@ -36,6 +38,7 @@ impl Args {
|
|||||||
use_keystore: true,
|
use_keystore: true,
|
||||||
dbpath: None,
|
dbpath: None,
|
||||||
datapath: None,
|
datapath: None,
|
||||||
|
locale: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
@@ -47,6 +50,23 @@ impl Args {
|
|||||||
res.is_mobile = Some(true);
|
res.is_mobile = Some(true);
|
||||||
} else if arg == "--light" {
|
} else if arg == "--light" {
|
||||||
res.light = true;
|
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" {
|
} else if arg == "--dark" {
|
||||||
res.light = false;
|
res.light = false;
|
||||||
} else if arg == "--debug" {
|
} else if arg == "--debug" {
|
||||||
|
|||||||
Reference in New Issue
Block a user