diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 2a865f93e..cfa2c3cdb 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -73,7 +73,6 @@ class _Collection: ls: int conf: Dict[str, Any] _undo: List[Any] - backend: RustBackend def __init__( self, @@ -83,6 +82,7 @@ class _Collection: log: bool = False, ) -> None: self.backend = backend + self.tr = backend.translate self._debugLog = log self.db = db self.path = db._path diff --git a/pylib/anki/rsbackend.py b/pylib/anki/rsbackend.py index cdd9d9603..def276f30 100644 --- a/pylib/anki/rsbackend.py +++ b/pylib/anki/rsbackend.py @@ -324,7 +324,7 @@ class RustBackend: 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( pb.BackendInput(translate_string=translate_string_in(key, **kwargs)) ).translate_string diff --git a/pylib/anki/stats.py b/pylib/anki/stats.py index d336b6b61..2f24babe6 100644 --- a/pylib/anki/stats.py +++ b/pylib/anki/stats.py @@ -47,9 +47,7 @@ class CardStats: next = c.due next = self.date(next) if next: - self.addLine( - self.col.backend.translate(TR.STATISTICS_DUE_DATE), next, - ) + self.addLine(self.col.tr(TR.STATISTICS_DUE_DATE), next) if c.queue == QUEUE_TYPE_REV: self.addLine( _("Interval"), self.col.backend.format_time_span(c.ivl * 86400) @@ -278,9 +276,7 @@ from revlog where id > ? """ def _dueInfo(self, tot, num) -> str: i: List[str] = [] self._line( - i, - _("Total"), - self.col.backend.translate(TR.STATISTICS_REVIEWS, reviews=tot), + i, _("Total"), self.col.tr(TR.STATISTICS_REVIEWS, reviews=tot), ) self._line(i, _("Average"), self._avgDay(tot, num, _("reviews"))) tomorrow = self.col.db.scalar( @@ -457,7 +453,7 @@ group by day order by day""" self._line( i, _("Average answer time"), - self.col.backend.translate( + self.col.tr( TR.STATISTICS_AVERAGE_ANSWER_TIME, **{"cards-per-minute": perMin, "average-seconds": average_secs}, ), diff --git a/pylib/tests/test_collection.py b/pylib/tests/test_collection.py index 734ca5fa9..8c0985426 100644 --- a/pylib/tests/test_collection.py +++ b/pylib/tests/test_collection.py @@ -153,12 +153,11 @@ def test_furigana(): def test_translate(): d = getEmptyCol() - tr = d.backend.translate no_uni = without_unicode_isolation assert ( - tr(TR.CARD_TEMPLATE_RENDERING_FRONT_SIDE_PROBLEM) + d.tr(TR.CARD_TEMPLATE_RENDERING_FRONT_SIDE_PROBLEM) == "Front template has a problem:" ) - assert no_uni(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=1)) == "1 review" + assert no_uni(d.tr(TR.STATISTICS_REVIEWS, reviews=2)) == "2 reviews"