diff --git a/Cargo.lock b/Cargo.lock index b25b340..27175fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1610,6 +1610,7 @@ dependencies = [ "env_logger", "futures", "gettext-rs", + "gettext-sys", "gio", "glycin", "gtk4", diff --git a/Cargo.toml b/Cargo.toml index f723301..a418877 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,3 +52,7 @@ features = ["v1_4"] [dependencies.gettext-rs] version = "0.7.0" features = ["gettext-system"] + +[dependencies.gettext-sys] +version = "0.21.3" +features = ["gettext-system"] \ No newline at end of file diff --git a/src/widgets/print.rs b/src/widgets/print.rs index db07b99..d30e9b6 100644 --- a/src/widgets/print.rs +++ b/src/widgets/print.rs @@ -380,6 +380,20 @@ mod imp { .round(obj.image().image_size().0 as f64 * obj.width_unit_factor()), ); + // Default to inch for USA and Liberia + if let Some(unit_locale) = getlocale(gettextrs::LocaleCategory::LcMeasurement) { + if let Some(locale) = unit_locale + .split(|x| *x == b'_') + .nth(1) + .and_then(|x| x.get(0..2)) + { + if locale == b"US" || locale == b"LR" { + imp.margin_unit.set_selected(Unit::Inch as u32); + imp.size_unit.set_selected(Unit::Inch as u32); + } + } + } + imp.print_operation.cancel(); let orientation = match obj.page_setup().orientation() { @@ -902,3 +916,15 @@ extern "C" { max: std::ffi::c_double, ); } + +// TODO: Upstream to gettext if possible +pub fn getlocale(category: gettextrs::LocaleCategory) -> Option> { + unsafe { + let ret = gettext_sys::setlocale(category as i32, std::ptr::null()); + if ret.is_null() { + None + } else { + Some(std::ffi::CStr::from_ptr(ret).to_bytes().to_owned()) + } + } +}