mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Humanize file size error messages (#14398)
The file size error messages for max_image_size_kb and max_attachment_size_kb are shown to the user in the KB format, regardless of how large the limit is. Since we are going to support uploading much larger files soon, this KB-based limit soon becomes unfriendly to the end user. For example, if the max attachment size is set to 512000 KB, this is what the user sees: > Sorry, the file you are trying to upload is too big (maximum size is 512000KB) This makes the user do math. In almost all file explorers that a regular user would be familiar width, the file size is shown in a format based on the maximum increment (e.g. KB, MB, GB). This commit changes the behaviour to output a humanized file size instead of the raw KB. For the above example, it would now say: > Sorry, the file you are trying to upload is too big (maximum size is 512 MB) This humanization also handles decimals, e.g. 1536KB = 1.5 MB
This commit is contained in:
@@ -142,7 +142,15 @@ class CookedPostProcessor
|
||||
span = create_span_node("url", url)
|
||||
a.add_child(span)
|
||||
span.add_previous_sibling(create_icon_node("far-image"))
|
||||
span.add_next_sibling(create_span_node("help", I18n.t("upload.placeholders.too_large", max_size_kb: SiteSetting.max_image_size_kb)))
|
||||
span.add_next_sibling(
|
||||
create_span_node(
|
||||
"help",
|
||||
I18n.t(
|
||||
"upload.placeholders.too_large_humanized",
|
||||
max_size: ActiveSupport::NumberHelper.number_to_human_size(SiteSetting.max_image_size_kb.kilobytes)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
# Only if the image is already linked
|
||||
if is_hyperlinked
|
||||
|
||||
Reference in New Issue
Block a user