diff --git a/pylib/anki/importing/anki2.py b/pylib/anki/importing/anki2.py index b5f4ca44f..f911155b9 100644 --- a/pylib/anki/importing/anki2.py +++ b/pylib/anki/importing/anki2.py @@ -10,7 +10,6 @@ from anki.collection import Collection from anki.consts import * from anki.decks import DeckID, DeckManager from anki.importing.base import Importer -from anki.lang import TR from anki.models import NoteTypeID from anki.notes import NoteID from anki.utils import intTime, joinFields, splitFields, stripHTMLMedia @@ -142,22 +141,19 @@ class Anki2Importer(Importer): if dupesIgnored: self.log.append( - self.dst.tr( - TR.IMPORTING_NOTES_THAT_COULD_NOT_BE_IMPORTED, val=len(dupesIgnored) + self.dst.tr.importing_notes_that_could_not_be_imported( + val=len(dupesIgnored) ) ) if update: self.log.append( - self.dst.tr( - TR.IMPORTING_NOTES_UPDATED_AS_FILE_HAD_NEWER, val=len(update) - ) + self.dst.tr.importing_notes_updated_as_file_had_newer(val=len(update)) ) if add: self.log.append(self.dst.tr.importing_notes_added_from_file(val=len(add))) if dupesIdentical: self.log.append( - self.dst.tr( - TR.IMPORTING_NOTES_SKIPPED_AS_THEYRE_ALREADY_IN, + self.dst.tr.importing_notes_skipped_as_theyre_already_in( val=len(dupesIdentical), ) ) diff --git a/pylib/anki/importing/csvfile.py b/pylib/anki/importing/csvfile.py index 7bcd760b1..961018772 100644 --- a/pylib/anki/importing/csvfile.py +++ b/pylib/anki/importing/csvfile.py @@ -7,7 +7,6 @@ from typing import Any, List, Optional, TextIO, Union from anki.collection import Collection from anki.importing.noteimp import ForeignNote, NoteImporter -from anki.lang import TR class TextImporter(NoteImporter): @@ -41,8 +40,7 @@ class TextImporter(NoteImporter): if len(row) != self.numFields: if row: log.append( - self.col.tr( - TR.IMPORTING_ROWS_HAD_NUM1D_FIELDS_EXPECTED_NUM2D, + self.col.tr.importing_rows_had_num1d_fields_expected_num2d( row=" ".join(row), found=len(row), expected=self.numFields, diff --git a/pylib/anki/importing/noteimp.py b/pylib/anki/importing/noteimp.py index 125450bbb..df8445a48 100644 --- a/pylib/anki/importing/noteimp.py +++ b/pylib/anki/importing/noteimp.py @@ -9,7 +9,6 @@ from anki.collection import Collection from anki.config import Config from anki.consts import NEW_CARDS_RANDOM, STARTING_FACTOR from anki.importing.base import Importer -from anki.lang import TR from anki.models import NoteTypeID from anki.notes import NoteID from anki.utils import ( @@ -177,9 +176,7 @@ class NoteImporter(Importer): if data: updates.append(data) updateLog.append( - self.col.tr( - TR.IMPORTING_FIRST_FIELD_MATCHED, val=fld0 - ) + self.col.tr.importing_first_field_matched(val=fld0) ) dupeCount += 1 found = True @@ -191,8 +188,7 @@ class NoteImporter(Importer): # only show message once, no matter how many # duplicates are in the collection already updateLog.append( - self.col.tr( - TR.IMPORTING_ADDED_DUPLICATE_WITH_FIRST_FIELD, + self.col.tr.importing_added_duplicate_with_first_field( val=fld0, ) ) diff --git a/pylib/anki/stats.py b/pylib/anki/stats.py index bd7de3e44..618db9a34 100644 --- a/pylib/anki/stats.py +++ b/pylib/anki/stats.py @@ -10,7 +10,7 @@ from typing import Any, Dict, List, Optional, Sequence, Tuple, Union import anki from anki.consts import * -from anki.lang import TR, FormatTimeSpan +from anki.lang import FormatTimeSpan from anki.utils import ids2str # Card stats @@ -421,9 +421,8 @@ group by day order by day""" self._line( i, "Average answer time", - self.col.tr( - TR.STATISTICS_AVERAGE_ANSWER_TIME, - **{"cards-per-minute": perMin, "average-seconds": average_secs}, + self.col.tr.statistics_average_answer_time( + average_seconds=average_secs ), ) return self._lineTbl(i), int(tot) diff --git a/pylib/tools/rewrite_tr.py b/pylib/tools/rewrite_tr.py index b91aa8f6c..de626aed4 100644 --- a/pylib/tools/rewrite_tr.py +++ b/pylib/tools/rewrite_tr.py @@ -9,7 +9,7 @@ from re import Match import stringcase -TR_REF = re.compile(r"tr\(TR.([^,) ]+),\s*([^)]+)\)") +TR_REF = re.compile(r"tr\(\s*TR.([^,) ]+),\s*([^)]+)\)") def repl(m: Match) -> str: @@ -19,19 +19,10 @@ def repl(m: Match) -> str: def update_py(path: str) -> None: - buf = [] - changed = False - for line in open(path): - line2 = TR_REF.sub(repl, line) - if line != line2: - print(line2) - buf.append(line2) - changed = True - else: - buf.append(line) - - if changed: - open(path, "w").writelines(buf) + buf = open(path).read() + buf2 = TR_REF.sub(repl, buf) + if buf != buf2: + open(path, "w").writelines(buf2) print("updated", path) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index 9063ff02d..e6b07f940 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -380,8 +380,7 @@ def setupGL(pm: aqt.profiles.ProfileManager) -> None: QMessageBox.critical( None, tr.qt_misc_error(), - tr( - TR.QT_MISC_ERROR_LOADING_GRAPHICS_DRIVER, + tr.qt_misc_error_loading_graphics_driver( mode=driver.value, context=context, ), diff --git a/qt/aqt/about.py b/qt/aqt/about.py index 662b7862e..a831cfdaa 100644 --- a/qt/aqt/about.py +++ b/qt/aqt/about.py @@ -8,7 +8,7 @@ from anki.lang import without_unicode_isolation from anki.utils import versionWithBuild from aqt.addons import AddonManager, AddonMeta 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): @@ -209,8 +209,8 @@ def show(mw: aqt.AnkiQt) -> QDialog: ) ) - abouttext += "
" + tr( - TR.ABOUT_WRITTEN_BY_DAMIEN_ELMES_WITH_PATCHES, cont=", ".join(allusers) + abouttext += "
" + tr.about_written_by_damien_elmes_with_patches( + cont=", ".join(allusers) ) abouttext += f"
{tr.about_if_you_have_contributed_and_are()}" abouttext += f"
{tr.about_a_big_thanks_to_all_the()}" diff --git a/qt/aqt/addons.py b/qt/aqt/addons.py index b0294a288..605acad31 100644 --- a/qt/aqt/addons.py +++ b/qt/aqt/addons.py @@ -28,7 +28,6 @@ from anki.lang import without_unicode_isolation from aqt import gui_hooks from aqt.qt import * from aqt.utils import ( - TR, askUser, disable_help_button, getFile, @@ -220,8 +219,7 @@ class AddonManager: pass except: showWarning( - tr( - TR.ADDONS_FAILED_TO_LOAD, + tr.addons_failed_to_load( name=addon.human_name(), traceback=traceback.format_exc(), ) @@ -286,8 +284,7 @@ class AddonManager: if conflicting: addons = ", ".join(self.addonName(f) for f in conflicting) showInfo( - tr( - TR.ADDONS_THE_FOLLOWING_ADDONS_ARE_INCOMPATIBLE_WITH, + tr.addons_the_following_addons_are_incompatible_with( name=addon.human_name(), found=addons, ), @@ -1090,8 +1087,7 @@ class DownloaderInstaller(QObject): def _progress_callback(self, up: int, down: int) -> None: self.dl_bytes += down self.mgr.mw.progress.update( - label=tr( - TR.ADDONS_DOWNLOADING_ADBD_KB02FKB, + label=tr.addons_downloading_adbd_kb02fkb( part=len(self.log) + 1, total=len(self.ids), kilobytes=self.dl_bytes / 1024, @@ -1459,8 +1455,7 @@ class ConfigEditor(QDialog): restoreSplitter(self.form.splitter, "addonconf") self.setWindowTitle( without_unicode_isolation( - tr( - TR.ADDONS_CONFIG_WINDOW_TITLE, + tr.addons_config_window_title( name=self.mgr.addon_meta(addon).human_name(), ) ) @@ -1528,8 +1523,7 @@ class ConfigEditor(QDialog): erroneous_conf=erroneous_conf, ) else: - msg = tr( - TR.ADDONS_CONFIG_VALIDATION_ERROR, + msg = tr.addons_config_validation_error( problem=e.message, path=path, schema=str(schema), diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 17b3d1fc6..1127a5ceb 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -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.theme import theme_manager from aqt.utils import ( - TR, HelpPage, KeyboardModifiersPressed, askUser, @@ -801,8 +800,7 @@ QTableView {{ gridline-color: {grid} }} None, "preview", lambda _editor: self.onTogglePreview(), - tr( - TR.BROWSING_PREVIEW_SELECTED_CARD, + tr.browsing_preview_selected_card( val=shortcut(preview_shortcut), ), tr.actions_preview(), diff --git a/qt/aqt/clayout.py b/qt/aqt/clayout.py index e6f90945c..465c3ae88 100644 --- a/qt/aqt/clayout.py +++ b/qt/aqt/clayout.py @@ -17,7 +17,6 @@ from aqt.schema_change_tracker import ChangeTracker from aqt.sound import av_player, play_clicked_audio from aqt.theme import theme_manager from aqt.utils import ( - TR, HelpPage, askUser, disable_help_button, @@ -559,8 +558,7 @@ class CardLayout(QDialog): template = self.current_template() cards = tr.card_templates_card_count(count=card_cnt) - msg = tr( - TR.CARD_TEMPLATES_DELETE_THE_AS_CARD_TYPE_AND, + msg = tr.card_templates_delete_the_as_card_type_and( template=template["name"], cards=cards, ) diff --git a/qt/aqt/customstudy.py b/qt/aqt/customstudy.py index cee0c8c23..931571257 100644 --- a/qt/aqt/customstudy.py +++ b/qt/aqt/customstudy.py @@ -5,7 +5,7 @@ import aqt from anki.collection import SearchNode from anki.consts 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_REV = 2 @@ -68,9 +68,7 @@ class CustomStudy(QDialog): new, self.conf["new"]["perDay"] - self.deck["newToday"][1] ) newExceeding = min(new, new - newUnderLearning) - tit = tr( - TR.CUSTOM_STUDY_NEW_CARDS_IN_DECK_OVER_TODAY, val=plus(newExceeding) - ) + tit = tr.custom_study_new_cards_in_deck_over_today(val=plus(newExceeding)) pre = tr.custom_study_increase_todays_new_card_limit_by() sval = min(new, self.deck.get("extendNew", 10)) smin = -DYN_MAX_SIZE @@ -82,9 +80,7 @@ class CustomStudy(QDialog): rev, self.conf["rev"]["perDay"] - self.deck["revToday"][1] ) revExceeding = min(rev, rev - revUnderLearning) - tit = tr( - TR.CUSTOM_STUDY_REVIEWS_DUE_IN_DECK_OVER_TODAY, val=plus(revExceeding) - ) + tit = tr.custom_study_reviews_due_in_deck_over_today(val=plus(revExceeding)) pre = tr.custom_study_increase_todays_review_limit_by() sval = min(rev, self.deck.get("extendRev", 10)) smin = -DYN_MAX_SIZE diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 26aa542fe..dcac1398c 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -35,7 +35,6 @@ from aqt.qt import * from aqt.sound import av_player from aqt.theme import theme_manager from aqt.utils import ( - TR, HelpPage, KeyboardModifiersPressed, disable_help_button, @@ -957,8 +956,7 @@ class Editor: client.timeout = 30 with client.get(url) as response: if response.status_code != 200: - error_msg = tr( - TR.QT_MISC_UNEXPECTED_RESPONSE_CODE, + error_msg = tr.qt_misc_unexpected_response_code( val=response.status_code, ) return None diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 4e83e611f..2567f6ca0 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -24,7 +24,7 @@ from anki.sync import SyncAuth from anki.utils import intTime, isMac, isWin from aqt import appHelpSite 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 ########################################################################## @@ -516,8 +516,7 @@ create table if not exists profiles with open(p, "w", encoding="utf8") as file: file.write( without_unicode_isolation( - tr( - TR.PROFILES_FOLDER_README, + tr.profiles_folder_readme( link=f"{appHelpSite}files?id=startup-options", ) )