localization pattern

This commit is contained in:
GenevensiS
2025-04-11 03:25:21 +02:00
parent cdfec5d00c
commit 1a3940c16d
3 changed files with 19 additions and 18 deletions
+7
View File
@@ -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
+1 -1
View File
@@ -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"])
+11 -17
View File
@@ -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;
}