update TR references that crossed multiple lines

This commit is contained in:
Damien Elmes 2021-03-26 14:38:15 +10:00
parent b7587cb8d2
commit e687552aeb
13 changed files with 32 additions and 70 deletions

View file

@ -10,7 +10,6 @@ from anki.collection import Collection
from anki.consts import * from anki.consts import *
from anki.decks import DeckID, DeckManager from anki.decks import DeckID, DeckManager
from anki.importing.base import Importer from anki.importing.base import Importer
from anki.lang import TR
from anki.models import NoteTypeID from anki.models import NoteTypeID
from anki.notes import NoteID from anki.notes import NoteID
from anki.utils import intTime, joinFields, splitFields, stripHTMLMedia from anki.utils import intTime, joinFields, splitFields, stripHTMLMedia
@ -142,22 +141,19 @@ class Anki2Importer(Importer):
if dupesIgnored: if dupesIgnored:
self.log.append( self.log.append(
self.dst.tr( self.dst.tr.importing_notes_that_could_not_be_imported(
TR.IMPORTING_NOTES_THAT_COULD_NOT_BE_IMPORTED, val=len(dupesIgnored) val=len(dupesIgnored)
) )
) )
if update: if update:
self.log.append( self.log.append(
self.dst.tr( self.dst.tr.importing_notes_updated_as_file_had_newer(val=len(update))
TR.IMPORTING_NOTES_UPDATED_AS_FILE_HAD_NEWER, val=len(update)
)
) )
if add: if add:
self.log.append(self.dst.tr.importing_notes_added_from_file(val=len(add))) self.log.append(self.dst.tr.importing_notes_added_from_file(val=len(add)))
if dupesIdentical: if dupesIdentical:
self.log.append( self.log.append(
self.dst.tr( self.dst.tr.importing_notes_skipped_as_theyre_already_in(
TR.IMPORTING_NOTES_SKIPPED_AS_THEYRE_ALREADY_IN,
val=len(dupesIdentical), val=len(dupesIdentical),
) )
) )

View file

@ -7,7 +7,6 @@ from typing import Any, List, Optional, TextIO, Union
from anki.collection import Collection from anki.collection import Collection
from anki.importing.noteimp import ForeignNote, NoteImporter from anki.importing.noteimp import ForeignNote, NoteImporter
from anki.lang import TR
class TextImporter(NoteImporter): class TextImporter(NoteImporter):
@ -41,8 +40,7 @@ class TextImporter(NoteImporter):
if len(row) != self.numFields: if len(row) != self.numFields:
if row: if row:
log.append( log.append(
self.col.tr( self.col.tr.importing_rows_had_num1d_fields_expected_num2d(
TR.IMPORTING_ROWS_HAD_NUM1D_FIELDS_EXPECTED_NUM2D,
row=" ".join(row), row=" ".join(row),
found=len(row), found=len(row),
expected=self.numFields, expected=self.numFields,

View file

@ -9,7 +9,6 @@ from anki.collection import Collection
from anki.config import Config from anki.config import Config
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 TR
from anki.models import NoteTypeID from anki.models import NoteTypeID
from anki.notes import NoteID from anki.notes import NoteID
from anki.utils import ( from anki.utils import (
@ -177,9 +176,7 @@ class NoteImporter(Importer):
if data: if data:
updates.append(data) updates.append(data)
updateLog.append( updateLog.append(
self.col.tr( self.col.tr.importing_first_field_matched(val=fld0)
TR.IMPORTING_FIRST_FIELD_MATCHED, val=fld0
)
) )
dupeCount += 1 dupeCount += 1
found = True found = True
@ -191,8 +188,7 @@ class NoteImporter(Importer):
# only show message once, no matter how many # only show message once, no matter how many
# duplicates are in the collection already # duplicates are in the collection already
updateLog.append( updateLog.append(
self.col.tr( self.col.tr.importing_added_duplicate_with_first_field(
TR.IMPORTING_ADDED_DUPLICATE_WITH_FIRST_FIELD,
val=fld0, val=fld0,
) )
) )

View file

@ -10,7 +10,7 @@ from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
import anki import anki
from anki.consts import * from anki.consts import *
from anki.lang import TR, FormatTimeSpan from anki.lang import FormatTimeSpan
from anki.utils import ids2str from anki.utils import ids2str
# Card stats # Card stats
@ -421,9 +421,8 @@ group by day order by day"""
self._line( self._line(
i, i,
"Average answer time", "Average answer time",
self.col.tr( self.col.tr.statistics_average_answer_time(
TR.STATISTICS_AVERAGE_ANSWER_TIME, average_seconds=average_secs
**{"cards-per-minute": perMin, "average-seconds": average_secs},
), ),
) )
return self._lineTbl(i), int(tot) return self._lineTbl(i), int(tot)

View file

@ -9,7 +9,7 @@ from re import Match
import stringcase import stringcase
TR_REF = re.compile(r"tr\(TR.([^,) ]+),\s*([^)]+)\)") TR_REF = re.compile(r"tr\(\s*TR.([^,) ]+),\s*([^)]+)\)")
def repl(m: Match) -> str: def repl(m: Match) -> str:
@ -19,19 +19,10 @@ def repl(m: Match) -> str:
def update_py(path: str) -> None: def update_py(path: str) -> None:
buf = [] buf = open(path).read()
changed = False buf2 = TR_REF.sub(repl, buf)
for line in open(path): if buf != buf2:
line2 = TR_REF.sub(repl, line) open(path, "w").writelines(buf2)
if line != line2:
print(line2)
buf.append(line2)
changed = True
else:
buf.append(line)
if changed:
open(path, "w").writelines(buf)
print("updated", path) print("updated", path)

View file

@ -380,8 +380,7 @@ def setupGL(pm: aqt.profiles.ProfileManager) -> None:
QMessageBox.critical( QMessageBox.critical(
None, None,
tr.qt_misc_error(), tr.qt_misc_error(),
tr( tr.qt_misc_error_loading_graphics_driver(
TR.QT_MISC_ERROR_LOADING_GRAPHICS_DRIVER,
mode=driver.value, mode=driver.value,
context=context, context=context,
), ),

View file

@ -8,7 +8,7 @@ from anki.lang import without_unicode_isolation
from anki.utils import versionWithBuild from anki.utils import versionWithBuild
from aqt.addons import AddonManager, AddonMeta from aqt.addons import AddonManager, AddonMeta
from aqt.qt import * from aqt.qt import *
from aqt.utils import TR, disable_help_button, supportText, tooltip, tr from aqt.utils import disable_help_button, supportText, tooltip, tr
class ClosableQDialog(QDialog): class ClosableQDialog(QDialog):
@ -209,8 +209,8 @@ def show(mw: aqt.AnkiQt) -> QDialog:
) )
) )
abouttext += "<p>" + tr( abouttext += "<p>" + tr.about_written_by_damien_elmes_with_patches(
TR.ABOUT_WRITTEN_BY_DAMIEN_ELMES_WITH_PATCHES, cont=", ".join(allusers) cont=", ".join(allusers)
) )
abouttext += f"<p>{tr.about_if_you_have_contributed_and_are()}" abouttext += f"<p>{tr.about_if_you_have_contributed_and_are()}"
abouttext += f"<p>{tr.about_a_big_thanks_to_all_the()}" abouttext += f"<p>{tr.about_a_big_thanks_to_all_the()}"

View file

@ -28,7 +28,6 @@ from anki.lang import without_unicode_isolation
from aqt import gui_hooks from aqt import gui_hooks
from aqt.qt import * from aqt.qt import *
from aqt.utils import ( from aqt.utils import (
TR,
askUser, askUser,
disable_help_button, disable_help_button,
getFile, getFile,
@ -220,8 +219,7 @@ class AddonManager:
pass pass
except: except:
showWarning( showWarning(
tr( tr.addons_failed_to_load(
TR.ADDONS_FAILED_TO_LOAD,
name=addon.human_name(), name=addon.human_name(),
traceback=traceback.format_exc(), traceback=traceback.format_exc(),
) )
@ -286,8 +284,7 @@ class AddonManager:
if conflicting: if conflicting:
addons = ", ".join(self.addonName(f) for f in conflicting) addons = ", ".join(self.addonName(f) for f in conflicting)
showInfo( showInfo(
tr( tr.addons_the_following_addons_are_incompatible_with(
TR.ADDONS_THE_FOLLOWING_ADDONS_ARE_INCOMPATIBLE_WITH,
name=addon.human_name(), name=addon.human_name(),
found=addons, found=addons,
), ),
@ -1090,8 +1087,7 @@ class DownloaderInstaller(QObject):
def _progress_callback(self, up: int, down: int) -> None: def _progress_callback(self, up: int, down: int) -> None:
self.dl_bytes += down self.dl_bytes += down
self.mgr.mw.progress.update( self.mgr.mw.progress.update(
label=tr( label=tr.addons_downloading_adbd_kb02fkb(
TR.ADDONS_DOWNLOADING_ADBD_KB02FKB,
part=len(self.log) + 1, part=len(self.log) + 1,
total=len(self.ids), total=len(self.ids),
kilobytes=self.dl_bytes / 1024, kilobytes=self.dl_bytes / 1024,
@ -1459,8 +1455,7 @@ class ConfigEditor(QDialog):
restoreSplitter(self.form.splitter, "addonconf") restoreSplitter(self.form.splitter, "addonconf")
self.setWindowTitle( self.setWindowTitle(
without_unicode_isolation( without_unicode_isolation(
tr( tr.addons_config_window_title(
TR.ADDONS_CONFIG_WINDOW_TITLE,
name=self.mgr.addon_meta(addon).human_name(), name=self.mgr.addon_meta(addon).human_name(),
) )
) )
@ -1528,8 +1523,7 @@ class ConfigEditor(QDialog):
erroneous_conf=erroneous_conf, erroneous_conf=erroneous_conf,
) )
else: else:
msg = tr( msg = tr.addons_config_validation_error(
TR.ADDONS_CONFIG_VALIDATION_ERROR,
problem=e.message, problem=e.message,
path=path, path=path,
schema=str(schema), schema=str(schema),

View file

@ -53,7 +53,6 @@ from aqt.sidebar import SidebarTreeView
from aqt.tag_ops import add_tags, clear_unused_tags, remove_tags_for_notes from aqt.tag_ops import add_tags, clear_unused_tags, remove_tags_for_notes
from aqt.theme import theme_manager from aqt.theme import theme_manager
from aqt.utils import ( from aqt.utils import (
TR,
HelpPage, HelpPage,
KeyboardModifiersPressed, KeyboardModifiersPressed,
askUser, askUser,
@ -801,8 +800,7 @@ QTableView {{ gridline-color: {grid} }}
None, None,
"preview", "preview",
lambda _editor: self.onTogglePreview(), lambda _editor: self.onTogglePreview(),
tr( tr.browsing_preview_selected_card(
TR.BROWSING_PREVIEW_SELECTED_CARD,
val=shortcut(preview_shortcut), val=shortcut(preview_shortcut),
), ),
tr.actions_preview(), tr.actions_preview(),

View file

@ -17,7 +17,6 @@ from aqt.schema_change_tracker import ChangeTracker
from aqt.sound import av_player, play_clicked_audio from aqt.sound import av_player, play_clicked_audio
from aqt.theme import theme_manager from aqt.theme import theme_manager
from aqt.utils import ( from aqt.utils import (
TR,
HelpPage, HelpPage,
askUser, askUser,
disable_help_button, disable_help_button,
@ -559,8 +558,7 @@ class CardLayout(QDialog):
template = self.current_template() template = self.current_template()
cards = tr.card_templates_card_count(count=card_cnt) cards = tr.card_templates_card_count(count=card_cnt)
msg = tr( msg = tr.card_templates_delete_the_as_card_type_and(
TR.CARD_TEMPLATES_DELETE_THE_AS_CARD_TYPE_AND,
template=template["name"], template=template["name"],
cards=cards, cards=cards,
) )

View file

@ -5,7 +5,7 @@ import aqt
from anki.collection import SearchNode from anki.collection import SearchNode
from anki.consts import * from anki.consts import *
from aqt.qt import * from aqt.qt import *
from aqt.utils import TR, disable_help_button, showInfo, showWarning, tr from aqt.utils import disable_help_button, showInfo, showWarning, tr
RADIO_NEW = 1 RADIO_NEW = 1
RADIO_REV = 2 RADIO_REV = 2
@ -68,9 +68,7 @@ class CustomStudy(QDialog):
new, self.conf["new"]["perDay"] - self.deck["newToday"][1] new, self.conf["new"]["perDay"] - self.deck["newToday"][1]
) )
newExceeding = min(new, new - newUnderLearning) newExceeding = min(new, new - newUnderLearning)
tit = tr( tit = tr.custom_study_new_cards_in_deck_over_today(val=plus(newExceeding))
TR.CUSTOM_STUDY_NEW_CARDS_IN_DECK_OVER_TODAY, val=plus(newExceeding)
)
pre = tr.custom_study_increase_todays_new_card_limit_by() pre = tr.custom_study_increase_todays_new_card_limit_by()
sval = min(new, self.deck.get("extendNew", 10)) sval = min(new, self.deck.get("extendNew", 10))
smin = -DYN_MAX_SIZE smin = -DYN_MAX_SIZE
@ -82,9 +80,7 @@ class CustomStudy(QDialog):
rev, self.conf["rev"]["perDay"] - self.deck["revToday"][1] rev, self.conf["rev"]["perDay"] - self.deck["revToday"][1]
) )
revExceeding = min(rev, rev - revUnderLearning) revExceeding = min(rev, rev - revUnderLearning)
tit = tr( tit = tr.custom_study_reviews_due_in_deck_over_today(val=plus(revExceeding))
TR.CUSTOM_STUDY_REVIEWS_DUE_IN_DECK_OVER_TODAY, val=plus(revExceeding)
)
pre = tr.custom_study_increase_todays_review_limit_by() pre = tr.custom_study_increase_todays_review_limit_by()
sval = min(rev, self.deck.get("extendRev", 10)) sval = min(rev, self.deck.get("extendRev", 10))
smin = -DYN_MAX_SIZE smin = -DYN_MAX_SIZE

View file

@ -35,7 +35,6 @@ from aqt.qt import *
from aqt.sound import av_player from aqt.sound import av_player
from aqt.theme import theme_manager from aqt.theme import theme_manager
from aqt.utils import ( from aqt.utils import (
TR,
HelpPage, HelpPage,
KeyboardModifiersPressed, KeyboardModifiersPressed,
disable_help_button, disable_help_button,
@ -957,8 +956,7 @@ class Editor:
client.timeout = 30 client.timeout = 30
with client.get(url) as response: with client.get(url) as response:
if response.status_code != 200: if response.status_code != 200:
error_msg = tr( error_msg = tr.qt_misc_unexpected_response_code(
TR.QT_MISC_UNEXPECTED_RESPONSE_CODE,
val=response.status_code, val=response.status_code,
) )
return None return None

View file

@ -24,7 +24,7 @@ from anki.sync import SyncAuth
from anki.utils import intTime, isMac, isWin from anki.utils import intTime, isMac, isWin
from aqt import appHelpSite from aqt import appHelpSite
from aqt.qt import * from aqt.qt import *
from aqt.utils import TR, disable_help_button, showWarning, tr from aqt.utils import disable_help_button, showWarning, tr
# Profile handling # Profile handling
########################################################################## ##########################################################################
@ -516,8 +516,7 @@ create table if not exists profiles
with open(p, "w", encoding="utf8") as file: with open(p, "w", encoding="utf8") as file:
file.write( file.write(
without_unicode_isolation( without_unicode_isolation(
tr( tr.profiles_folder_readme(
TR.PROFILES_FOLDER_README,
link=f"{appHelpSite}files?id=startup-options", link=f"{appHelpSite}files?id=startup-options",
) )
) )