mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
add self.col.tr() shortcut
This commit is contained in:
parent
0c49431719
commit
4d917cc65b
4 changed files with 8 additions and 13 deletions
|
@ -73,7 +73,6 @@ class _Collection:
|
||||||
ls: int
|
ls: int
|
||||||
conf: Dict[str, Any]
|
conf: Dict[str, Any]
|
||||||
_undo: List[Any]
|
_undo: List[Any]
|
||||||
backend: RustBackend
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -83,6 +82,7 @@ class _Collection:
|
||||||
log: bool = False,
|
log: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
|
self.tr = backend.translate
|
||||||
self._debugLog = log
|
self._debugLog = log
|
||||||
self.db = db
|
self.db = db
|
||||||
self.path = db._path
|
self.path = db._path
|
||||||
|
|
|
@ -324,7 +324,7 @@ class RustBackend:
|
||||||
pb.BackendInput(trash_media_files=pb.TrashMediaFilesIn(fnames=fnames))
|
pb.BackendInput(trash_media_files=pb.TrashMediaFilesIn(fnames=fnames))
|
||||||
)
|
)
|
||||||
|
|
||||||
def translate(self, key: TR, **kwargs: Union[str, int, float]):
|
def translate(self, key: TR, **kwargs: Union[str, int, float]) -> str:
|
||||||
return self._run_command(
|
return self._run_command(
|
||||||
pb.BackendInput(translate_string=translate_string_in(key, **kwargs))
|
pb.BackendInput(translate_string=translate_string_in(key, **kwargs))
|
||||||
).translate_string
|
).translate_string
|
||||||
|
|
|
@ -47,9 +47,7 @@ class CardStats:
|
||||||
next = c.due
|
next = c.due
|
||||||
next = self.date(next)
|
next = self.date(next)
|
||||||
if next:
|
if next:
|
||||||
self.addLine(
|
self.addLine(self.col.tr(TR.STATISTICS_DUE_DATE), next)
|
||||||
self.col.backend.translate(TR.STATISTICS_DUE_DATE), next,
|
|
||||||
)
|
|
||||||
if c.queue == QUEUE_TYPE_REV:
|
if c.queue == QUEUE_TYPE_REV:
|
||||||
self.addLine(
|
self.addLine(
|
||||||
_("Interval"), self.col.backend.format_time_span(c.ivl * 86400)
|
_("Interval"), self.col.backend.format_time_span(c.ivl * 86400)
|
||||||
|
@ -278,9 +276,7 @@ from revlog where id > ? """
|
||||||
def _dueInfo(self, tot, num) -> str:
|
def _dueInfo(self, tot, num) -> str:
|
||||||
i: List[str] = []
|
i: List[str] = []
|
||||||
self._line(
|
self._line(
|
||||||
i,
|
i, _("Total"), self.col.tr(TR.STATISTICS_REVIEWS, reviews=tot),
|
||||||
_("Total"),
|
|
||||||
self.col.backend.translate(TR.STATISTICS_REVIEWS, reviews=tot),
|
|
||||||
)
|
)
|
||||||
self._line(i, _("Average"), self._avgDay(tot, num, _("reviews")))
|
self._line(i, _("Average"), self._avgDay(tot, num, _("reviews")))
|
||||||
tomorrow = self.col.db.scalar(
|
tomorrow = self.col.db.scalar(
|
||||||
|
@ -457,7 +453,7 @@ group by day order by day"""
|
||||||
self._line(
|
self._line(
|
||||||
i,
|
i,
|
||||||
_("Average answer time"),
|
_("Average answer time"),
|
||||||
self.col.backend.translate(
|
self.col.tr(
|
||||||
TR.STATISTICS_AVERAGE_ANSWER_TIME,
|
TR.STATISTICS_AVERAGE_ANSWER_TIME,
|
||||||
**{"cards-per-minute": perMin, "average-seconds": average_secs},
|
**{"cards-per-minute": perMin, "average-seconds": average_secs},
|
||||||
),
|
),
|
||||||
|
|
|
@ -153,12 +153,11 @@ def test_furigana():
|
||||||
|
|
||||||
def test_translate():
|
def test_translate():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
tr = d.backend.translate
|
|
||||||
no_uni = without_unicode_isolation
|
no_uni = without_unicode_isolation
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
tr(TR.CARD_TEMPLATE_RENDERING_FRONT_SIDE_PROBLEM)
|
d.tr(TR.CARD_TEMPLATE_RENDERING_FRONT_SIDE_PROBLEM)
|
||||||
== "Front template has a problem:"
|
== "Front template has a problem:"
|
||||||
)
|
)
|
||||||
assert no_uni(tr(TR.STATISTICS_REVIEWS, reviews=1)) == "1 review"
|
assert no_uni(d.tr(TR.STATISTICS_REVIEWS, reviews=1)) == "1 review"
|
||||||
assert no_uni(tr(TR.STATISTICS_REVIEWS, reviews=2)) == "2 reviews"
|
assert no_uni(d.tr(TR.STATISTICS_REVIEWS, reviews=2)) == "2 reviews"
|
||||||
|
|
Loading…
Reference in a new issue