im-web: translate device-label fallback and 'on' connector (BrowserWord, device_summary)
Browse files at this commitf465b366125fa96bfe6675072858e457ae2537edParent: 7ff59862 changed files +19 -4
- crates/im-web/src/i18n.rs +14 -0
- crates/im-web/src/pages.rs +5 -4
crates/im-web/src/i18n.rsmodified+14 -0
| @@ -156,6 +156,7 @@ pub enum Key { | |||
| 156 | ViewPhotoAria, | 156 | ViewPhotoAria, |
| 157 | ThisSessionChip, | 157 | ThisSessionChip, |
| 158 | UnknownDevice, | 158 | UnknownDevice, |
| 159 | + BrowserWord, | ||
| 159 | DeviceLabel, | 160 | DeviceLabel, |
| 160 | AddressLabel, | 161 | AddressLabel, |
| 161 | SignedInLabel, | 162 | SignedInLabel, |
| @@ -552,6 +553,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 552 | (ThisSessionChip, Tr) => "Bu oturum", | 553 | (ThisSessionChip, Tr) => "Bu oturum", |
| 553 | (UnknownDevice, En) => "Unknown device", | 554 | (UnknownDevice, En) => "Unknown device", |
| 554 | (UnknownDevice, Tr) => "Bilinmeyen cihaz", | 555 | (UnknownDevice, Tr) => "Bilinmeyen cihaz", |
| 556 | + (BrowserWord, En) => "Browser", | ||
| 557 | + (BrowserWord, Tr) => "Tarayıcı", | ||
| 555 | (DeviceLabel, En) => "Device", | 558 | (DeviceLabel, En) => "Device", |
| 556 | (DeviceLabel, Tr) => "Cihaz", | 559 | (DeviceLabel, Tr) => "Cihaz", |
| 557 | (AddressLabel, En) => "Address", | 560 | (AddressLabel, En) => "Address", |
| @@ -929,6 +932,17 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 929 | } | 932 | } |
| 930 | } | 933 | } |
| 931 | 934 | ||
| 935 | +/// A session's device summary — "Chrome on Linux". The browser and system | ||
| 936 | +/// names are proper nouns and stay as the agent spelled them; only the | ||
| 937 | +/// connector between them follows the viewer's language, and Turkish reads | ||
| 938 | +/// it as a location: "Linux üzerinde Chrome". | ||
| 939 | +pub fn device_summary(lang: Lang, browser: &str, system: &str) -> String { | ||
| 940 | + match lang { | ||
| 941 | + Lang::En => format!("{browser} on {system}"), | ||
| 942 | + Lang::Tr => format!("{system} üzerinde {browser}"), | ||
| 943 | + } | ||
| 944 | +} | ||
| 945 | + | ||
| 932 | /// A user row's "Sessions (N)" disclosure summary, in the viewer's language. | 946 | /// A user row's "Sessions (N)" disclosure summary, in the viewer's language. |
| 933 | pub fn sessions_summary(lang: Lang, n: usize) -> String { | 947 | pub fn sessions_summary(lang: Lang, n: usize) -> String { |
| 934 | match lang { | 948 | match lang { |
crates/im-web/src/pages.rsmodified+5 -4
| @@ -493,8 +493,9 @@ pub(crate) fn escape(raw: &str) -> String { | |||
| 493 | /// header. The full string stays one click away in the session's detail. | 493 | /// header. The full string stays one click away in the session's detail. |
| 494 | /// Substring matching in precedence order (Edge before Chrome before Safari: | 494 | /// Substring matching in precedence order (Edge before Chrome before Safari: |
| 495 | /// each carries the later one's token too); shared with the admin panel. | 495 | /// each carries the later one's token too); shared with the admin panel. |
| 496 | -/// Browser and system names are proper nouns and stay untranslated; only the | 496 | +/// Browser and system names are proper nouns and stay as the agent spelled |
| 497 | -/// unknown-device fallback follows the viewer's language. | 497 | +/// them; the connector and the generic fallback follow the viewer's language |
| 498 | +/// (`i18n::device_summary`, `Key::BrowserWord`). | ||
| 498 | pub(crate) fn device_label(agent: Option<&str>, lang: Lang) -> String { | 499 | pub(crate) fn device_label(agent: Option<&str>, lang: Lang) -> String { |
| 499 | let Some(agent) = agent.filter(|agent| !agent.is_empty()) else { | 500 | let Some(agent) = agent.filter(|agent| !agent.is_empty()) else { |
| 500 | return t(lang, Key::UnknownDevice).to_string(); | 501 | return t(lang, Key::UnknownDevice).to_string(); |
| @@ -508,7 +509,7 @@ pub(crate) fn device_label(agent: Option<&str>, lang: Lang) -> String { | |||
| 508 | } else if agent.contains("Safari/") { | 509 | } else if agent.contains("Safari/") { |
| 509 | "Safari" | 510 | "Safari" |
| 510 | } else { | 511 | } else { |
| 511 | - "Browser" | 512 | + return t(lang, Key::BrowserWord).to_string(); |
| 512 | }; | 513 | }; |
| 513 | let system = if agent.contains("iPhone") { | 514 | let system = if agent.contains("iPhone") { |
| 514 | "iPhone" | 515 | "iPhone" |
| @@ -527,7 +528,7 @@ pub(crate) fn device_label(agent: Option<&str>, lang: Lang) -> String { | |||
| 527 | } else { | 528 | } else { |
| 528 | return browser.to_string(); | 529 | return browser.to_string(); |
| 529 | }; | 530 | }; |
| 530 | - format!("{browser} on {system}") | 531 | + crate::i18n::device_summary(lang, browser, system) |
| 531 | } | 532 | } |
| 532 | 533 | ||
| 533 | /// `2026-09-04 10:22`: the last-seen stamp. An unrenderable stamp falls back | 534 | /// `2026-09-04 10:22`: the last-seen stamp. An unrenderable stamp falls back |