Skip to content

Commit 66a5e07

Browse files
authored
make connectivity and quota views translatable (#2694)
* add missing stock strings for connectivity and quota * reword quota error * use 'Incoming/Outgoing Messages' instead of 'Inbox/Outbox' * just say 'Not supported by your provider.' if quota cannot be read. - the context is already given by the headline 'Storage on domain.org' - the string is short and does not disturb much (it is a very common error) - the string does not mention 'quota' as such, which will be hard to translate ('Kontingentsinformationen') - even if ppl as we know about the Quota extensions an such things. there was also the idea to hide the whole section, however, that is confusing in a multi-device-usage when things are sometimes shown and sometimes not.
1 parent 43d1d9b commit 66a5e07

File tree

4 files changed

+196
-22
lines changed

4 files changed

+196
-22
lines changed

deltachat-ffi/deltachat.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5900,6 +5900,70 @@ void dc_event_unref(dc_event_t* event);
59005900
/// `%1$s` will be replaced by human-readable date and time.
59015901
#define DC_STR_DOWNLOAD_AVAILABILITY 100
59025902

5903+
/// "Incoming Messages"
5904+
///
5905+
/// Used as a headline in the connectivity view.
5906+
#define DC_STR_INCOMING_MESSAGES 103
5907+
5908+
/// "Outgoing Messages"
5909+
///
5910+
/// Used as a headline in the connectivity view.
5911+
#define DC_STR_OUTGOING_MESSAGES 104
5912+
5913+
/// "Storage on %1$s"
5914+
///
5915+
/// Used as a headline in the connectivity view.
5916+
///
5917+
/// `%1$s` will be replaced by the domain of the configured email-address.
5918+
#define DC_STR_STORAGE_ON_DOMAIN 105
5919+
5920+
/// "One moment…"
5921+
///
5922+
/// Used in the connectivity view when some information are not yet there.
5923+
#define DC_STR_ONE_MOMENT 106
5924+
5925+
/// "Connected"
5926+
///
5927+
/// Used as status in the connectivity view.
5928+
#define DC_STR_CONNECTED 107
5929+
5930+
/// "Connecting…"
5931+
///
5932+
/// Used as status in the connectivity view.
5933+
#define DC_STR_CONNTECTING 108
5934+
5935+
/// "Updating…"
5936+
///
5937+
/// Used as status in the connectivity view.
5938+
#define DC_STR_UPDATING 109
5939+
5940+
/// "Sending…"
5941+
///
5942+
/// Used as status in the connectivity view.
5943+
#define DC_STR_SENDING 110
5944+
5945+
/// "Your last message was sent successfully."
5946+
///
5947+
/// Used as status in the connectivity view.
5948+
#define DC_STR_LAST_MSG_SENT_SUCCESSFULLY 111
5949+
5950+
/// "Error: %1$s"
5951+
///
5952+
/// Used as status in the connectivity view.
5953+
///
5954+
/// `%1$s` will be replaced by a possibly more detailed, typically english, error description.
5955+
#define DC_STR_ERROR 112
5956+
5957+
/// "Not supported by your provider."
5958+
///
5959+
/// Used in the connectivity view.
5960+
#define DC_STR_NOT_SUPPORTED_BY_PROVIDER 113
5961+
5962+
/// "Messages"
5963+
///
5964+
/// Used as a subtitle in quota context; can be plural always.
5965+
#define DC_STR_MESSAGES 114
5966+
59035967
/**
59045968
* @}
59055969
*/

src/quota.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Context {
128128
let folders = get_watched_folders(self).await;
129129
get_unique_quota_roots_and_usage(folders, imap).await
130130
} else {
131-
Err(anyhow!("Quota not supported by your provider."))
131+
Err(anyhow!(stock_str::not_supported_by_provider(self).await))
132132
};
133133

134134
if let Ok(quota) = &quota {

src/scheduler/connectivity.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::events::EventType;
88
use crate::quota::{
99
QUOTA_ERROR_THRESHOLD_PERCENTAGE, QUOTA_MAX_AGE_SECONDS, QUOTA_WARN_THRESHOLD_PERCENTAGE,
1010
};
11-
use crate::{config::Config, dc_tools, scheduler::Scheduler};
11+
use crate::{config::Config, dc_tools, scheduler::Scheduler, stock_str};
1212
use crate::{context::Context, log::LogExt};
1313
use anyhow::{anyhow, Result};
1414
use humansize::{file_size_opts, FileSize};
@@ -73,33 +73,33 @@ impl DetailedConnectivity {
7373
}
7474
}
7575

76-
fn to_string_imap(&self, _context: &Context) -> String {
76+
async fn to_string_imap(&self, context: &Context) -> String {
7777
match self {
78-
DetailedConnectivity::Error(e) => format!("Error: {}", e),
78+
DetailedConnectivity::Error(e) => stock_str::error(context, e).await,
7979
DetailedConnectivity::Uninitialized => "Not started".to_string(),
80-
DetailedConnectivity::Connecting => "Connecting…".to_string(),
81-
DetailedConnectivity::Working => "Getting new messages…".to_string(),
80+
DetailedConnectivity::Connecting => stock_str::connecting(context).await,
81+
DetailedConnectivity::Working => stock_str::updating(context).await,
8282
DetailedConnectivity::InterruptingIdle | DetailedConnectivity::Connected => {
83-
"Connected".to_string()
83+
stock_str::connected(context).await
8484
}
8585
DetailedConnectivity::NotConfigured => "Not configured".to_string(),
8686
}
8787
}
8888

89-
fn to_string_smtp(&self, _context: &Context) -> String {
89+
async fn to_string_smtp(&self, context: &Context) -> String {
9090
match self {
91-
DetailedConnectivity::Error(e) => format!("Error: {}", e),
91+
DetailedConnectivity::Error(e) => stock_str::error(context, e).await,
9292
DetailedConnectivity::Uninitialized => {
93-
"(You did not try to send a message recently)".to_string()
93+
"You did not try to send a message recently.".to_string()
9494
}
95-
DetailedConnectivity::Connecting => "Connecting…".to_string(),
96-
DetailedConnectivity::Working => "Sending…".to_string(),
95+
DetailedConnectivity::Connecting => stock_str::connecting(context).await,
96+
DetailedConnectivity::Working => stock_str::sending(context).await,
9797

9898
// We don't know any more than that the last message was sent successfully;
9999
// since sending the last message, connectivity could have changed, which we don't notice
100100
// until another message is sent
101101
DetailedConnectivity::InterruptingIdle | DetailedConnectivity::Connected => {
102-
"Your last message was sent successfully".to_string()
102+
stock_str::last_msg_sent_successfully(context).await
103103
}
104104
DetailedConnectivity::NotConfigured => "Not configured".to_string(),
105105
}
@@ -251,7 +251,7 @@ impl Context {
251251
/// One of:
252252
/// - DC_CONNECTIVITY_NOT_CONNECTED (1000-1999): Show e.g. the string "Not connected" or a red dot
253253
/// - DC_CONNECTIVITY_CONNECTING (2000-2999): Show e.g. the string "Connecting…" or a yellow dot
254-
/// - DC_CONNECTIVITY_WORKING (3000-3999): Show e.g. the string "Getting new messages" or a spinning wheel
254+
/// - DC_CONNECTIVITY_WORKING (3000-3999): Show e.g. the string "Updating…" or a spinning wheel
255255
/// - DC_CONNECTIVITY_CONNECTED (>=4000): Show e.g. the string "Connected" or a green dot
256256
///
257257
/// We don't use exact values but ranges here so that we can split up
@@ -380,7 +380,7 @@ impl Context {
380380
};
381381
drop(lock);
382382

383-
ret += "<h3>Incoming messages</h3><ul>";
383+
ret += &format!("<h3>{}</h3><ul>", stock_str::incoming_messages(self).await);
384384
for (folder, watch, state) in &folders_states {
385385
let w = self.get_config(*watch).await.ok_or_log(self);
386386

@@ -395,7 +395,7 @@ impl Context {
395395
ret += " <b>";
396396
ret += &*escaper::encode_minimal(&foldername);
397397
ret += ":</b> ";
398-
ret += &*escaper::encode_minimal(&*detailed.to_string_imap(self));
398+
ret += &*escaper::encode_minimal(&*detailed.to_string_imap(self).await);
399399
ret += "</li>";
400400

401401
folder_added = true;
@@ -410,18 +410,21 @@ impl Context {
410410
ret += "<li>";
411411
ret += &*detailed.to_icon();
412412
ret += " ";
413-
ret += &*escaper::encode_minimal(&detailed.to_string_imap(self));
413+
ret += &*escaper::encode_minimal(&detailed.to_string_imap(self).await);
414414
ret += "</li>";
415415
}
416416
}
417417
}
418418
ret += "</ul>";
419419

420-
ret += "<h3>Outgoing messages</h3><ul><li>";
420+
ret += &format!(
421+
"<h3>{}</h3><ul><li>",
422+
stock_str::outgoing_messages(self).await
423+
);
421424
let detailed = smtp.get_detailed().await;
422425
ret += &*detailed.to_icon();
423426
ret += " ";
424-
ret += &*escaper::encode_minimal(&detailed.to_string_smtp(self));
427+
ret += &*escaper::encode_minimal(&detailed.to_string_smtp(self).await);
425428
ret += "</li></ul>";
426429

427430
let domain = dc_tools::EmailAddress::new(
@@ -431,7 +434,10 @@ impl Context {
431434
.unwrap_or_default(),
432435
)?
433436
.domain;
434-
ret += &format!("<h3>Storage on {}</h3><ul>", domain);
437+
ret += &format!(
438+
"<h3>{}</h3><ul>",
439+
stock_str::storage_on_domain(self, domain).await
440+
);
435441
let quota = self.quota.read().await;
436442
if let Some(quota) = &*quota {
437443
match &quota.recent {
@@ -462,7 +468,8 @@ impl Context {
462468
}
463469
Message => {
464470
format!(
465-
"<b>Messages:</b> {} of {} used",
471+
"<b>{}:</b> {} of {} used",
472+
stock_str::messages(self).await,
466473
resource.usage.to_string(),
467474
resource.limit.to_string(),
468475
)
@@ -507,7 +514,7 @@ impl Context {
507514
self.schedule_quota_update().await?;
508515
}
509516
} else {
510-
ret += "<li>One moment...</li>";
517+
ret += &format!("<li>{}</li>", stock_str::one_moment(self).await);
511518
self.schedule_quota_update().await?;
512519
}
513520
ret += "</ul>";

src/stock_str.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,42 @@ pub enum StockMessage {
275275

276276
#[strum(props(fallback = "Download maximum available until %1$s"))]
277277
DownloadAvailability = 100,
278+
279+
#[strum(props(fallback = "Incoming Messages"))]
280+
IncomingMessages = 103,
281+
282+
#[strum(props(fallback = "Outgoing Messages"))]
283+
OutgoingMessages = 104,
284+
285+
#[strum(props(fallback = "Storage on %1$s"))]
286+
StorageOnDomain = 105,
287+
288+
#[strum(props(fallback = "One moment…"))]
289+
OneMoment = 106,
290+
291+
#[strum(props(fallback = "Connected"))]
292+
Connected = 107,
293+
294+
#[strum(props(fallback = "Connecting…"))]
295+
Connecting = 108,
296+
297+
#[strum(props(fallback = "Updating…"))]
298+
Updating = 109,
299+
300+
#[strum(props(fallback = "Sending…"))]
301+
Sending = 110,
302+
303+
#[strum(props(fallback = "Your last message was sent successfully."))]
304+
LastMsgSentSuccessfully = 111,
305+
306+
#[strum(props(fallback = "Error: %1$s"))]
307+
Error = 112,
308+
309+
#[strum(props(fallback = "Not supported by your provider."))]
310+
NotSupportedByProvider = 113,
311+
312+
#[strum(props(fallback = "Messages"))]
313+
Messages = 114,
278314
}
279315

280316
impl StockMessage {
@@ -882,6 +918,73 @@ pub(crate) async fn download_availability(context: &Context, timestamp: i64) ->
882918
.replace1(dc_timestamp_to_str(timestamp))
883919
}
884920

921+
/// Stock string: `Incoming Messages`.
922+
pub(crate) async fn incoming_messages(context: &Context) -> String {
923+
translated(context, StockMessage::IncomingMessages).await
924+
}
925+
926+
/// Stock string: `Outgoing Messages`.
927+
pub(crate) async fn outgoing_messages(context: &Context) -> String {
928+
translated(context, StockMessage::OutgoingMessages).await
929+
}
930+
931+
/// Stock string: `Storage on %1$s`.
932+
/// `%1$s` will be replaced by the domain of the configured email-address.
933+
pub(crate) async fn storage_on_domain(context: &Context, domain: impl AsRef<str>) -> String {
934+
translated(context, StockMessage::StorageOnDomain)
935+
.await
936+
.replace1(domain)
937+
}
938+
939+
/// Stock string: `One moment…`.
940+
pub(crate) async fn one_moment(context: &Context) -> String {
941+
translated(context, StockMessage::OneMoment).await
942+
}
943+
944+
/// Stock string: `Connected`.
945+
pub(crate) async fn connected(context: &Context) -> String {
946+
translated(context, StockMessage::Connected).await
947+
}
948+
949+
/// Stock string: `Connecting…`.
950+
pub(crate) async fn connecting(context: &Context) -> String {
951+
translated(context, StockMessage::Connecting).await
952+
}
953+
954+
/// Stock string: `Updating…`.
955+
pub(crate) async fn updating(context: &Context) -> String {
956+
translated(context, StockMessage::Updating).await
957+
}
958+
959+
/// Stock string: `Sending…`.
960+
pub(crate) async fn sending(context: &Context) -> String {
961+
translated(context, StockMessage::Sending).await
962+
}
963+
964+
/// Stock string: `Your last message was sent successfully.`.
965+
pub(crate) async fn last_msg_sent_successfully(context: &Context) -> String {
966+
translated(context, StockMessage::LastMsgSentSuccessfully).await
967+
}
968+
969+
/// Stock string: `Error: %1$s…`.
970+
/// `%1$s` will be replaced by a possibly more detailed, typically english, error description.
971+
pub(crate) async fn error(context: &Context, error: impl AsRef<str>) -> String {
972+
translated(context, StockMessage::Error)
973+
.await
974+
.replace1(error)
975+
}
976+
977+
/// Stock string: `Not supported by your provider.`.
978+
pub(crate) async fn not_supported_by_provider(context: &Context) -> String {
979+
translated(context, StockMessage::NotSupportedByProvider).await
980+
}
981+
982+
/// Stock string: `Messages`.
983+
/// Used as a subtitle in quota context; can be plural always.
984+
pub(crate) async fn messages(context: &Context) -> String {
985+
translated(context, StockMessage::Messages).await
986+
}
987+
885988
impl Context {
886989
/// Set the stock string for the [StockMessage].
887990
///

0 commit comments

Comments
 (0)