diff --git a/aqt/browser.py b/aqt/browser.py index 17798131d..b2ca7097b 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -17,6 +17,7 @@ from anki.hooks import runHook, addHook, remHook from aqt.webview import AnkiWebView from aqt.toolbar import Toolbar from anki.consts import * +from anki.lang import ngettext COLOUR_SUSPENDED = "#FFFFB2" COLOUR_MARKED = "#D9B2E9" @@ -1179,13 +1180,15 @@ update cards set usn=?, mod=?, did=? where odid=0 and id in """ + ids2str( self.mw.progress.start() res = self.mw.col.findDupes(fname, search) t = "" - t += _("Found %(a)d group of duplicates across %(b)d notes.") % dict( - b=sum(len(r[1]) for r in res), a=len(res)) + part1 = ngettext("Found %d duplicate in", "Found %d duplicates in", \ + sum(len(r[1]) for r in res)) % sum(len(r[1]) for r in res) + part2 = ngettext("%d note.", "%d notes.", len(res)) % len(res) + t += "%s %s" % (part1, part2) t += "

    " for val, nids in res: t += '
  1. %s: %s' % ( "nid:" + ",".join(str(id) for id in nids), - _("%d notes") % len(nids), + ngettext("%d note", "%d notes", len(nids)) % len(nids), cgi.escape(val)) t += "
" t += "" diff --git a/aqt/deckbrowser.py b/aqt/deckbrowser.py index 7328d9636..232fcbcb9 100644 --- a/aqt/deckbrowser.py +++ b/aqt/deckbrowser.py @@ -10,6 +10,7 @@ import anki.js from anki.errors import DeckRenameError import aqt from anki.sound import clearAudioQueue +from anki.lang import ngettext class DeckBrowser(object): @@ -155,8 +156,8 @@ select count(), sum(time)/1000 from revlog where id > ?""", (self.mw.col.sched.dayCutoff-86400)*1000) cards = cards or 0 thetime = thetime or 0 - buf = _("Studied %(a)d cards in %(b)s today.") % dict( - a=cards, b=fmtTimeSpan(thetime)) + msgp1 = ngettext("Studied %d card", "Studied %d cards", cards) % cards + buf = "%s in %s today." % (msgp1, fmtTimeSpan(thetime)) return buf def _renderDeckTree(self, nodes, depth=0): @@ -288,7 +289,7 @@ where id > ?""", (self.mw.col.sched.dayCutoff-86400)*1000) "select count() from cards where did in {0} or " "odid in {0}".format(ids2str(dids))) if cnt: - extra = _(" It has %d cards.") % cnt + extra = ngettext(" It has %d card.", " It has %d cards.", cnt) % cnt else: extra = None if deck['dyn'] or not extra or askUser( diff --git a/aqt/deckconf.py b/aqt/deckconf.py index 4a6ee45d0..f0a336798 100644 --- a/aqt/deckconf.py +++ b/aqt/deckconf.py @@ -8,6 +8,7 @@ from anki.utils import ids2str from aqt.utils import showInfo, showWarning, openHelp, getOnlyText, askUser, \ tooltip from operator import itemgetter +from anki.lang import ngettext class DeckConf(QDialog): def __init__(self, mw, deck): @@ -92,7 +93,8 @@ class DeckConf(QDialog): continue if d['conf'] == conf['id']: cnt += 1 - self.form.count.setText(_("%d decks use this options group") % cnt) + self.form.count.setText(ngettext("%d deck uses this options group", \ + "%d decks use this options group", cnt) % cnt) def addGroup(self): name = getOnlyText(_("New options group name:")) @@ -132,7 +134,9 @@ class DeckConf(QDialog): deck = self.mw.col.decks.get(did) deck['conf'] = self.deck['conf'] self.mw.col.decks.save(deck) - tooltip(_("%d decks updated.") % len(self.childDids)) + + tooltip(ngettext("%d deck updated.", "%d decks updated.", \ + len(self.childDids)) % len(self.childDids)) # Loading ################################################## diff --git a/aqt/exporting.py b/aqt/exporting.py index 9be2fa388..d32a8ce43 100644 --- a/aqt/exporting.py +++ b/aqt/exporting.py @@ -6,6 +6,7 @@ from aqt.qt import * import anki, aqt, aqt.tagedit from aqt.utils import getSaveFile, tooltip, showWarning from anki.exporting import exporters +from anki.lang import ngettext class ExportDialog(QDialog): @@ -63,7 +64,8 @@ class ExportDialog(QDialog): else: os.unlink(file) self.exporter.exportInto(file) - tooltip(_("%d exported.") % self.exporter.count) + tooltip(ngettext("%d card exported.", "%d cards exported.", \ + self.exporter.count) % self.exporter.count) finally: self.mw.progress.finish() QDialog.accept(self) diff --git a/aqt/main.py b/aqt/main.py index 6b21bf7d9..871fcca4c 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -19,6 +19,7 @@ from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \ saveState, restoreState, getOnlyText, askUser, GetTextDialog, \ askUserDialog, applyStyles, getText, showText, showCritical, getFile, \ tooltip, openHelp, openLink +from anki.lang import ngettext class AnkiQt(QMainWindow): def __init__(self, app, profileManager, args): @@ -893,16 +894,16 @@ will be lost. Continue?""")) return report = self.col.emptyCardReport(cids) self.progress.finish() - diag, box = showText( - _("%(cnt)d cards to delete:\n\n%(rep)s") % dict( - cnt=len(cids), rep=report), run=False) + part1 = ngettext("%d card", "%d cards", len(cids)) + part2 = "to delete:\n\n%s" % report + diag, box = showText("%s %s" % (part1, part2), run=False) box.addButton(_("Delete Cards"), QDialogButtonBox.AcceptRole) box.button(QDialogButtonBox.Close).setDefault(True) def onDelete(): QDialog.accept(diag) self.checkpoint(_("Delete Empty")) self.col.remCards(cids) - tooltip(_("%d cards deleted.") % len(cids)) + tooltip(ngettext("%d card deleted.", "%d cards deleted.", len(cids)) % len(cids)) self.reset() diag.connect(box, SIGNAL("accepted()"), onDelete) diag.show() diff --git a/aqt/models.py b/aqt/models.py index 57c435946..e54e11b95 100644 --- a/aqt/models.py +++ b/aqt/models.py @@ -7,6 +7,7 @@ from aqt.utils import showInfo, askUser, getText, maybeHideClose, openHelp import aqt.modelchooser, aqt.clayout from anki import stdmodels from aqt.utils import saveGeom, restoreGeom +from anki.lang import ngettext class Models(QDialog): def __init__(self, mw, parent=None): @@ -62,8 +63,9 @@ class Models(QDialog): self.models.sort(key=itemgetter("name")) self.form.modelsList.clear() for m in self.models: - item = QListWidgetItem(_("%(name)s [%(notes)d notes]") % dict( - name=m['name'], notes=self.mm.useCount(m))) + item = QListWidgetItem(ngettext("%s [%d note]", "%s [%d notes]", \ + self.mm.useCount(m)) % ( + m['name'], self.mm.useCount(m))) self.form.modelsList.addItem(item) self.form.modelsList.setCurrentRow(row) diff --git a/aqt/reviewer.py b/aqt/reviewer.py index 36dd7349c..476cb1800 100644 --- a/aqt/reviewer.py +++ b/aqt/reviewer.py @@ -12,6 +12,7 @@ from anki.sound import playFromText, clearAudioQueue, hasSound, play from aqt.utils import mungeQA, getBase, shortcut, openLink, tooltip from aqt.sound import getAudio import aqt +from anki.lang import ngettext class Reviewer(object): "Manage reviews. Maintains a separate state." @@ -82,9 +83,9 @@ class Reviewer(object): self._showQuestion() elapsed = self.mw.col.timeboxReached() if elapsed: - tooltip(_("%(cards)d cards studied in %(mins)s minutes.") % - dict(cards=elapsed[1], mins=elapsed[0]/60), - period=5000) + part1 = ngettext("%d card studied in", "%d cards studied in", elapsed[1]) % elapsed[1] + part2 = ngettext("%s minute.", "%s minutes.", elapsed[0]/60) % (elapsed[0]/60) + tooltip("%s %s" % (part1, part2), period=5000) self.mw.col.startTimebox() # Audio