convert card template error to tuple, and report notetype name in error
Older translations will note have the $notetype variable, but that is not an error in Fluent - it would only cause problems if we tried to use the new string on older Anki versions.
This commit is contained in:
parent
7a29d987c4
commit
ba541076aa
@ -18,7 +18,7 @@ card-templates-night-mode = Night Mode
|
||||
# on a mobile device.
|
||||
card-templates-add-mobile-class = Add Mobile Class
|
||||
card-templates-preview-settings = Options
|
||||
card-templates-invalid-template-number = Card template { $number } has a problem.
|
||||
card-templates-invalid-template-number = Card template { $number } in notetype '{ $notetype }' has a problem.
|
||||
card-templates-changes-saved = Changes saved.
|
||||
card-templates-discard-changes = Discard changes?
|
||||
card-templates-add-card-type = Add Card Type...
|
||||
|
@ -21,7 +21,7 @@ pub type Result<T, E = AnkiError> = std::result::Result<T, E>;
|
||||
pub enum AnkiError {
|
||||
InvalidInput(String),
|
||||
TemplateError(String),
|
||||
TemplateSaveError { ordinal: usize },
|
||||
TemplateSaveError(TemplateSaveError),
|
||||
IoError(String),
|
||||
DbError(DbError),
|
||||
NetworkError(NetworkError),
|
||||
@ -60,8 +60,8 @@ impl AnkiError {
|
||||
// already localized
|
||||
info.into()
|
||||
}
|
||||
AnkiError::TemplateSaveError { ordinal } => tr
|
||||
.card_templates_invalid_template_number(ordinal + 1)
|
||||
AnkiError::TemplateSaveError(err) => tr
|
||||
.card_templates_invalid_template_number(err.ordinal + 1, &err.notetype)
|
||||
.into(),
|
||||
AnkiError::DbError(err) => err.localized_description(tr),
|
||||
AnkiError::SearchError(kind) => kind.localized_description(&tr),
|
||||
@ -129,3 +129,9 @@ impl From<regex::Error> for AnkiError {
|
||||
AnkiError::InvalidRegex(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct TemplateSaveError {
|
||||
pub notetype: String,
|
||||
pub ordinal: usize,
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ use crate::{
|
||||
collection::Collection,
|
||||
decks::DeckId,
|
||||
define_newtype,
|
||||
error::{AnkiError, Result},
|
||||
error::{AnkiError, Result, TemplateSaveError},
|
||||
notes::Note,
|
||||
prelude::*,
|
||||
template::{FieldRequirements, ParsedTemplate},
|
||||
@ -250,7 +250,10 @@ impl Notetype {
|
||||
}
|
||||
});
|
||||
if let Some(idx) = invalid_card_idx {
|
||||
return Err(AnkiError::TemplateSaveError { ordinal: idx });
|
||||
return Err(AnkiError::TemplateSaveError(TemplateSaveError {
|
||||
notetype: self.name.clone(),
|
||||
ordinal: idx,
|
||||
}));
|
||||
}
|
||||
let reqs = self.updated_requirements(&parsed_templates);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user