update pylib ngettext references
This commit is contained in:
parent
e9cd956acd
commit
177d98489a
@ -7,7 +7,6 @@ from typing import cast
|
|||||||
|
|
||||||
from anki.db import DB
|
from anki.db import DB
|
||||||
from anki.importing.noteimp import ForeignCard, ForeignNote, NoteImporter
|
from anki.importing.noteimp import ForeignCard, ForeignNote, NoteImporter
|
||||||
from anki.lang import ngettext
|
|
||||||
from anki.rsbackend import TR
|
from anki.rsbackend import TR
|
||||||
from anki.stdmodels import addBasicModel, addClozeModel
|
from anki.stdmodels import addBasicModel, addClozeModel
|
||||||
|
|
||||||
@ -104,9 +103,7 @@ acq_reps+ret_reps, lapses, card_type_id from cards"""
|
|||||||
self.total += total
|
self.total += total
|
||||||
self._addCloze(cloze)
|
self._addCloze(cloze)
|
||||||
self.total += total
|
self.total += total
|
||||||
self.log.append(
|
self.log.append(self.col.tr(TR.IMPORTING_NOTE_IMPORTED, count=self.total))
|
||||||
ngettext("%d note imported.", "%d notes imported.", self.total) % self.total
|
|
||||||
)
|
|
||||||
|
|
||||||
def fields(self):
|
def fields(self):
|
||||||
return self._fields
|
return self._fields
|
||||||
|
@ -7,7 +7,6 @@ from typing import Dict, List, Optional, Tuple, Union
|
|||||||
from anki.collection import Collection
|
from anki.collection import Collection
|
||||||
from anki.consts import NEW_CARDS_RANDOM, STARTING_FACTOR
|
from anki.consts import NEW_CARDS_RANDOM, STARTING_FACTOR
|
||||||
from anki.importing.base import Importer
|
from anki.importing.base import Importer
|
||||||
from anki.lang import ngettext
|
|
||||||
from anki.rsbackend import TR
|
from anki.rsbackend import TR
|
||||||
from anki.utils import (
|
from anki.utils import (
|
||||||
fieldChecksum,
|
fieldChecksum,
|
||||||
@ -221,20 +220,15 @@ class NoteImporter(Importer):
|
|||||||
if conf["new"]["order"] == NEW_CARDS_RANDOM:
|
if conf["new"]["order"] == NEW_CARDS_RANDOM:
|
||||||
self.col.sched.randomizeCards(did)
|
self.col.sched.randomizeCards(did)
|
||||||
|
|
||||||
part1 = ngettext("%d note added", "%d notes added", len(new)) % len(new)
|
part1 = self.col.tr(TR.IMPORTING_NOTE_ADDED, count=len(new))
|
||||||
part2 = (
|
part2 = self.col.tr(TR.IMPORTING_NOTE_UPDATED, count=self.updateCount)
|
||||||
ngettext("%d note updated", "%d notes updated", self.updateCount)
|
|
||||||
% self.updateCount
|
|
||||||
)
|
|
||||||
if self.importMode == UPDATE_MODE:
|
if self.importMode == UPDATE_MODE:
|
||||||
unchanged = dupeCount - self.updateCount
|
unchanged = dupeCount - self.updateCount
|
||||||
elif self.importMode == IGNORE_MODE:
|
elif self.importMode == IGNORE_MODE:
|
||||||
unchanged = dupeCount
|
unchanged = dupeCount
|
||||||
else:
|
else:
|
||||||
unchanged = 0
|
unchanged = 0
|
||||||
part3 = (
|
part3 = self.col.tr(TR.IMPORTING_NOTE_UNCHANGED, count=unchanged)
|
||||||
ngettext("%d note unchanged", "%d notes unchanged", unchanged) % unchanged
|
|
||||||
)
|
|
||||||
self.log.append("%s, %s, %s." % (part1, part2, part3))
|
self.log.append("%s, %s, %s." % (part1, part2, part3))
|
||||||
self.log.extend(updateLog)
|
self.log.extend(updateLog)
|
||||||
self.total = len(self._ids)
|
self.total = len(self._ids)
|
||||||
|
@ -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"<string>(.*?)</string>")
|
string_re = re.compile(r'ngettext\(\s*"(.+?)",\s+".+?",\s+(.+?)\) % \2')
|
||||||
|
|
||||||
map = json.load(open("keys_by_text.json"))
|
map = json.load(open("keys_by_text.json"))
|
||||||
|
|
||||||
@ -19,6 +19,7 @@ blacklist = {
|
|||||||
"Show %s",
|
"Show %s",
|
||||||
"~",
|
"~",
|
||||||
"about:blank",
|
"about:blank",
|
||||||
|
"%d card imported.",
|
||||||
# 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",
|
||||||
@ -52,16 +53,28 @@ def decode_ents(html):
|
|||||||
return reEnts.sub(fixup, 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):
|
def repl(m):
|
||||||
|
print(m.group(0))
|
||||||
text = decode_ents(m.group(1))
|
text = decode_ents(m.group(1))
|
||||||
if text in blacklist:
|
if text in blacklist:
|
||||||
return m.group(0)
|
return m.group(0)
|
||||||
|
|
||||||
(module, key) = map[text]
|
(module, key) = map[text]
|
||||||
screaming = stringcase.constcase(key)
|
key = munge_key(key)
|
||||||
print(screaming)
|
|
||||||
|
|
||||||
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:
|
for file in files:
|
||||||
@ -70,4 +83,8 @@ for file in files:
|
|||||||
buf = open(file).read()
|
buf = open(file).read()
|
||||||
buf2 = string_re.sub(repl, buf)
|
buf2 = string_re.sub(repl, buf)
|
||||||
if buf != buf2:
|
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)
|
open(file, "w").write(buf2)
|
||||||
|
Loading…
Reference in New Issue
Block a user