diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py
index d76558d3e..1ab4b6347 100644
--- a/qt/aqt/browser.py
+++ b/qt/aqt/browser.py
@@ -1574,9 +1574,7 @@ where id in %s"""
self.model.focusedCard = self.model.cards[newRow]
self.model.endReset()
self.mw.reset()
- tooltip(
- ngettext("%d note deleted.", "%d notes deleted.", len(nids)) % len(nids)
- )
+ tooltip(tr(TR.BROWSING_NOTE_DELETED, count=len(nids)))
# Deck change
######################################################################
@@ -2001,8 +1999,8 @@ where id in %s"""
t = ""
groups = len(res)
notes = sum(len(r[1]) for r in res)
- part1 = ngettext("%d group", "%d groups", groups) % groups
- part2 = ngettext("%d note", "%d notes", notes) % notes
+ part1 = tr(TR.BROWSING_GROUP, count=groups)
+ part2 = tr(TR.BROWSING_NOTE_COUNT, count=notes)
t += tr(TR.BROWSING_FOUND_AS_ACROSS_BS) % dict(a=part1, b=part2)
t += "
"
for val, nids in res:
@@ -2010,7 +2008,7 @@ where id in %s"""
"""- %s: %s"""
% (
"nid:" + ",".join(str(id) for id in nids),
- ngettext("%d note", "%d notes", len(nids)) % len(nids),
+ tr(TR.BROWSING_NOTE_COUNT, count=len(nids)),
html.escape(val),
)
)
diff --git a/qt/aqt/clayout.py b/qt/aqt/clayout.py
index be2648c90..af19e1a41 100644
--- a/qt/aqt/clayout.py
+++ b/qt/aqt/clayout.py
@@ -561,7 +561,7 @@ class CardLayout(QDialog):
card_cnt = fut.result()
template = self.current_template()
- cards = ngettext("%d card", "%d cards", card_cnt) % card_cnt
+ cards = tr(TR.CARD_TEMPLATES_CARD_COUNT, count=card_cnt)
msg = tr(TR.CARD_TEMPLATES_DELETE_THE_AS_CARD_TYPE_AND) % dict(
a=template["name"], b=cards
)
diff --git a/qt/aqt/deckbrowser.py b/qt/aqt/deckbrowser.py
index dbc01c5da..eaf899ff6 100644
--- a/qt/aqt/deckbrowser.py
+++ b/qt/aqt/deckbrowser.py
@@ -285,7 +285,7 @@ class DeckBrowser:
"odid in {0}".format(ids2str(dids))
)
if cnt:
- extra = ngettext(" It has %d card.", " It has %d cards.", cnt) % cnt
+ extra = tr(TR.DECKS_IT_HAS_CARD, count=cnt)
else:
extra = None
if (
diff --git a/qt/aqt/fields.py b/qt/aqt/fields.py
index 22e09a64f..173a7edb4 100644
--- a/qt/aqt/fields.py
+++ b/qt/aqt/fields.py
@@ -122,7 +122,7 @@ class FieldDialog(QDialog):
if len(self.model["flds"]) < 2:
return showWarning(tr(TR.FIELDS_NOTES_REQUIRE_AT_LEAST_ONE_FIELD))
count = self.mm.useCount(self.model)
- c = ngettext("%d note", "%d notes", count) % count
+ c = tr(TR.BROWSING_NOTE_COUNT, count=count)
if not askUser(tr(TR.FIELDS_DELETE_FIELD_FROM, val=c)):
return
if not self.change_tracker.mark_schema():
diff --git a/qt/aqt/main.py b/qt/aqt/main.py
index 0f06783b0..a15a8b617 100644
--- a/qt/aqt/main.py
+++ b/qt/aqt/main.py
@@ -1217,7 +1217,7 @@ title="%s" %s>%s""" % (
if devMode:
print("clock is off; ignoring")
return
- diffText = ngettext("%s second", "%s seconds", diff) % diff
+ diffText = tr(TR.QT_MISC_SECOND, count=diff)
warn = (
_(
"""\
diff --git a/qt/aqt/models.py b/qt/aqt/models.py
index eaf8347dd..12d7f05f4 100644
--- a/qt/aqt/models.py
+++ b/qt/aqt/models.py
@@ -110,7 +110,7 @@ class Models(QDialog):
self.models = notetypes
for m in self.models:
- mUse = ngettext("%d note", "%d notes", m.use_count) % m.use_count
+ mUse = tr(TR.BROWSING_NOTE_COUNT, count=m.use_count)
item = QListWidgetItem("%s [%s]" % (m.name, mUse))
self.form.modelsList.addItem(item)
self.form.modelsList.setCurrentRow(row)
diff --git a/qt/aqt/reviewer.py b/qt/aqt/reviewer.py
index c5115ad0c..85f187093 100644
--- a/qt/aqt/reviewer.py
+++ b/qt/aqt/reviewer.py
@@ -92,12 +92,9 @@ class Reviewer:
elapsed = self.mw.col.timeboxReached()
if elapsed:
assert not isinstance(elapsed, bool)
- part1 = (
- ngettext("%d card studied in", "%d cards studied in", elapsed[1])
- % elapsed[1]
- )
+ part1 = tr(TR.STUDYING_CARD_STUDIED_IN, count=elapsed[1])
mins = int(round(elapsed[0] / 60))
- part2 = ngettext("%s minute.", "%s minutes.", mins) % mins
+ part2 = tr(TR.STUDYING_MINUTE, count=mins)
fin = tr(TR.STUDYING_FINISH)
diag = askUserDialog(
"%s %s" % (part1, part2), [tr(TR.STUDYING_CONTINUE), fin]
diff --git a/qt/po/scripts/rewrite-refs.py b/qt/po/scripts/rewrite-refs.py
index 9d9803c7d..96be38501 100644
--- a/qt/po/scripts/rewrite-refs.py
+++ b/qt/po/scripts/rewrite-refs.py
@@ -3,11 +3,11 @@
import glob, re, json, stringcase
files = (
- glob.glob("../../pylib/**/*.py", recursive=True)
- # + glob.glob("../../qt/**/*.py", recursive=True)
+ # glob.glob("../../pylib/**/*.py", recursive=True)
+ glob.glob("../../qt/**/*.py", recursive=True)
# glob.glob("../../qt/**/forms/*.ui", recursive=True)
)
-string_re = re.compile(r'ngettext\(\s*"(.+?)",\s+".+?",\s+(.+?)\) % \2')
+string_re = re.compile(r'ngettext\(\s*"(.+?)",\s+".+?",\s+(.+?)\) % \2', re.DOTALL)
map = json.load(open("keys_by_text.json"))
@@ -20,6 +20,8 @@ blacklist = {
"~",
"about:blank",
"%d card imported.",
+ # need to update manually
+ "Browse (%(cur)d card shown; %(sel)s)",
# previewer.py needs updating to fix these
"Shortcut key: R",
"Shortcut key: B",
@@ -72,7 +74,7 @@ def repl(m):
screaming = stringcase.constcase(key)
- ret = f"tr_legacyglobal(TR.{screaming}, count={m.group(2)})"
+ ret = f"tr(TR.{screaming}, count={m.group(2)})"
print(ret)
return ret
@@ -84,7 +86,6 @@ for file in files:
buf2 = string_re.sub(repl, buf)
if buf != buf2:
lines = buf2.split("\n")
- lines.insert(3, "from anki.rsbackend import TR")
- lines.insert(3, "from anki.lang import tr_legacyglobal")
+ lines.insert(3, "from aqt.utils import tr, TR")
buf2 = "\n".join(lines)
open(file, "w").write(buf2)