iz: route remaining hardcoded UI strings through t()
Browse files at this commit66ac68631839fb0b2a59be6b607b7ef2fe653ff1Parent: 30596376 changed files +77 -43
- crates/iz-core/src/detail.rs +0 -18
- crates/iz-core/tests/store.rs +0 -5
- crates/iz-web/src/detail.rs +13 -2
- crates/iz-web/src/files.rs +6 -5
- crates/iz-web/src/i18n.rs +37 -0
- crates/iz-web/src/settings.rs +21 -13
crates/iz-core/src/detail.rsmodified+0 -18
| @@ -41,24 +41,6 @@ impl DependencyEdge { | |||
| 41 | self.cleared_at.is_some() || self.done_at.is_some() | 41 | self.cleared_at.is_some() || self.done_at.is_some() |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | - /// The right-hand note on a `BLOCKED BY` row: `cleared Aug 16`, or what is | ||
| 45 | - /// still in the way. | ||
| 46 | - pub fn blocked_by_label(&self) -> String { | ||
| 47 | - match (self.cleared_at, self.done_at) { | ||
| 48 | - (Some(at), _) => format!("cleared {}", day_label(at.date())), | ||
| 49 | - (None, Some(at)) => format!("done {}", day_label(at.date())), | ||
| 50 | - (None, None) => "blocking this task".to_string(), | ||
| 51 | - } | ||
| 52 | - } | ||
| 53 | - | ||
| 54 | - /// The same note on a `BLOCKS` row. | ||
| 55 | - pub fn blocks_label(&self) -> String { | ||
| 56 | - if self.is_cleared() { | ||
| 57 | - "no longer waiting".to_string() | ||
| 58 | - } else { | ||
| 59 | - "waiting on this task".to_string() | ||
| 60 | - } | ||
| 61 | - } | ||
| 62 | } | 44 | } |
| 63 | 45 | ||
| 64 | /// One file hung off a task, as the detail screen prints it. | 46 | /// One file hung off a task, as the detail screen prints it. |
crates/iz-core/tests/store.rsmodified+0 -5
| @@ -1926,11 +1926,6 @@ async fn a_task_detail_carries_both_directions_of_its_dependencies() { | |||
| 1926 | assert_eq!(blocked_by, ["before"]); | 1926 | assert_eq!(blocked_by, ["before"]); |
| 1927 | assert_eq!(blocks, ["after"]); | 1927 | assert_eq!(blocks, ["after"]); |
| 1928 | assert!(detail.is_blocked()); | 1928 | assert!(detail.is_blocked()); |
| 1929 | - assert_eq!( | ||
| 1930 | - detail.blocked_by[0].blocked_by_label(), | ||
| 1931 | - "blocking this task" | ||
| 1932 | - ); | ||
| 1933 | - assert_eq!(detail.blocks[0].blocks_label(), "waiting on this task"); | ||
| 1934 | } | 1929 | } |
| 1935 | 1930 | ||
| 1936 | #[tokio::test] | 1931 | #[tokio::test] |
crates/iz-web/src/detail.rsmodified+13 -2
| @@ -1818,8 +1818,19 @@ async fn dep_row<'a>( | |||
| 1818 | ) -> Result<impl View + 'a> { | 1818 | ) -> Result<impl View + 'a> { |
| 1819 | let cleared = edge.is_cleared(); | 1819 | let cleared = edge.is_cleared(); |
| 1820 | let note = match direction { | 1820 | let note = match direction { |
| 1821 | - Direction::BlockedBy => edge.blocked_by_label(), | 1821 | + Direction::BlockedBy => match (edge.cleared_at, edge.done_at) { |
| 1822 | - Direction::Blocks => edge.blocks_label(), | 1822 | + (Some(at), _) => crate::i18n::cleared_dep_label( |
| 1823 | + lang, | ||
| 1824 | + &iz_core::board::day_label(at.date()), | ||
| 1825 | + ), | ||
| 1826 | + (None, Some(at)) => crate::i18n::done_dep_label( | ||
| 1827 | + lang, | ||
| 1828 | + &iz_core::board::day_label(at.date()), | ||
| 1829 | + ), | ||
| 1830 | + (None, None) => t(lang, Key::BlocksThisTask).to_string(), | ||
| 1831 | + }, | ||
| 1832 | + Direction::Blocks if cleared => t(lang, Key::NoLongerWaiting).to_string(), | ||
| 1833 | + Direction::Blocks => t(lang, Key::WaitsOnThisTask).to_string(), | ||
| 1823 | }; | 1834 | }; |
| 1824 | let waiting = matches!(direction, Direction::BlockedBy) && !cleared; | 1835 | let waiting = matches!(direction, Direction::BlockedBy) && !cleared; |
| 1825 | let wire = match direction { | 1836 | let wire = match direction { |
crates/iz-web/src/files.rsmodified+6 -5
| @@ -226,12 +226,13 @@ fn not_found() -> (StatusCode, HeaderMap, Vec<u8>) { | |||
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | /// The 503 a stored attachment serves when the Files service cannot be | 228 | /// The 503 a stored attachment serves when the Files service cannot be |
| 229 | -/// reached — one plain line, and never the 404, because the row exists. | 229 | +/// reached — one plain line in the reader's language, and never the 404, |
| 230 | -fn service_unavailable() -> (StatusCode, HeaderMap, Vec<u8>) { | 230 | +/// because the row exists. |
| 231 | +fn service_unavailable(lang: crate::i18n::Lang) -> (StatusCode, HeaderMap, Vec<u8>) { | ||
| 231 | ( | 232 | ( |
| 232 | StatusCode::SERVICE_UNAVAILABLE, | 233 | StatusCode::SERVICE_UNAVAILABLE, |
| 233 | HeaderMap::new(), | 234 | HeaderMap::new(), |
| 234 | - b"the Files service is unreachable\n".to_vec(), | 235 | + format!("{}\n", Refusal::StorageUnavailable.message_in(lang)).into_bytes(), |
| 235 | ) | 236 | ) |
| 236 | } | 237 | } |
| 237 | 238 | ||
| @@ -539,13 +540,13 @@ async fn download(cx: &Cx) -> topcoat::Result<(StatusCode, HeaderMap, Vec<u8>)> | |||
| 539 | }, | 540 | }, |
| 540 | AttachmentWhere::Stored => { | 541 | AttachmentWhere::Stored => { |
| 541 | let Some((_, url)) = crate::storage::in_of(store.as_ref()).await else { | 542 | let Some((_, url)) = crate::storage::in_of(store.as_ref()).await else { |
| 542 | - return Ok(service_unavailable()); | 543 | + return Ok(service_unavailable(crate::i18n::Lang::from_code(&user.language))); |
| 543 | }; | 544 | }; |
| 544 | match crate::storage::client(cx).fetch(&url, id).await { | 545 | match crate::storage::client(cx).fetch(&url, id).await { |
| 545 | Ok(bytes) => bytes, | 546 | Ok(bytes) => bytes, |
| 546 | Err(problem) => { | 547 | Err(problem) => { |
| 547 | eprintln!("storage fetch: {problem:?}"); | 548 | eprintln!("storage fetch: {problem:?}"); |
| 548 | - return Ok(service_unavailable()); | 549 | + return Ok(service_unavailable(crate::i18n::Lang::from_code(&user.language))); |
| 549 | } | 550 | } |
| 550 | } | 551 | } |
| 551 | } | 552 | } |
crates/iz-web/src/i18n.rsmodified+37 -0
| @@ -99,6 +99,7 @@ pub enum Key { | |||
| 99 | BlockedBy, | 99 | BlockedBy, |
| 100 | Overdue, | 100 | Overdue, |
| 101 | Blocked, | 101 | Blocked, |
| 102 | + NoLongerWaiting, | ||
| 102 | 103 | ||
| 103 | // Topbar nav / chrome shared by board.rs, rules.rs, logs.rs, settings.rs. | 104 | // Topbar nav / chrome shared by board.rs, rules.rs, logs.rs, settings.rs. |
| 104 | NavBoard, | 105 | NavBoard, |
| @@ -208,6 +209,9 @@ pub enum Key { | |||
| 208 | PublicAddressLabel, | 209 | PublicAddressLabel, |
| 209 | PublicAddressNote, | 210 | PublicAddressNote, |
| 210 | SenderNotConfiguredYet, | 211 | SenderNotConfiguredYet, |
| 212 | + ProblemUnreachable, | ||
| 213 | + ProblemQuota, | ||
| 214 | + Ago, | ||
| 211 | 215 | ||
| 212 | // pages.rs | 216 | // pages.rs |
| 213 | 217 | ||
| @@ -522,6 +526,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 522 | (Overdue, Tr) => "gecikmiş", | 526 | (Overdue, Tr) => "gecikmiş", |
| 523 | (Blocked, En) => "blocked", | 527 | (Blocked, En) => "blocked", |
| 524 | (Blocked, Tr) => "engelli", | 528 | (Blocked, Tr) => "engelli", |
| 529 | + (NoLongerWaiting, En) => "no longer waiting", | ||
| 530 | + (NoLongerWaiting, Tr) => "artık beklemiyor", | ||
| 525 | 531 | ||
| 526 | (NavBoard, En) => "Board", | 532 | (NavBoard, En) => "Board", |
| 527 | (NavBoard, Tr) => "Pano", | 533 | (NavBoard, Tr) => "Pano", |
| @@ -738,6 +744,12 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 738 | } | 744 | } |
| 739 | (SenderNotConfiguredYet, En) => "No sender to test.", | 745 | (SenderNotConfiguredYet, En) => "No sender to test.", |
| 740 | (SenderNotConfiguredYet, Tr) => "Test edilecek gönderen yok.", | 746 | (SenderNotConfiguredYet, Tr) => "Test edilecek gönderen yok.", |
| 747 | + (Ago, En) => "ago", | ||
| 748 | + (Ago, Tr) => "önce", | ||
| 749 | + (ProblemUnreachable, En) => "unreachable", | ||
| 750 | + (ProblemUnreachable, Tr) => "erişilemiyor", | ||
| 751 | + (ProblemQuota, En) => "quota", | ||
| 752 | + (ProblemQuota, Tr) => "kota", | ||
| 741 | 753 | ||
| 742 | (MailRules, En) => "Mail rules", | 754 | (MailRules, En) => "Mail rules", |
| 743 | (MailRules, Tr) => "Posta kuralları", | 755 | (MailRules, Tr) => "Posta kuralları", |
| @@ -1217,6 +1229,31 @@ pub fn unblocked_label(lang: Lang, detail: &str) -> String { | |||
| 1217 | } | 1229 | } |
| 1218 | } | 1230 | } |
| 1219 | 1231 | ||
| 1232 | +/// A dependency's note once it no longer holds: the day it went away. | ||
| 1233 | +pub fn cleared_dep_label(lang: Lang, day: &str) -> String { | ||
| 1234 | + match lang { | ||
| 1235 | + Lang::En => format!("cleared {day}"), | ||
| 1236 | + Lang::Tr => format!("{day} kalktı"), | ||
| 1237 | + } | ||
| 1238 | +} | ||
| 1239 | + | ||
| 1240 | +/// A dependency's note when the task in front of this one finished. | ||
| 1241 | +pub fn done_dep_label(lang: Lang, day: &str) -> String { | ||
| 1242 | + match lang { | ||
| 1243 | + Lang::En => format!("done {day}"), | ||
| 1244 | + Lang::Tr => format!("{day} tamamlandı"), | ||
| 1245 | + } | ||
| 1246 | +} | ||
| 1247 | + | ||
| 1248 | +/// A used amount against its total — a storage limit, a migration's | ||
| 1249 | +/// progress. Turkish writes the pair with a slash, not a word. | ||
| 1250 | +pub fn share_of_total(lang: Lang, used: &str, total: &str) -> String { | ||
| 1251 | + match lang { | ||
| 1252 | + Lang::En => format!("{used} of {total}"), | ||
| 1253 | + Lang::Tr => format!("{used} / {total}"), | ||
| 1254 | + } | ||
| 1255 | +} | ||
| 1256 | + | ||
| 1220 | pub fn role_changed_label(lang: Lang, detail: &str) -> String { | 1257 | pub fn role_changed_label(lang: Lang, detail: &str) -> String { |
| 1221 | match lang { | 1258 | match lang { |
| 1222 | Lang::En => format!("made {detail}"), | 1259 | Lang::En => format!("made {detail}"), |
crates/iz-web/src/settings.rsmodified+21 -13
| @@ -971,12 +971,12 @@ async fn connection_card<'a>(cx: &'a Cx, lang: Lang) -> Result<impl View + 'a> { | |||
| 971 | let event_line = if event_age.is_empty() { | 971 | let event_line = if event_age.is_empty() { |
| 972 | never.clone() | 972 | never.clone() |
| 973 | } else { | 973 | } else { |
| 974 | - format!("{event_age} ago") | 974 | + format!("{} {}", event_age, t(lang, Key::Ago)) |
| 975 | }; | 975 | }; |
| 976 | let pass_line = if pass_age.is_empty() { | 976 | let pass_line = if pass_age.is_empty() { |
| 977 | never | 977 | never |
| 978 | } else { | 978 | } else { |
| 979 | - format!("{pass_age} ago") | 979 | + format!("{} {}", pass_age, t(lang, Key::Ago)) |
| 980 | }; | 980 | }; |
| 981 | Ok(view! { | 981 | Ok(view! { |
| 982 | cx => | 982 | cx => |
| @@ -1031,20 +1031,28 @@ async fn storage_card<'a>( | |||
| 1031 | (t(lang, Key::StorageUnreachable), "connection-wait") | 1031 | (t(lang, Key::StorageUnreachable), "connection-wait") |
| 1032 | }; | 1032 | }; |
| 1033 | let limit_line = match (snap.used, snap.quota) { | 1033 | let limit_line = match (snap.used, snap.quota) { |
| 1034 | - (Some(used), Some(quota)) => format!( | 1034 | + (Some(used), Some(quota)) => crate::i18n::share_of_total( |
| 1035 | - "{} of {}", | 1035 | + lang, |
| 1036 | - crate::storage::human_bytes(used), | 1036 | + &crate::storage::human_bytes(used), |
| 1037 | - crate::storage::human_bytes(quota) | 1037 | + &crate::storage::human_bytes(quota), |
| 1038 | ), | 1038 | ), |
| 1039 | _ => "—".to_string(), | 1039 | _ => "—".to_string(), |
| 1040 | }; | 1040 | }; |
| 1041 | - let problem_line = match &snap.problem_word { | 1041 | + let problem_word = match snap.problem_word.as_deref() { |
| 1042 | - Some(word) => format!( | 1042 | + Some("unreachable") => t(lang, Key::ProblemUnreachable).to_string(), |
| 1043 | - "{} ago · {}", | 1043 | + Some("quota") => t(lang, Key::ProblemQuota).to_string(), |
| 1044 | + Some(other) => other.to_string(), | ||
| 1045 | + None => String::new(), | ||
| 1046 | + }; | ||
| 1047 | + let problem_line = if problem_word.is_empty() { | ||
| 1048 | + t(lang, Key::ConnectionNever).to_string() | ||
| 1049 | + } else { | ||
| 1050 | + format!( | ||
| 1051 | + "{} {} · {}", | ||
| 1044 | crate::directory::age_text(snap.problem_age), | 1052 | crate::directory::age_text(snap.problem_age), |
| 1045 | - word | 1053 | + t(lang, Key::Ago), |
| 1046 | - ), | 1054 | + problem_word |
| 1047 | - None => t(lang, Key::ConnectionNever).to_string(), | 1055 | + ) |
| 1048 | }; | 1056 | }; |
| 1049 | let migrating = snap.migrating; | 1057 | let migrating = snap.migrating; |
| 1050 | Ok(view! { | 1058 | Ok(view! { |
| @@ -1062,7 +1070,7 @@ async fn storage_card<'a>( | |||
| 1062 | if backend == StorageBackend::In && let Some((moved, total)) = migrating { | 1070 | if backend == StorageBackend::In && let Some((moved, total)) = migrating { |
| 1063 | <dt>(t(lang, Key::StorageMigration))</dt> | 1071 | <dt>(t(lang, Key::StorageMigration))</dt> |
| 1064 | <dd class="connection-fact"> | 1072 | <dd class="connection-fact"> |
| 1065 | - (format!("{moved} of {total}")) | 1073 | + (crate::i18n::share_of_total(lang, &moved.to_string(), &total.to_string())) |
| 1066 | <div class="quota-bar" role="progressbar" aria-valuenow=(migration_percent(moved, total).to_string()) aria-valuemin="0" aria-valuemax="100"> | 1074 | <div class="quota-bar" role="progressbar" aria-valuenow=(migration_percent(moved, total).to_string()) aria-valuemin="0" aria-valuemax="100"> |
| 1067 | <div class="quota-fill" style=(format!("width: {}%", migration_percent(moved, total)))></div> | 1075 | <div class="quota-fill" style=(format!("width: {}%", migration_percent(moved, total)))></div> |
| 1068 | </div> | 1076 | </div> |