mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
pass progress back as translated string(s)
This commit is contained in:
parent
d1e587fca9
commit
f6a881f950
7 changed files with 38 additions and 30 deletions
|
@ -17,6 +17,7 @@ enum StringsGroup {
|
||||||
TEST = 1;
|
TEST = 1;
|
||||||
MEDIA_CHECK = 2;
|
MEDIA_CHECK = 2;
|
||||||
CARD_TEMPLATES = 3;
|
CARD_TEMPLATES = 3;
|
||||||
|
SYNC = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1-15 reserved for future use; 2047 for errors
|
// 1-15 reserved for future use; 2047 for errors
|
||||||
|
@ -78,7 +79,7 @@ message BackendError {
|
||||||
message Progress {
|
message Progress {
|
||||||
oneof value {
|
oneof value {
|
||||||
MediaSyncProgress media_sync = 1;
|
MediaSyncProgress media_sync = 1;
|
||||||
uint32 media_check = 2;
|
string media_check = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,11 +118,9 @@ message SyncError {
|
||||||
}
|
}
|
||||||
|
|
||||||
message MediaSyncProgress {
|
message MediaSyncProgress {
|
||||||
uint32 checked = 1;
|
string checked = 1;
|
||||||
uint32 downloaded_files = 2;
|
string added = 2;
|
||||||
uint32 downloaded_deletions = 3;
|
string removed = 3;
|
||||||
uint32 uploaded_files = 4;
|
|
||||||
uint32 uploaded_deletions = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message MediaSyncUploadProgress {
|
message MediaSyncUploadProgress {
|
||||||
|
|
|
@ -147,7 +147,7 @@ class ProgressKind(enum.Enum):
|
||||||
@dataclass
|
@dataclass
|
||||||
class Progress:
|
class Progress:
|
||||||
kind: ProgressKind
|
kind: ProgressKind
|
||||||
val: Union[MediaSyncProgress, int]
|
val: Union[MediaSyncProgress, str]
|
||||||
|
|
||||||
|
|
||||||
def proto_replacement_list_to_native(
|
def proto_replacement_list_to_native(
|
||||||
|
|
|
@ -51,9 +51,7 @@ class MediaChecker:
|
||||||
if self.progress_dialog.wantCancel:
|
if self.progress_dialog.wantCancel:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.mw.taskman.run_on_main(
|
self.mw.taskman.run_on_main(lambda: self.mw.progress.update(progress.val))
|
||||||
lambda: self.mw.progress.update(_("Checked {}...").format(progress.val))
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _check(self) -> MediaCheckOutput:
|
def _check(self) -> MediaCheckOutput:
|
||||||
|
|
|
@ -243,15 +243,7 @@ class MediaSyncDialog(QDialog):
|
||||||
return self._time_and_text(entry.time, txt)
|
return self._time_and_text(entry.time, txt)
|
||||||
|
|
||||||
def _logentry_to_text(self, e: MediaSyncProgress) -> str:
|
def _logentry_to_text(self, e: MediaSyncProgress) -> str:
|
||||||
return _(
|
return f"{e.added}, {e.removed}, {e.checked}"
|
||||||
"Added: %(a_up)s↑ %(a_dwn)s↓, Removed: %(r_up)s↑ %(r_dwn)s↓, Checked: %(chk)s"
|
|
||||||
) % dict(
|
|
||||||
a_up=e.uploaded_files,
|
|
||||||
a_dwn=e.downloaded_files,
|
|
||||||
r_up=e.uploaded_deletions,
|
|
||||||
r_dwn=e.downloaded_deletions,
|
|
||||||
chk=e.checked,
|
|
||||||
)
|
|
||||||
|
|
||||||
def _on_log_entry(self, entry: LogEntryWithTime):
|
def _on_log_entry(self, entry: LogEntryWithTime):
|
||||||
self.form.plainTextEdit.appendPlainText(self._entry_to_text(entry))
|
self.form.plainTextEdit.appendPlainText(self._entry_to_text(entry))
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::backend_proto as pb;
|
||||||
use crate::backend_proto::backend_input::Value;
|
use crate::backend_proto::backend_input::Value;
|
||||||
use crate::backend_proto::{Empty, RenderedTemplateReplacement, SyncMediaIn};
|
use crate::backend_proto::{Empty, RenderedTemplateReplacement, SyncMediaIn};
|
||||||
use crate::err::{AnkiError, NetworkErrorKind, Result, SyncErrorKind};
|
use crate::err::{AnkiError, NetworkErrorKind, Result, SyncErrorKind};
|
||||||
use crate::i18n::I18n;
|
use crate::i18n::{tr_args, I18n, StringsGroup};
|
||||||
use crate::latex::{extract_latex, ExtractedLatex};
|
use crate::latex::{extract_latex, ExtractedLatex};
|
||||||
use crate::media::check::MediaChecker;
|
use crate::media::check::MediaChecker;
|
||||||
use crate::media::sync::MediaSyncProgress;
|
use crate::media::sync::MediaSyncProgress;
|
||||||
|
@ -198,7 +198,7 @@ impl Backend {
|
||||||
|
|
||||||
fn fire_progress_callback(&self, progress: Progress) -> bool {
|
fn fire_progress_callback(&self, progress: Progress) -> bool {
|
||||||
if let Some(cb) = &self.progress_callback {
|
if let Some(cb) = &self.progress_callback {
|
||||||
let bytes = progress_to_proto_bytes(progress);
|
let bytes = progress_to_proto_bytes(progress, &self.i18n);
|
||||||
cb(bytes)
|
cb(bytes)
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
|
@ -406,17 +406,16 @@ fn rendered_node_to_proto(node: RenderedNode) -> pb::rendered_template_node::Val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn progress_to_proto_bytes(progress: Progress) -> Vec<u8> {
|
fn progress_to_proto_bytes(progress: Progress, i18n: &I18n) -> Vec<u8> {
|
||||||
let proto = pb::Progress {
|
let proto = pb::Progress {
|
||||||
value: Some(match progress {
|
value: Some(match progress {
|
||||||
Progress::MediaSync(p) => pb::progress::Value::MediaSync(pb::MediaSyncProgress {
|
Progress::MediaSync(p) => pb::progress::Value::MediaSync(media_sync_progress(p, i18n)),
|
||||||
checked: p.checked as u32,
|
Progress::MediaCheck(n) => {
|
||||||
downloaded_files: p.downloaded_files as u32,
|
let s = i18n
|
||||||
downloaded_deletions: p.downloaded_deletions as u32,
|
.get(StringsGroup::MediaCheck)
|
||||||
uploaded_files: p.uploaded_files as u32,
|
.trn("checked", tr_args!["count"=>n]);
|
||||||
uploaded_deletions: p.uploaded_deletions as u32,
|
pb::progress::Value::MediaCheck(s)
|
||||||
}),
|
}
|
||||||
Progress::MediaCheck(n) => pb::progress::Value::MediaCheck(n),
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -424,3 +423,18 @@ fn progress_to_proto_bytes(progress: Progress) -> Vec<u8> {
|
||||||
proto.encode(&mut buf).expect("encode failed");
|
proto.encode(&mut buf).expect("encode failed");
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn media_sync_progress(p: &MediaSyncProgress, i18n: &I18n) -> pb::MediaSyncProgress {
|
||||||
|
let cat = i18n.get(StringsGroup::Sync);
|
||||||
|
pb::MediaSyncProgress {
|
||||||
|
checked: cat.trn("media-checked-count", tr_args!["count"=>p.checked]),
|
||||||
|
added: cat.trn(
|
||||||
|
"media-added-count",
|
||||||
|
tr_args!["up"=>p.uploaded_files,"down"=>p.downloaded_files],
|
||||||
|
),
|
||||||
|
removed: cat.trn(
|
||||||
|
"media-removed-count",
|
||||||
|
tr_args!["up"=>p.uploaded_deletions,"down"=>p.downloaded_deletions],
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -17,3 +17,5 @@ oversize-file = Over 100MB: {$filename}
|
||||||
subfolder-file = Folder: {$filename}
|
subfolder-file = Folder: {$filename}
|
||||||
missing-file = Missing: {$filename}
|
missing-file = Missing: {$filename}
|
||||||
unused-file = Unused: {$filename}
|
unused-file = Unused: {$filename}
|
||||||
|
|
||||||
|
checked = Checked {$count}...
|
||||||
|
|
|
@ -11,6 +11,7 @@ use unic_langid::LanguageIdentifier;
|
||||||
pub use fluent::fluent_args as tr_args;
|
pub use fluent::fluent_args as tr_args;
|
||||||
|
|
||||||
pub use crate::backend_proto::StringsGroup;
|
pub use crate::backend_proto::StringsGroup;
|
||||||
|
|
||||||
/// Helper for creating args with &strs
|
/// Helper for creating args with &strs
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! tr_strs {
|
macro_rules! tr_strs {
|
||||||
|
@ -61,6 +62,7 @@ fn ftl_fallback_for_group(group: StringsGroup) -> String {
|
||||||
StringsGroup::Test => include_str!("../../tests/support/test.ftl"),
|
StringsGroup::Test => include_str!("../../tests/support/test.ftl"),
|
||||||
StringsGroup::MediaCheck => include_str!("media-check.ftl"),
|
StringsGroup::MediaCheck => include_str!("media-check.ftl"),
|
||||||
StringsGroup::CardTemplates => include_str!("card-template-rendering.ftl"),
|
StringsGroup::CardTemplates => include_str!("card-template-rendering.ftl"),
|
||||||
|
StringsGroup::Sync => include_str!("sync.ftl"),
|
||||||
}
|
}
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
@ -77,6 +79,7 @@ fn localized_ftl_for_group(
|
||||||
StringsGroup::Test => "test.ftl",
|
StringsGroup::Test => "test.ftl",
|
||||||
StringsGroup::MediaCheck => "media-check.ftl",
|
StringsGroup::MediaCheck => "media-check.ftl",
|
||||||
StringsGroup::CardTemplates => "card-template-rendering.ftl",
|
StringsGroup::CardTemplates => "card-template-rendering.ftl",
|
||||||
|
StringsGroup::Sync => "sync.ftl",
|
||||||
});
|
});
|
||||||
fs::read_to_string(&path)
|
fs::read_to_string(&path)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
|
|
Loading…
Reference in a new issue