Localise RenameDeckError

This commit is contained in:
RumovZ 2021-02-24 13:57:44 +01:00
parent c9992e395f
commit 8e43b29816
5 changed files with 19 additions and 8 deletions

View File

@ -1,3 +1,5 @@
errors-invalid-deck-name = Invalid deck name: { $reason }
errors-invalid-input-empty = Invalid input.
errors-invalid-input-details = Invalid input: { $details }
errors-parse-number-fail = A number was invalid or out of range.
errors-reason-filtered-parent = Filtered decks cannot be parent decks.

View File

@ -21,8 +21,8 @@ from aqt.utils import (
getOnlyText,
openLink,
shortcut,
show_rename_deck_error,
showInfo,
showWarning,
tr,
)
@ -272,8 +272,8 @@ class DeckBrowser:
try:
self.mw.col.decks.rename(deck, newName)
gui_hooks.sidebar_should_refresh_decks()
except DeckRenameError as e:
showWarning(e.description)
except DeckRenameError as err:
show_rename_deck_error(err)
return
self.show()

View File

@ -19,6 +19,7 @@ from aqt.utils import (
restoreGeom,
saveGeom,
show_invalid_search_error,
show_rename_deck_error,
showWarning,
tr,
)
@ -244,7 +245,7 @@ class DeckConf(QDialog):
except InvalidInput as err:
show_invalid_search_error(err)
except DeckRenameError as err:
showWarning(err.description)
show_rename_deck_error(err)
else:
if not self.mw.col.sched.rebuild_filtered_deck(self.deck["id"]):
if askUser(tr(TR.DECKS_THE_PROVIDED_SEARCH_DID_NOT_MATCH)):

View File

@ -23,8 +23,8 @@ from aqt.utils import (
askUser,
getOnlyText,
show_invalid_search_error,
show_rename_deck_error,
showInfo,
showWarning,
tr,
)
@ -993,8 +993,8 @@ class SidebarTreeView(QTreeView):
self.mw.checkpoint(tr(TR.ACTIONS_RENAME_DECK))
try:
self.mw.col.decks.rename(deck, new_name)
except DeckRenameError as e:
showWarning(e.description)
except DeckRenameError as err:
show_rename_deck_error(err)
return
self.refresh()
self.mw.deckBrowser.refresh()

View File

@ -36,7 +36,7 @@ from PyQt5.QtWidgets import (
import anki
import aqt
from anki import Collection
from anki.errors import InvalidInput
from anki.errors import DeckRenameError, InvalidInput
from anki.lang import TR # pylint: disable=unused-import
from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild
from aqt.qt import *
@ -146,6 +146,14 @@ def show_invalid_search_error(err: Exception) -> None:
showWarning(text)
def show_rename_deck_error(err: DeckRenameError) -> None:
if err.description == "deck was filtered":
reason = tr(TR.ERRORS_REASON_FILTERED_PARENT)
else:
reason = "unknown reason."
showWarning(tr(TR.ERRORS_INVALID_DECK_NAME, reason=reason))
def showInfo(
text: str,
parent: Union[Literal[False], QDialog] = False,