BlueGit

ict rusty-teams

fix(format): dates and times follow the OS regional format

- Teams desktop formats with the OS region (getLocaleInfoAsync), not the account language
- falls back to the account display language when the OS gives none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-09 · 3 weeks ago

Hash
df4f177f9b9d95bc11094763a778da9eb50a6372
Parent
260814fa
3 files changed +28 −6
crates/app-base/Cargo.toml +1 −0
@@ -29,6 +29,7 @@ tokio.workspace = true
29 29 image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"] }
30 30 raw-window-handle = "0.6"
31 31 sha2 = "0.10"
32 sys-locale = "0.3"
32 33 resvg = { version = "0.46", default-features = false, features = ["text"] }
33 34
34 35 [target.'cfg(target_os = "linux")'.dependencies]
@@ -29,6 +29,7 @@ tokio.workspace = true
29image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"] }
29image = { version = "0.25", default-features = false, features = ["bmp", "gif", "jpeg", "png", "webp"] }
30raw-window-handle = "0.6"
30raw-window-handle = "0.6"
31sha2 = "0.10"
31sha2 = "0.10"
32sys-locale = "0.3"
32resvg = { version = "0.46", default-features = false, features = ["text"] }
33resvg = { version = "0.46", default-features = false, features = ["text"] }
33
34
34[target.'cfg(target_os = "linux")'.dependencies]
35[target.'cfg(target_os = "linux")'.dependencies]
crates/app-base/src/format.rs +20 −0
@@ -25,6 +25,16 @@ pub fn set_date_locale(locale: Option<&str>) {
25 25 DATE_STYLE.with(|style| style.set(locale.map(date_style)));
26 26 }
27 27
28 /// Teams desktop formats dates and times with the OS regional format, not the account language.
29 pub fn os_regional_locale() -> Option<String> {
30 sys_locale::get_locale().as_deref().and_then(normalize_locale)
31 }
32
33 fn normalize_locale(raw: &str) -> Option<String> {
34 let tag = raw.split(['.', '@']).next().unwrap_or_default().replace('_', "-");
35 (!tag.is_empty() && tag != "C" && tag != "POSIX").then_some(tag)
36 }
37
28 38 fn current_date_style() -> Option<DateStyle> {
29 39 DATE_STYLE.with(Cell::get)
30 40 }
@@ -305,6 +315,16 @@ mod tests {
305 315 assert_eq!(team_initials(""), "?");
306 316 }
307 317
318 #[test]
319 fn os_locale_names_become_language_tags() {
320 assert_eq!(normalize_locale("en-GB").as_deref(), Some("en-GB"));
321 assert_eq!(normalize_locale("en_GB.UTF-8").as_deref(), Some("en-GB"));
322 assert_eq!(normalize_locale("de_DE@euro").as_deref(), Some("de-DE"));
323 assert_eq!(normalize_locale("C"), None);
324 assert_eq!(normalize_locale("POSIX"), None);
325 assert_eq!(normalize_locale(""), None);
326 }
327
308 328 #[test]
309 329 fn the_clock_follows_the_display_language() {
310 330 set_date_locale(Some("en-US"));
@@ -25,6 +25,16 @@ pub fn set_date_locale(locale: Option<&str>) {
25 DATE_STYLE.with(|style| style.set(locale.map(date_style)));
25 DATE_STYLE.with(|style| style.set(locale.map(date_style)));
26}
26}
27
27
28/// Teams desktop formats dates and times with the OS regional format, not the account language.
29pub fn os_regional_locale() -> Option<String> {
30 sys_locale::get_locale().as_deref().and_then(normalize_locale)
31}
32
33fn normalize_locale(raw: &str) -> Option<String> {
34 let tag = raw.split(['.', '@']).next().unwrap_or_default().replace('_', "-");
35 (!tag.is_empty() && tag != "C" && tag != "POSIX").then_some(tag)
36}
37
28fn current_date_style() -> Option<DateStyle> {
38fn current_date_style() -> Option<DateStyle> {
29 DATE_STYLE.with(Cell::get)
39 DATE_STYLE.with(Cell::get)
30}
40}
@@ -305,6 +315,16 @@ mod tests {
305 assert_eq!(team_initials(""), "?");
315 assert_eq!(team_initials(""), "?");
306 }
316 }
307
317
318 #[test]
319 fn os_locale_names_become_language_tags() {
320 assert_eq!(normalize_locale("en-GB").as_deref(), Some("en-GB"));
321 assert_eq!(normalize_locale("en_GB.UTF-8").as_deref(), Some("en-GB"));
322 assert_eq!(normalize_locale("de_DE@euro").as_deref(), Some("de-DE"));
323 assert_eq!(normalize_locale("C"), None);
324 assert_eq!(normalize_locale("POSIX"), None);
325 assert_eq!(normalize_locale(""), None);
326 }
327
308 #[test]
328 #[test]
309 fn the_clock_follows_the_display_language() {
329 fn the_clock_follows_the_display_language() {
310 set_date_locale(Some("en-US"));
330 set_date_locale(Some("en-US"));
crates/app-state/src/translation_actions.rs +7 −6
@@ -28,12 +28,13 @@ type TranslationOutcome = Result<Vec<Translation>, String>;
28 28
29 29 impl AppState {
30 30 pub fn apply_date_locale(&self) {
31 crate::format::set_date_locale(
32 self.translation
33 .settings
34 .as_ref()
35 .and_then(|settings| settings.display_locale.as_deref()),
36 );
31 let regional = crate::format::os_regional_locale();
32 let display = self
33 .translation
34 .settings
35 .as_ref()
36 .and_then(|settings| settings.display_locale.as_deref());
37 crate::format::set_date_locale(regional.as_deref().or(display));
37 38 }
38 39
39 40 pub fn load_cached_translation_settings(&mut self) {
@@ -28,12 +28,13 @@ type TranslationOutcome = Result<Vec<Translation>, String>;
28
28
29impl AppState {
29impl AppState {
30 pub fn apply_date_locale(&self) {
30 pub fn apply_date_locale(&self) {
31 crate::format::set_date_locale(
31 let regional = crate::format::os_regional_locale();
32 self.translation
32 let display = self
33 .settings
33 .translation
34 .as_ref()
34 .settings
35 .and_then(|settings| settings.display_locale.as_deref()),
35 .as_ref()
36 );
36 .and_then(|settings| settings.display_locale.as_deref());
37 crate::format::set_date_locale(regional.as_deref().or(display));
37 }
38 }
38
39
39 pub fn load_cached_translation_settings(&mut self) {
40 pub fn load_cached_translation_settings(&mut self) {