From 43f5d13ed6b19337f1bf041c043050a1bffa79ad Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 27 Feb 2020 20:32:57 +1000 Subject: [PATCH] migrate strings with trailing newlines to fluent --- pylib/anki/collection.py | 8 +++++--- qt/aqt/addons.py | 15 ++++++--------- qt/aqt/errors.py | 4 ++-- qt/aqt/importing.py | 8 +++++--- qt/aqt/main.py | 13 +++---------- qt/aqt/profiles.py | 15 ++++----------- qt/ftl/addons.ftl | 6 ++++++ qt/ftl/errors.ftl | 5 ++++- qt/ftl/profiles.ftl | 6 ++++++ rslib/ftl/empty-cards.ftl | 3 +++ rslib/ftl/importing.ftl | 1 + 11 files changed, 45 insertions(+), 39 deletions(-) create mode 100644 qt/ftl/addons.ftl create mode 100644 qt/ftl/profiles.ftl create mode 100644 rslib/ftl/empty-cards.ftl create mode 100644 rslib/ftl/importing.ftl diff --git a/pylib/anki/collection.py b/pylib/anki/collection.py index 34946900b..46c8fe209 100644 --- a/pylib/anki/collection.py +++ b/pylib/anki/collection.py @@ -26,7 +26,7 @@ from anki.lang import _, ngettext from anki.media import MediaManager from anki.models import ModelManager, NoteType, Template from anki.notes import Note -from anki.rsbackend import RustBackend +from anki.rsbackend import TR, RustBackend from anki.sched import Scheduler as V1Scheduler from anki.schedv2 import Scheduler as V2Scheduler from anki.tags import TagManager @@ -580,9 +580,11 @@ select group_concat(ord+1), count(), flds from cards c, notes n where c.nid = n.id and c.id in %s group by nid""" % ids2str(cids) ): - rep += _("Empty card numbers: %(c)s\nFields: %(f)s\n\n") % dict( - c=ords, f=flds.replace("\x1f", " / ") + rep += self.tr( + TR.EMPTY_CARDS_CARD_LINE, + **{"card-numbers": ords, "fields": flds.replace("\x1f", " / ")}, ) + rep += "\n\n" return rep # Field checksums and sorting fields diff --git a/qt/aqt/addons.py b/qt/aqt/addons.py index 08dbc673c..41c74a2c4 100644 --- a/qt/aqt/addons.py +++ b/qt/aqt/addons.py @@ -28,6 +28,7 @@ from anki.httpclient import HttpClient from anki.lang import _, ngettext from aqt.qt import * from aqt.utils import ( + TR, askUser, getFile, isWin, @@ -40,6 +41,7 @@ from aqt.utils import ( showInfo, showWarning, tooltip, + tr, ) @@ -205,16 +207,11 @@ class AddonManager: __import__(addon.dir_name) except: showWarning( - _( - """\ -An add-on you installed failed to load. If problems persist, please \ -go to the Tools>Add-ons menu, and disable or delete the add-on. - -When loading '%(name)s': -%(traceback)s -""" + tr( + TR.ADDONS_FAILED_TO_LOAD, + name=addon.human_name(), + traceback=traceback.format_exc(), ) - % dict(name=addon.human_name(), traceback=traceback.format_exc()) ) def onAddonsDialog(self): diff --git a/qt/aqt/errors.py b/qt/aqt/errors.py index 1bbc3b1da..d099537c1 100644 --- a/qt/aqt/errors.py +++ b/qt/aqt/errors.py @@ -128,7 +128,7 @@ your system's temporary folder may be incorrect.""" addons = [ mw.addonManager.addonName(i) for i in dict.fromkeys(reversed(matches)) ] - txt = _("""Add-ons possibly involved: {}\n""") # highlight importance of first add-on: addons[0] = "{}".format(addons[0]) - return txt.format(", ".join(addons)) + addons_str = ", ".join(addons) + return tr(TR.ADDONS_POSSIBLY_INVOLVED, addons=addons_str) + "\n" diff --git a/qt/aqt/importing.py b/qt/aqt/importing.py index 2c649e7c5..5c679a28e 100644 --- a/qt/aqt/importing.py +++ b/qt/aqt/importing.py @@ -18,6 +18,7 @@ from anki.lang import _, ngettext from aqt import AnkiQt, gui_hooks from aqt.qt import * from aqt.utils import ( + TR, askUser, getFile, getOnlyText, @@ -26,6 +27,7 @@ from aqt.utils import ( showText, showWarning, tooltip, + tr, ) @@ -196,7 +198,7 @@ you can enter it here. Use \\t to represent tab.""" showUnicodeWarning() return except Exception as e: - msg = _("Import failed.\n") + msg = tr(TR.IMPORTING_FAILED_DEBUG_INFO) + "\n" err = repr(str(e)) if "1-character string" in err: msg += err @@ -360,7 +362,7 @@ def importFile(mw, file): if msg == "'unknownFormat'": showWarning(_("Unknown file format.")) else: - msg = _("Import failed. Debugging info:\n") + msg = tr(TR.IMPORTING_FAILED_DEBUG_INFO) + "\n" msg += str(traceback.format_exc()) showText(msg) return @@ -405,7 +407,7 @@ Unable to import from a read-only file.""" ) ) else: - msg = _("Import failed.\n") + msg = tr(TR.IMPORTING_FAILED_DEBUG_INFO) + "\n" msg += str(traceback.format_exc()) showText(msg) else: diff --git a/qt/aqt/main.py b/qt/aqt/main.py index bfd066216..79ef51bf2 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -42,6 +42,7 @@ from aqt.qt import sip from aqt.taskman import TaskManager from aqt.theme import theme_manager from aqt.utils import ( + TR, askUser, checkInvalidFilename, getFile, @@ -55,6 +56,7 @@ from aqt.utils import ( showText, showWarning, tooltip, + tr, ) install_pylib_legacy() @@ -439,16 +441,7 @@ close the profile or restart Anki.""" return self._loadCollection() except Exception as e: showWarning( - _( - """\ -Anki was unable to open your collection file. If problems persist after \ -restarting your computer, please use the Open Backup button in the profile \ -manager. - -Debug info: -""" - ) - + traceback.format_exc() + tr(TR.ERRORS_UNABLE_OPEN_COLLECTION) + "\n" + traceback.format_exc() ) # clean up open collection if possible if self.col: diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index d6f63d425..ccef2f1b5 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -19,11 +19,11 @@ import anki.lang import aqt.forms import aqt.sound from anki.db import DB -from anki.lang import _ +from anki.lang import _, without_unicode_isolation from anki.utils import intTime, isMac, isWin from aqt import appHelpSite from aqt.qt import * -from aqt.utils import locale_dir, showWarning +from aqt.utils import TR, locale_dir, showWarning, tr metaConf = dict( ver=0, @@ -375,16 +375,9 @@ create table if not exists profiles self.create(_("User 1")) p = os.path.join(self.base, "README.txt") open(p, "w", encoding="utf8").write( - _( - """\ -This folder stores all of your Anki data in a single location, -to make backups easy. To tell Anki to use a different location, -please see: - -%s -""" + without_unicode_isolation( + tr(TR.PROFILES_FOLDER_README, link=appHelpSite + "#startupopts") ) - % (appHelpSite + "#startupopts") ) # Default language diff --git a/qt/ftl/addons.ftl b/qt/ftl/addons.ftl new file mode 100644 index 000000000..d59c68354 --- /dev/null +++ b/qt/ftl/addons.ftl @@ -0,0 +1,6 @@ +addons-possibly-involved = Add-ons possibly involved: { $addons } +addons-failed-to-load = + An add-on you installed failed to load. If problems persist, please go to the Tools>Add-ons menu, and disable or delete the add-on. + + When loading '{$name}': + {$traceback} diff --git a/qt/ftl/errors.ftl b/qt/ftl/errors.ftl index 86316d3d0..8f7c86805 100644 --- a/qt/ftl/errors.ftl +++ b/qt/ftl/errors.ftl @@ -36,4 +36,7 @@ errors-accessing-db = - Your hard disk may have errors. It's a good idea to run Tools>Check Database to ensure your collection is not corrupt. - +errors-unable-open-collection = + Anki was unable to open your collection file. If problems persist after restarting your computer, please use the Open Backup button in the profile manager. + + Debug info: diff --git a/qt/ftl/profiles.ftl b/qt/ftl/profiles.ftl new file mode 100644 index 000000000..f9114a58e --- /dev/null +++ b/qt/ftl/profiles.ftl @@ -0,0 +1,6 @@ +profiles-folder-readme = + This folder stores all of your Anki data in a single location, + to make backups easy. To tell Anki to use a different location, + please see: + + {$link} diff --git a/rslib/ftl/empty-cards.ftl b/rslib/ftl/empty-cards.ftl new file mode 100644 index 000000000..2cc9758ac --- /dev/null +++ b/rslib/ftl/empty-cards.ftl @@ -0,0 +1,3 @@ +empty-cards-card-line = + Empty card numbers: {$card-numbers} + Fields: {$fields} diff --git a/rslib/ftl/importing.ftl b/rslib/ftl/importing.ftl new file mode 100644 index 000000000..e2917506e --- /dev/null +++ b/rslib/ftl/importing.ftl @@ -0,0 +1 @@ +importing-failed-debug-info = Import failed. Debugging info: