update pylib ngettext references

This commit is contained in:
Damien Elmes 2020-11-18 09:12:25 +10:00
parent e9cd956acd
commit 177d98489a
3 changed files with 28 additions and 20 deletions

View File

@ -7,7 +7,6 @@ from typing import cast
from anki.db import DB
from anki.importing.noteimp import ForeignCard, ForeignNote, NoteImporter
from anki.lang import ngettext
from anki.rsbackend import TR
from anki.stdmodels import addBasicModel, addClozeModel
@ -104,9 +103,7 @@ acq_reps+ret_reps, lapses, card_type_id from cards"""
self.total += total
self._addCloze(cloze)
self.total += total
self.log.append(
ngettext("%d note imported.", "%d notes imported.", self.total) % self.total
)
self.log.append(self.col.tr(TR.IMPORTING_NOTE_IMPORTED, count=self.total))
def fields(self):
return self._fields

View File

@ -7,7 +7,6 @@ from typing import Dict, List, Optional, Tuple, Union
from anki.collection import Collection
from anki.consts import NEW_CARDS_RANDOM, STARTING_FACTOR
from anki.importing.base import Importer
from anki.lang import ngettext
from anki.rsbackend import TR
from anki.utils import (
fieldChecksum,
@ -221,20 +220,15 @@ class NoteImporter(Importer):
if conf["new"]["order"] == NEW_CARDS_RANDOM:
self.col.sched.randomizeCards(did)
part1 = ngettext("%d note added", "%d notes added", len(new)) % len(new)
part2 = (
ngettext("%d note updated", "%d notes updated", self.updateCount)
% self.updateCount
)
part1 = self.col.tr(TR.IMPORTING_NOTE_ADDED, count=len(new))
part2 = self.col.tr(TR.IMPORTING_NOTE_UPDATED, count=self.updateCount)
if self.importMode == UPDATE_MODE:
unchanged = dupeCount - self.updateCount
elif self.importMode == IGNORE_MODE:
unchanged = dupeCount
else:
unchanged = 0
part3 = (
ngettext("%d note unchanged", "%d notes unchanged", unchanged) % unchanged
)
part3 = self.col.tr(TR.IMPORTING_NOTE_UNCHANGED, count=unchanged)
self.log.append("%s, %s, %s." % (part1, part2, part3))
self.log.extend(updateLog)
self.total = len(self._ids)

View File

@ -3,11 +3,11 @@
import glob, re, json, stringcase
files = (
# glob.glob("../../pylib/**/*.py", recursive=True)
# glob.glob("../../qt/**/*.py", recursive=True)
glob.glob("../../qt/**/forms/*.ui", 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"<string>(.*?)</string>")
string_re = re.compile(r'ngettext\(\s*"(.+?)",\s+".+?",\s+(.+?)\) % \2')
map = json.load(open("keys_by_text.json"))
@ -19,6 +19,7 @@ blacklist = {
"Show %s",
"~",
"about:blank",
"%d card imported.",
# previewer.py needs updating to fix these
"Shortcut key: R",
"Shortcut key: B",
@ -52,16 +53,28 @@ def decode_ents(html):
return reEnts.sub(fixup, html)
def munge_key(key):
if key == "browsing-note":
return "browsing-note-count"
if key == "card-templates-card":
return "card-templates-card-count"
return key
def repl(m):
print(m.group(0))
text = decode_ents(m.group(1))
if text in blacklist:
return m.group(0)
(module, key) = map[text]
screaming = stringcase.constcase(key)
print(screaming)
key = munge_key(key)
return f"<string>{screaming}</string>"
screaming = stringcase.constcase(key)
ret = f"tr_legacyglobal(TR.{screaming}, count={m.group(2)})"
print(ret)
return ret
for file in files:
@ -70,4 +83,8 @@ for file in files:
buf = open(file).read()
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")
buf2 = "\n".join(lines)
open(file, "w").write(buf2)