@wordpress/upload-media
Version:
Core media upload logic.
102 lines (101 loc) • 3.09 kB
JavaScript
// packages/upload-media/src/error-messages.ts
import { __, sprintf } from "@wordpress/i18n";
import { ErrorCode } from "./upload-error.mjs";
function getErrorMessage(code, fileName) {
const messages = {
[]: {
title: __("Empty file"),
description: sprintf(
/* translators: %s: file name */
__('"%s" is empty.'),
fileName
),
action: __("Please choose a different file.")
},
[]: {
title: __("File too large"),
description: sprintf(
/* translators: %s: file name */
__('"%s" exceeds the maximum upload size.'),
fileName
),
action: __("Please reduce the file size and try again.")
},
[]: {
title: __("Unsupported file type"),
description: sprintf(
/* translators: %s: file name */
__('"%s" is not a supported file type.'),
fileName
),
action: __("Please upload a different file format.")
},
[]: {
title: __("File type not allowed"),
description: sprintf(
/* translators: %s: file name */
__('You are not allowed to upload "%s".'),
fileName
),
action: __("Please contact your site administrator.")
},
[]: {
title: __("HEIC decode failed"),
description: sprintf(
/* translators: %s: file name */
__('Failed to decode HEIC file "%s".'),
fileName
),
action: __("Try converting the image to JPEG or PNG first.")
},
[]: {
title: __("Image processing failed"),
description: sprintf(
/* translators: %s: file name */
__('Failed to process "%s".'),
fileName
),
action: __("The image may be corrupted. Try a different file.")
},
[]: {
title: __("Image rotation failed"),
description: sprintf(
/* translators: %s: file name */
__('Failed to rotate "%s".'),
fileName
),
action: __("The image may be corrupted. Try a different file.")
},
[]: {
title: __("Media processing failed"),
description: sprintf(
/* translators: %s: file name */
__('Failed to convert "%s" to the target format.'),
fileName
),
action: __("The file may be corrupted. Try a different file.")
},
[]: {
title: __("Upload failed"),
description: sprintf(
/* translators: %s: file name */
__('Failed to upload "%s".'),
fileName
),
action: __("Please try again.")
}
};
return messages[code] || {
title: __("Upload failed"),
description: sprintf(
/* translators: %s: file name */
__('Failed to upload "%s".'),
fileName
),
action: __("Please try again.")
};
}
export {
getErrorMessage
};
//# sourceMappingURL=error-messages.mjs.map