From 1a3940c16d24a207a5de7af5dd099a57bb190180 Mon Sep 17 00:00:00 2001 From: GenevensiS <66968533+G-e-n-e-v-e-n-s-i-S@users.noreply.github.com> Date: Fri, 11 Apr 2025 03:25:21 +0200 Subject: [PATCH] localization pattern --- data/en.mse-locale/locale | 7 +++++++ doc/function/import_image.txt | 2 +- src/gfx/generated_image.cpp | 28 +++++++++++----------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/data/en.mse-locale/locale b/data/en.mse-locale/locale index dbe12600..e9f42fa5 100644 --- a/data/en.mse-locale/locale +++ b/data/en.mse-locale/locale @@ -803,6 +803,13 @@ error: To resolve this, add: depends on: %s %s + # Image import + import not found: File not found: '%s' + can't import image without set: Must first save or load a set file before importing file: '%s' + can't create file stream: Failed to create file stream: '%s' + can't write image to set: Failed to write image to set: '%s' + can't import image: Failed to import image: '%s' + # Script stuff has no member: %s has no member '%s' can't convert: Can't convert from %s to %s diff --git a/doc/function/import_image.txt b/doc/function/import_image.txt index f1eedab7..874fab5a 100644 --- a/doc/function/import_image.txt +++ b/doc/function/import_image.txt @@ -10,4 +10,4 @@ Load an image from outside the data folder. Intended for use from the CLI. | @input@ [[type:string]] Full path of the image to load --Examples-- -> import_image("D:/Art/Ajani.png") +> new_card([image: import_image("D:/Art/Ajani.png"), card_color: "green"]) diff --git a/src/gfx/generated_image.cpp b/src/gfx/generated_image.cpp index 8c4686f2..d77daaa6 100644 --- a/src/gfx/generated_image.cpp +++ b/src/gfx/generated_image.cpp @@ -521,34 +521,28 @@ bool ImageValueToImage::operator == (const GeneratedImage& that) const { Image ExternalImage::generate(const Options& opt) const { wxFileName fname(filepath, wxPATH_UNIX); - - // has a pre-existing .mse-set file been loaded? - if (opt.local_package->needSaveAs()) - throw ScriptError(_("Cannot import an image without first saving/loading a set file.")); + String filePathString = fname.GetAbsolutePath(); + + // has a pre-existing .mse-set file been loaded? + if (opt.local_package->needSaveAs()) throw ScriptError(_ERROR_1_("can't import image without set", filePathString)); // does the file pointed to by filepath exist? - if (!fname.FileExists()) { - String filePathString = fname.GetAbsolutePath().ToStdString(); - throw ScriptError(format_string(_("The file '%s' was not found."),filePathString)); - } + if (!fname.FileExists()) throw ScriptError(_ERROR_1_("import not found", filePathString)); String fileExt = fname.GetExt(); wxBitmapType bitmapType; - if (fileExt == _("png")) - bitmapType = wxBITMAP_TYPE_PNG; - else if (fileExt == _("jpg")) - bitmapType = wxBITMAP_TYPE_JPEG; - else - bitmapType = wxBITMAP_TYPE_BMP; + if (fileExt == _("png")) bitmapType = wxBITMAP_TYPE_PNG; + else if (fileExt == _("jpg") || fileExt == _("jpeg")) bitmapType = wxBITMAP_TYPE_JPEG; + else bitmapType = wxBITMAP_TYPE_BMP; // does the file exist in the package? String fileNameNoExtension = fname.GetName(); if (!opt.local_package->existsIn(fileNameNoExtension)) { auto outStream = opt.local_package->openOut(fileNameNoExtension); wxFileInputStream inStream = wxFileInputStream(filepath.ToStdString()); - if (!inStream.IsOk()) throw ScriptError(_("Failed to create file stream.")); + if (!inStream.IsOk()) throw ScriptError(_ERROR_1_("can't create file stream", filePathString)); outStream->Write(inStream); - if (!outStream->IsOk()) throw ScriptError(_("Failed to write image to set.")); + if (!outStream->IsOk()) throw ScriptError(_ERROR_1_("can't write image to set", filePathString)); outStream->Close(); } @@ -558,7 +552,7 @@ Image ExternalImage::generate(const Options& opt) const { auto imageInputStream = opt.local_package->openIn(fileNameNoExtension); Image img(*imageInputStream.get(), bitmapType); - if (!img.IsOk()) throw ScriptError(_("The image could not be created.")); + if (!img.IsOk()) throw ScriptError(_ERROR_1_("can't import image", filePathString)); return img; }