From e8019380a8134aeffaa03202099addc67d0e921b Mon Sep 17 00:00:00 2001 From: jaap aarts Date: Sun, 11 Jul 2021 13:08:06 +0200 Subject: [PATCH 1/5] Fix localisation stipping in GTK and X11 --- druid-shell/src/backend/gtk/application.rs | 6 +++++- druid-shell/src/backend/x11/application.rs | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/druid-shell/src/backend/gtk/application.rs b/druid-shell/src/backend/gtk/application.rs index d6d615b3be..95b067d137 100644 --- a/druid-shell/src/backend/gtk/application.rs +++ b/druid-shell/src/backend/gtk/application.rs @@ -84,7 +84,11 @@ impl Application { } pub fn get_locale() -> String { - glib::get_language_names()[0].as_str().into() + let mut locale: String = glib::get_language_names()[0].as_str().into(); + if let Some(idx) = locale.chars().position(|c| c == '.') { + locale.truncate(idx); + } + locale } } diff --git a/druid-shell/src/backend/x11/application.rs b/druid-shell/src/backend/x11/application.rs index acec8042b1..af8f6712da 100644 --- a/druid-shell/src/backend/x11/application.rs +++ b/druid-shell/src/backend/x11/application.rs @@ -778,14 +778,18 @@ impl Application { // from gettext manual // https://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html#Locale-Environment-Variables - var_non_empty("LANGUAGE") + let mut locale = var_non_empty("LANGUAGE") // the LANGUAGE value is priority list seperated by : // See: https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable .and_then(|locale| locale.split(':').next().map(String::from)) .or_else(|| var_non_empty("LC_ALL")) .or_else(|| var_non_empty("LC_MESSAGES")) .or_else(|| var_non_empty("LANG")) - .unwrap_or_else(|| "en-US".to_string()) + .unwrap_or_else(|| "en-US".to_string()); + if let Some(idx) = locale.chars().position(|c| c == '.') { + locale.truncate(idx); + } + locale } pub(crate) fn idle_pipe(&self) -> RawFd { From 1e5efc0b2e813f9b376ba507350114e7f16e6f4f Mon Sep 17 00:00:00 2001 From: jaap aarts Date: Sun, 11 Jul 2021 13:20:44 +0200 Subject: [PATCH 2/5] Normalise splitting across backends --- druid-shell/src/backend/gtk/application.rs | 2 +- druid-shell/src/backend/mac/application.rs | 2 +- druid-shell/src/backend/x11/application.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/druid-shell/src/backend/gtk/application.rs b/druid-shell/src/backend/gtk/application.rs index 95b067d137..973bf22a4f 100644 --- a/druid-shell/src/backend/gtk/application.rs +++ b/druid-shell/src/backend/gtk/application.rs @@ -85,7 +85,7 @@ impl Application { pub fn get_locale() -> String { let mut locale: String = glib::get_language_names()[0].as_str().into(); - if let Some(idx) = locale.chars().position(|c| c == '.') { + if let Some(idx) = locale.chars().position(|c| c == '.' || c == '@') { locale.truncate(idx); } locale diff --git a/druid-shell/src/backend/mac/application.rs b/druid-shell/src/backend/mac/application.rs index bbde4678e9..668dc2cee3 100644 --- a/druid-shell/src/backend/mac/application.rs +++ b/druid-shell/src/backend/mac/application.rs @@ -111,7 +111,7 @@ impl Application { let locale: id = msg_send![nslocale_class, currentLocale]; let ident: id = msg_send![locale, localeIdentifier]; let mut locale = util::from_nsstring(ident); - if let Some(idx) = locale.chars().position(|c| c == '@') { + if let Some(idx) = locale.chars().position(|c| c == '.' || c == '@') { locale.truncate(idx); } locale diff --git a/druid-shell/src/backend/x11/application.rs b/druid-shell/src/backend/x11/application.rs index af8f6712da..33dc0cd02d 100644 --- a/druid-shell/src/backend/x11/application.rs +++ b/druid-shell/src/backend/x11/application.rs @@ -786,7 +786,7 @@ impl Application { .or_else(|| var_non_empty("LC_MESSAGES")) .or_else(|| var_non_empty("LANG")) .unwrap_or_else(|| "en-US".to_string()); - if let Some(idx) = locale.chars().position(|c| c == '.') { + if let Some(idx) = locale.chars().position(|c| c == '.' || c == '@') { locale.truncate(idx); } locale From bd57341ab1669c6cf9f57fbf03fac43a78007968 Mon Sep 17 00:00:00 2001 From: jaap aarts Date: Sun, 11 Jul 2021 14:33:29 +0200 Subject: [PATCH 3/5] Add comment explaning the locale stipping --- druid-shell/src/backend/gtk/application.rs | 1 + druid-shell/src/backend/mac/application.rs | 1 + druid-shell/src/backend/x11/application.rs | 3 +++ 3 files changed, 5 insertions(+) diff --git a/druid-shell/src/backend/gtk/application.rs b/druid-shell/src/backend/gtk/application.rs index 973bf22a4f..53e0e80f55 100644 --- a/druid-shell/src/backend/gtk/application.rs +++ b/druid-shell/src/backend/gtk/application.rs @@ -85,6 +85,7 @@ impl Application { pub fn get_locale() -> String { let mut locale: String = glib::get_language_names()[0].as_str().into(); + // This is done because the locale parsing library we use expects an unicode locale, but these vars have an ISO locale if let Some(idx) = locale.chars().position(|c| c == '.' || c == '@') { locale.truncate(idx); } diff --git a/druid-shell/src/backend/mac/application.rs b/druid-shell/src/backend/mac/application.rs index 668dc2cee3..011fbfe735 100644 --- a/druid-shell/src/backend/mac/application.rs +++ b/druid-shell/src/backend/mac/application.rs @@ -111,6 +111,7 @@ impl Application { let locale: id = msg_send![nslocale_class, currentLocale]; let ident: id = msg_send![locale, localeIdentifier]; let mut locale = util::from_nsstring(ident); + // This is done because the locale parsing library we use expects an unicode locale, but these vars have an ISO locale if let Some(idx) = locale.chars().position(|c| c == '.' || c == '@') { locale.truncate(idx); } diff --git a/druid-shell/src/backend/x11/application.rs b/druid-shell/src/backend/x11/application.rs index 33dc0cd02d..a734f6fcab 100644 --- a/druid-shell/src/backend/x11/application.rs +++ b/druid-shell/src/backend/x11/application.rs @@ -22,6 +22,7 @@ use std::rc::Rc; use std::time::{Duration, Instant}; use anyhow::{anyhow, Context, Error}; +use tracing::debug; use x11rb::connection::{Connection, RequestConnection}; use x11rb::protocol::present::ConnectionExt as _; use x11rb::protocol::render::{self, ConnectionExt as _, Pictformat}; @@ -786,6 +787,8 @@ impl Application { .or_else(|| var_non_empty("LC_MESSAGES")) .or_else(|| var_non_empty("LANG")) .unwrap_or_else(|| "en-US".to_string()); + + // This is done because the locale parsing library we use expects an unicode locale, but these vars have an ISO locale if let Some(idx) = locale.chars().position(|c| c == '.' || c == '@') { locale.truncate(idx); } From f9da6f9c9dbf9d4dae0bf4b862c795578356cd41 Mon Sep 17 00:00:00 2001 From: jaap aarts Date: Sun, 11 Jul 2021 14:51:48 +0200 Subject: [PATCH 4/5] Remove import --- druid-shell/src/backend/x11/application.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/druid-shell/src/backend/x11/application.rs b/druid-shell/src/backend/x11/application.rs index a734f6fcab..bb6c2b3853 100644 --- a/druid-shell/src/backend/x11/application.rs +++ b/druid-shell/src/backend/x11/application.rs @@ -22,7 +22,6 @@ use std::rc::Rc; use std::time::{Duration, Instant}; use anyhow::{anyhow, Context, Error}; -use tracing::debug; use x11rb::connection::{Connection, RequestConnection}; use x11rb::protocol::present::ConnectionExt as _; use x11rb::protocol::render::{self, ConnectionExt as _, Pictformat}; From ca4b99d5ad29f6a48e723478da34446bd8906da1 Mon Sep 17 00:00:00 2001 From: jaap aarts Date: Thu, 15 Jul 2021 20:17:52 +0200 Subject: [PATCH 5/5] Remove added check in mac backend --- druid-shell/src/backend/mac/application.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/druid-shell/src/backend/mac/application.rs b/druid-shell/src/backend/mac/application.rs index 011fbfe735..b303e1fdbc 100644 --- a/druid-shell/src/backend/mac/application.rs +++ b/druid-shell/src/backend/mac/application.rs @@ -112,7 +112,7 @@ impl Application { let ident: id = msg_send![locale, localeIdentifier]; let mut locale = util::from_nsstring(ident); // This is done because the locale parsing library we use expects an unicode locale, but these vars have an ISO locale - if let Some(idx) = locale.chars().position(|c| c == '.' || c == '@') { + if let Some(idx) = locale.chars().position(|c| c == '@') { locale.truncate(idx); } locale