update some qt ngettext references

This commit is contained in:
Damien Elmes 2020-11-18 09:22:27 +10:00
parent 177d98489a
commit 1255e7530c
8 changed files with 18 additions and 22 deletions

View file

@ -1574,9 +1574,7 @@ where id in %s"""
self.model.focusedCard = self.model.cards[newRow] self.model.focusedCard = self.model.cards[newRow]
self.model.endReset() self.model.endReset()
self.mw.reset() self.mw.reset()
tooltip( tooltip(tr(TR.BROWSING_NOTE_DELETED, count=len(nids)))
ngettext("%d note deleted.", "%d notes deleted.", len(nids)) % len(nids)
)
# Deck change # Deck change
###################################################################### ######################################################################
@ -2001,8 +1999,8 @@ where id in %s"""
t = "" t = ""
groups = len(res) groups = len(res)
notes = sum(len(r[1]) for r in res) notes = sum(len(r[1]) for r in res)
part1 = ngettext("%d group", "%d groups", groups) % groups part1 = tr(TR.BROWSING_GROUP, count=groups)
part2 = ngettext("%d note", "%d notes", notes) % notes part2 = tr(TR.BROWSING_NOTE_COUNT, count=notes)
t += tr(TR.BROWSING_FOUND_AS_ACROSS_BS) % dict(a=part1, b=part2) t += tr(TR.BROWSING_FOUND_AS_ACROSS_BS) % dict(a=part1, b=part2)
t += "<p><ol>" t += "<p><ol>"
for val, nids in res: for val, nids in res:
@ -2010,7 +2008,7 @@ where id in %s"""
"""<li><a href=# onclick="pycmd('%s');return false;">%s</a>: %s</a>""" """<li><a href=# onclick="pycmd('%s');return false;">%s</a>: %s</a>"""
% ( % (
"nid:" + ",".join(str(id) for id in nids), "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), html.escape(val),
) )
) )

View file

@ -561,7 +561,7 @@ class CardLayout(QDialog):
card_cnt = fut.result() card_cnt = fut.result()
template = self.current_template() 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( msg = tr(TR.CARD_TEMPLATES_DELETE_THE_AS_CARD_TYPE_AND) % dict(
a=template["name"], b=cards a=template["name"], b=cards
) )

View file

@ -285,7 +285,7 @@ class DeckBrowser:
"odid in {0}".format(ids2str(dids)) "odid in {0}".format(ids2str(dids))
) )
if cnt: if cnt:
extra = ngettext(" It has %d card.", " It has %d cards.", cnt) % cnt extra = tr(TR.DECKS_IT_HAS_CARD, count=cnt)
else: else:
extra = None extra = None
if ( if (

View file

@ -122,7 +122,7 @@ class FieldDialog(QDialog):
if len(self.model["flds"]) < 2: if len(self.model["flds"]) < 2:
return showWarning(tr(TR.FIELDS_NOTES_REQUIRE_AT_LEAST_ONE_FIELD)) return showWarning(tr(TR.FIELDS_NOTES_REQUIRE_AT_LEAST_ONE_FIELD))
count = self.mm.useCount(self.model) 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)): if not askUser(tr(TR.FIELDS_DELETE_FIELD_FROM, val=c)):
return return
if not self.change_tracker.mark_schema(): if not self.change_tracker.mark_schema():

View file

@ -1217,7 +1217,7 @@ title="%s" %s>%s</button>""" % (
if devMode: if devMode:
print("clock is off; ignoring") print("clock is off; ignoring")
return return
diffText = ngettext("%s second", "%s seconds", diff) % diff diffText = tr(TR.QT_MISC_SECOND, count=diff)
warn = ( warn = (
_( _(
"""\ """\

View file

@ -110,7 +110,7 @@ class Models(QDialog):
self.models = notetypes self.models = notetypes
for m in self.models: 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)) item = QListWidgetItem("%s [%s]" % (m.name, mUse))
self.form.modelsList.addItem(item) self.form.modelsList.addItem(item)
self.form.modelsList.setCurrentRow(row) self.form.modelsList.setCurrentRow(row)

View file

@ -92,12 +92,9 @@ class Reviewer:
elapsed = self.mw.col.timeboxReached() elapsed = self.mw.col.timeboxReached()
if elapsed: if elapsed:
assert not isinstance(elapsed, bool) assert not isinstance(elapsed, bool)
part1 = ( part1 = tr(TR.STUDYING_CARD_STUDIED_IN, count=elapsed[1])
ngettext("%d card studied in", "%d cards studied in", elapsed[1])
% elapsed[1]
)
mins = int(round(elapsed[0] / 60)) 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) fin = tr(TR.STUDYING_FINISH)
diag = askUserDialog( diag = askUserDialog(
"%s %s" % (part1, part2), [tr(TR.STUDYING_CONTINUE), fin] "%s %s" % (part1, part2), [tr(TR.STUDYING_CONTINUE), fin]

View file

@ -3,11 +3,11 @@
import glob, re, json, stringcase import glob, re, json, stringcase
files = ( files = (
glob.glob("../../pylib/**/*.py", recursive=True) # glob.glob("../../pylib/**/*.py", recursive=True)
# + glob.glob("../../qt/**/*.py", recursive=True) glob.glob("../../qt/**/*.py", recursive=True)
# glob.glob("../../qt/**/forms/*.ui", 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")) map = json.load(open("keys_by_text.json"))
@ -20,6 +20,8 @@ blacklist = {
"~", "~",
"about:blank", "about:blank",
"%d card imported.", "%d card imported.",
# need to update manually
"Browse (%(cur)d card shown; %(sel)s)",
# previewer.py needs updating to fix these # previewer.py needs updating to fix these
"Shortcut key: R", "Shortcut key: R",
"Shortcut key: B", "Shortcut key: B",
@ -72,7 +74,7 @@ def repl(m):
screaming = stringcase.constcase(key) 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) print(ret)
return ret return ret
@ -84,7 +86,6 @@ for file in files:
buf2 = string_re.sub(repl, buf) buf2 = string_re.sub(repl, buf)
if buf != buf2: if buf != buf2:
lines = buf2.split("\n") lines = buf2.split("\n")
lines.insert(3, "from anki.rsbackend import TR") lines.insert(3, "from aqt.utils import tr, TR")
lines.insert(3, "from anki.lang import tr_legacyglobal")
buf2 = "\n".join(lines) buf2 = "\n".join(lines)
open(file, "w").write(buf2) open(file, "w").write(buf2)