Trim the preset file name like the engine, and list the clash prompt's plural forms for translation (#10640)

This commit is contained in:
aiongg committed 2026-11-01 13:14:09 +00:00
1 parent 586563fc2b
commit af404cfb9f
2 files changed
+28 -5

No files matched your search

@@ -49,12 +49,24 @@ pub(crate) fn intercept(app: &mut PhotocraftApp, held: Held) -> Result<Option<He
if app.ui.dialogs.iter().any(|d| owns(&d.fields)) {
return Err(tl!("Answer the open import question first, then import this file again.").into());
}
let (label, one, other) = if held.what == "gradients" {
("Import Gradients", "The gradient group “{group}” already exists ({n} gradient).", "The gradient group “{group}” already exists ({n} gradients).")
let (label, message) = if held.what == "gradients" {
let text = crate::i18n::trn(
crate::i18n::current(),
n as u64,
"The gradient group “{group}” already exists ({n} gradient).",
"The gradient group “{group}” already exists ({n} gradients).",
);
("Import Gradients", text)
} else {
("Import Brushes", "The brush group “{group}” already has {n} brush of yours.", "The brush group “{group}” already has {n} brushes of yours.")
let text = crate::i18n::trn(
crate::i18n::current(),
n as u64,
"The brush group “{group}” already has {n} brush of yours.",
"The brush group “{group}” already has {n} brushes of yours.",
);
("Import Brushes", text)
};
let message = crate::i18n::fmt(&crate::i18n::trn(crate::i18n::current(), n as u64, one, other), &[("group", &held.stem)]);
let message = crate::i18n::fmt(&message, &[("group", &held.stem)]);
let fields = json!({MARK: true, "__label": label, "message": message, "group": held.stem, "kind": held.what, "choice": "new"});
app.held_preset_import = Some(held);
app.ui.open_dialog(DialogKind::Command, fields.as_object().cloned().unwrap_or_default());
+12 -1
View File
@@ -95,7 +95,12 @@ pub fn open(app: &mut PhotocraftApp, name: &str, bytes: &[u8]) -> Option<Result<
"kys" | "psp" => return Some(crate::kys_import::open_bytes(app, name, bytes).map(|_| ())),
_ => return None,
};
let stem = std::path::Path::new(name).file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or_else(|| tl!("Imported").into());
// Trimmed like the engine trims `group`, so the clash check sees the name the import uses.
let stem = std::path::Path::new(name)
.file_stem()
.map(|s| s.to_string_lossy().trim().to_string())
.filter(|s| !s.is_empty())
.unwrap_or_else(|| tl!("Imported").into());
let mut p = source(name, bytes);
p["group"] = json!(stem);
if what == "brushes" {
@@ -203,6 +208,12 @@ mod tests {
assert_eq!((in_group(&app, "Kit"), in_group(&app, "Kit (2)")), (2, 0));
assert!(app.held_preset_import.is_none());
// A file name with a trailing space (`Kit .abr`) names the same group.
open(&mut app, "Kit .abr", &abr).unwrap().unwrap();
let id = prompt(&app).expect("the prompt is open for the trimmed name");
crate::dialogs::cancel(&mut app, id).unwrap();
assert_eq!(in_group(&app, "Kit (2)"), 0);
// The default answer imports beside it.
open(&mut app, "Kit.abr", &abr).unwrap().unwrap();
let id = prompt(&app).expect("the prompt is open");