From 1524e7dcacead2a552197c7ae8e8dd1ad14bfd36 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 17 Feb 2020 14:41:01 +1000 Subject: [PATCH] split "Due" into three different contexts for translators --- proto/backend.proto | 2 ++ pylib/anki/stats.py | 9 +++++++-- qt/aqt/browser.py | 6 ++++-- qt/aqt/deckbrowser.py | 13 +++++++++++-- rslib/src/i18n/filtering.ftl | 2 ++ rslib/src/i18n/mod.rs | 4 ++++ rslib/src/i18n/statistics.ftl | 4 ++++ 7 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 rslib/src/i18n/filtering.ftl create mode 100644 rslib/src/i18n/statistics.ftl diff --git a/proto/backend.proto b/proto/backend.proto index 77dc50a0d..f28d70a29 100644 --- a/proto/backend.proto +++ b/proto/backend.proto @@ -19,6 +19,8 @@ enum StringsGroup { CARD_TEMPLATES = 3; SYNC = 4; NETWORK = 5; + STATISTICS = 6; + FILTERING = 7; } // 1-15 reserved for future use; 2047 for errors diff --git a/pylib/anki/stats.py b/pylib/anki/stats.py index c67951db1..38eb62818 100644 --- a/pylib/anki/stats.py +++ b/pylib/anki/stats.py @@ -6,8 +6,10 @@ import json import time from typing import Any, Dict, List, Optional, Tuple +import anki from anki.consts import * from anki.lang import _, ngettext +from anki.rsbackend import StringsGroup from anki.utils import fmtTimeSpan, ids2str # Card stats @@ -19,7 +21,7 @@ PERIOD_LIFE = 2 class CardStats: - def __init__(self, col, card) -> None: + def __init__(self, col: anki.storage._Collection, card: anki.cards.Card) -> None: self.col = col self.card = card self.txt = "" @@ -45,7 +47,10 @@ class CardStats: next = c.due next = self.date(next) if next: - self.addLine(_("Due"), next) + self.addLine( + self.col.backend.translate(StringsGroup.STATISTICS, "due-date"), + next, + ) if c.queue == QUEUE_TYPE_REV: self.addLine(_("Interval"), fmt(c.ivl * 86400)) self.addLine(_("Ease"), "%d%%" % (c.factor / 10.0)) diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 0aec6b546..6d20c9e04 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -24,6 +24,7 @@ from anki.consts import * from anki.lang import _, ngettext from anki.models import NoteType from anki.notes import Note +from anki.rsbackend import StringsGroup from anki.utils import fmtTimeSpan, htmlToTextLine, ids2str, intTime, isMac, isWin from aqt import AnkiQt, gui_hooks from aqt.editor import Editor @@ -51,6 +52,7 @@ from aqt.utils import ( showInfo, showWarning, tooltip, + tr, ) from aqt.webview import AnkiWebView @@ -728,7 +730,7 @@ class Browser(QMainWindow): ("noteCrt", _("Created")), ("noteMod", _("Edited")), ("cardMod", _("Changed")), - ("cardDue", _("Due")), + ("cardDue", tr(StringsGroup.STATISTICS, "due-date")), ("cardIvl", _("Interval")), ("cardEase", _("Ease")), ("cardReps", _("Reviews")), @@ -1269,7 +1271,7 @@ by clicking on one on the left.""" (_("New"), "is:new"), (_("Learning"), "is:learn"), (_("Review"), "is:review"), - (_("Due"), "is:due"), + (tr(StringsGroup.FILTERING, "is-due"), "is:due"), None, (_("Suspended"), "is:suspended"), (_("Buried"), "is:buried"), diff --git a/qt/aqt/deckbrowser.py b/qt/aqt/deckbrowser.py index a57647d62..d28c8295c 100644 --- a/qt/aqt/deckbrowser.py +++ b/qt/aqt/deckbrowser.py @@ -10,12 +10,21 @@ from typing import Any import aqt from anki.errors import DeckRenameError from anki.lang import _, ngettext +from anki.rsbackend import StringsGroup from anki.utils import fmtTimeSpan, ids2str from aqt import AnkiQt, gui_hooks from aqt.qt import * from aqt.sound import av_player from aqt.toolbar import BottomBar -from aqt.utils import askUser, getOnlyText, openHelp, openLink, shortcut, showWarning +from aqt.utils import ( + askUser, + getOnlyText, + openHelp, + openLink, + shortcut, + showWarning, + tr, +) class DeckBrowserBottomBar: @@ -160,7 +169,7 @@ where id > ?""", %s%s %s""" % ( _("Deck"), - _("Due"), + tr(StringsGroup.STATISTICS, "due-count"), _("New"), ) buf += self._topLevelDragRow() diff --git a/rslib/src/i18n/filtering.ftl b/rslib/src/i18n/filtering.ftl new file mode 100644 index 000000000..19c2b0858 --- /dev/null +++ b/rslib/src/i18n/filtering.ftl @@ -0,0 +1,2 @@ +# True if a card is due/ready for review +is-due = Due diff --git a/rslib/src/i18n/mod.rs b/rslib/src/i18n/mod.rs index b1a72c312..5b35821d7 100644 --- a/rslib/src/i18n/mod.rs +++ b/rslib/src/i18n/mod.rs @@ -57,6 +57,8 @@ fn ftl_fallback_for_group(group: StringsGroup) -> String { StringsGroup::CardTemplates => include_str!("card-template-rendering.ftl"), StringsGroup::Sync => include_str!("sync.ftl"), StringsGroup::Network => include_str!("network.ftl"), + StringsGroup::Statistics => include_str!("statistics.ftl"), + StringsGroup::Filtering => include_str!("filtering.ftl"), } .to_string() } @@ -71,6 +73,8 @@ fn localized_ftl_for_group(group: StringsGroup, lang_ftl_folder: &Path) -> Optio StringsGroup::CardTemplates => "card-template-rendering.ftl", StringsGroup::Sync => "sync.ftl", StringsGroup::Network => "network.ftl", + StringsGroup::Statistics => "statistics.ftl", + StringsGroup::Filtering => "filtering.ftl", }); fs::read_to_string(&path) .map_err(|e| { diff --git a/rslib/src/i18n/statistics.ftl b/rslib/src/i18n/statistics.ftl new file mode 100644 index 000000000..503bbf61d --- /dev/null +++ b/rslib/src/i18n/statistics.ftl @@ -0,0 +1,4 @@ +# The date a card will be ready to review +due-date = Due +# The count of cards waiting to be reviewed +due-count = Due