diff --git a/app/assets/javascripts/discourse/components/utilities.js b/app/assets/javascripts/discourse/components/utilities.js
index 9b010113c46..567fea46997 100644
--- a/app/assets/javascripts/discourse/components/utilities.js
+++ b/app/assets/javascripts/discourse/components/utilities.js
@@ -224,7 +224,7 @@ Discourse.Utilities = {
if (this.isAnImage(upload.original_filename)) {
return '
';
} else {
- return '' + upload.original_filename + '';
+ return '' + upload.original_filename + '(' + I18n.toHumanSize(upload.filesize) + ')';
}
},
diff --git a/app/assets/javascripts/discourse/helpers/i18n_helpers.js b/app/assets/javascripts/discourse/helpers/i18n_helpers.js
index b6b7af10faf..4a9433514bb 100644
--- a/app/assets/javascripts/discourse/helpers/i18n_helpers.js
+++ b/app/assets/javascripts/discourse/helpers/i18n_helpers.js
@@ -2,13 +2,19 @@
We always prefix with "js." to select exactly what we want passed
through to the front end.
**/
-
var oldI18nlookup = I18n.lookup;
-I18n.lookup = function() {
- // jshint doesn't like when we change the arguments directly...
- var args = arguments;
- if (args.length > 0) { args[0] = "js." + args[0]; }
- return oldI18nlookup.apply(this, args);
+I18n.lookup = function(scope, options) {
+ return oldI18nlookup.apply(this, ["js." + scope, options]);
+};
+
+/**
+ Default format for storage units
+**/
+var oldI18ntoHumanSize = I18n.toHumanSize;
+I18n.toHumanSize = function(number, options) {
+ options = options || {};
+ options.format = I18n.t("number.human.storage_units.format");
+ return oldI18ntoHumanSize.apply(this, [number, options]);
};
/**
diff --git a/app/serializers/upload_serializer.rb b/app/serializers/upload_serializer.rb
index 9a0a7753b89..1d3812e200a 100644
--- a/app/serializers/upload_serializer.rb
+++ b/app/serializers/upload_serializer.rb
@@ -1,5 +1,5 @@
class UploadSerializer < ApplicationSerializer
- attributes :url, :original_filename, :width, :height
+ attributes :url, :original_filename, :filesize, :width, :height
end
diff --git a/config/locales/client.cs.yml b/config/locales/client.cs.yml
index b55cb2e5983..ef010664531 100644
--- a/config/locales/client.cs.yml
+++ b/config/locales/client.cs.yml
@@ -7,6 +7,16 @@
cs:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte: B
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
dates:
tiny:
half_a_minute: "< 1m"
diff --git a/config/locales/client.da.yml b/config/locales/client.da.yml
index 6421b039d29..6fc9a4aaf97 100644
--- a/config/locales/client.da.yml
+++ b/config/locales/client.da.yml
@@ -6,6 +6,18 @@
da:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
share:
topic: 'del et link til dette emne'
post: 'del et link til dette indlæg'
diff --git a/config/locales/client.de.yml b/config/locales/client.de.yml
index 9d01f04e164..32ca6ca00a6 100644
--- a/config/locales/client.de.yml
+++ b/config/locales/client.de.yml
@@ -7,6 +7,18 @@
de:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
dates:
short_date_no_year: "D MMM"
short_date: "D. MMM YYYY"
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 5f2e1769102..b294740f888 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -7,6 +7,18 @@
en:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
dates:
tiny:
half_a_minute: "< 1m"
diff --git a/config/locales/client.es.yml b/config/locales/client.es.yml
index 1b0d596062d..cf1147e9423 100644
--- a/config/locales/client.es.yml
+++ b/config/locales/client.es.yml
@@ -8,6 +8,18 @@
es:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
dates:
tiny:
half_a_minute: "< 1m"
diff --git a/config/locales/client.fr.yml b/config/locales/client.fr.yml
index 030b2134b37..bebe7881fef 100644
--- a/config/locales/client.fr.yml
+++ b/config/locales/client.fr.yml
@@ -11,6 +11,18 @@
fr:
js:
+ number:
+ human:
+ storage_units:
+ format: "%n %u"
+ units:
+ byte:
+ one: "octet"
+ other: "octets"
+ kb: "ko"
+ mb: "Mo"
+ gb: "Go"
+ tb: "To"
dates:
tiny:
half_a_minute: "< 1m"
diff --git a/config/locales/client.id.yml b/config/locales/client.id.yml
index 25943e3e5a4..f14e3521050 100644
--- a/config/locales/client.id.yml
+++ b/config/locales/client.id.yml
@@ -8,6 +8,18 @@
id:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Byte
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
share:
topic: "Bagikan tautan ke topik ini"
post: "Bagikan tautan ke muatan ini"
diff --git a/config/locales/client.it.yml b/config/locales/client.it.yml
index 0301373d690..cb9d18fd87d 100644
--- a/config/locales/client.it.yml
+++ b/config/locales/client.it.yml
@@ -7,6 +7,18 @@
it:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Byte
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
share:
topic: 'condividi un link a questo topic'
post: 'condividi un link a questo post'
diff --git a/config/locales/client.nb_NO.yml b/config/locales/client.nb_NO.yml
index 38e14f79e09..193c48e3896 100644
--- a/config/locales/client.nb_NO.yml
+++ b/config/locales/client.nb_NO.yml
@@ -7,6 +7,18 @@
nb_NO:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: kB
+ mb: MB
+ tb: TB
share:
topic: 'del en link til dette emnet'
post: 'del en link til dette innlegget'
diff --git a/config/locales/client.nl.yml b/config/locales/client.nl.yml
index 68c545a8824..574a9f64b0a 100644
--- a/config/locales/client.nl.yml
+++ b/config/locales/client.nl.yml
@@ -12,6 +12,18 @@
nl:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
dates:
tiny:
half_a_minute: "< 1m"
diff --git a/config/locales/client.pt.yml b/config/locales/client.pt.yml
index 6e8da9d3e0f..9315f73c1f8 100644
--- a/config/locales/client.pt.yml
+++ b/config/locales/client.pt.yml
@@ -8,6 +8,18 @@
pt:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
share:
topic: 'partilhe um link para este tópico'
post: 'partilhe um link para esta mensagem'
diff --git a/config/locales/client.ru.yml b/config/locales/client.ru.yml
index 26d969c8c9e..6add65a8eb2 100644
--- a/config/locales/client.ru.yml
+++ b/config/locales/client.ru.yml
@@ -10,6 +10,20 @@
ru:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ few: байта
+ many: байт
+ one: байт
+ other: байта
+ gb: ГБ
+ kb: КБ
+ mb: МБ
+ tb: ТБ
dates:
tiny:
half_a_minute: '< 1мин'
diff --git a/config/locales/client.sv.yml b/config/locales/client.sv.yml
index c6e6e960696..332ab576d76 100644
--- a/config/locales/client.sv.yml
+++ b/config/locales/client.sv.yml
@@ -8,6 +8,18 @@
sv:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
share:
topic: 'dela en länk till denna tråd'
post: 'dela en länk till denna tråd'
diff --git a/config/locales/client.zh_CN.yml b/config/locales/client.zh_CN.yml
index d7e1aa1bc77..aa4bd13c8da 100644
--- a/config/locales/client.zh_CN.yml
+++ b/config/locales/client.zh_CN.yml
@@ -7,6 +7,18 @@
zh_CN:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
dates:
short_date_no_year: "D MMM"
short_date: "D MMM, YYYY"
diff --git a/config/locales/client.zh_TW.yml b/config/locales/client.zh_TW.yml
index 1b8308a9692..a81583abbd7 100644
--- a/config/locales/client.zh_TW.yml
+++ b/config/locales/client.zh_TW.yml
@@ -7,6 +7,18 @@
zh_TW:
js:
+ number:
+ human:
+ storage_units:
+ format: ! '%n %u'
+ units:
+ byte:
+ one: Byte
+ other: Bytes
+ gb: GB
+ kb: KB
+ mb: MB
+ tb: TB
share:
topic: '分享一個到本主題的鏈接'
post: '分享一個到本帖的鏈接'
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index 84db9207449..211272f0b2c 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -25,14 +25,10 @@ class CookedPostProcessor
attachments.each do |attachment|
href = attachment['href']
attachment['href'] = relative_to_absolute(href)
+ # update reverse index
if upload = Upload.get_from_url(href)
- # update reverse index
associate_to_post(upload)
- # append the size
- append_human_size!(attachment, upload)
end
- # mark as dirty
- @dirty = true
end
end
@@ -234,13 +230,6 @@ class CookedPostProcessor
end
end
- def append_human_size!(attachment, upload)
- size = Nokogiri::XML::Node.new("span", @doc)
- size["class"] = "size"
- size.content = "(#{number_to_human_size(upload.filesize)})"
- attachment.add_next_sibling(size)
- end
-
def dirty?
@dirty
end
diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb
index e216c8b6c4b..e33994dbcf4 100644
--- a/spec/components/cooked_post_processor_spec.rb
+++ b/spec/components/cooked_post_processor_spec.rb
@@ -34,8 +34,6 @@ describe CookedPostProcessor do
cpp.html.should =~ /#{LocalStore.base_url}/
# ensure name is present
cpp.html.should =~ /archive.zip/
- # ensure size is present
- cpp.html.should =~ /\(1.21 KB\)<\/span>/
# dirty
cpp.should be_dirty
# keeps the reverse index up to date
@@ -79,8 +77,6 @@ describe CookedPostProcessor do
cpp.post_process_images
# ensures absolute urls on uploaded images
cpp.html.should =~ /#{LocalStore.base_url}/
- # dirty
- cpp.should be_dirty
# keeps the reverse index up to date
post.uploads.reload
post.uploads.count.should == 1
diff --git a/test/javascripts/components/utilities_test.js b/test/javascripts/components/utilities_test.js
index 416b2fde2bf..08a74179b52 100644
--- a/test/javascripts/components/utilities_test.js
+++ b/test/javascripts/components/utilities_test.js
@@ -88,6 +88,7 @@ test("isAuthorizedUpload", function() {
var getUploadMarkdown = function(filename) {
return utils.getUploadMarkdown({
original_filename: filename,
+ filesize: 42,
width: 100,
height: 200,
url: "/upload/123/abcdef.ext"
@@ -96,7 +97,7 @@ var getUploadMarkdown = function(filename) {
test("getUploadMarkdown", function() {
ok(getUploadMarkdown("lolcat.gif") === '
');
- ok(getUploadMarkdown("important.txt") === 'important.txt');
+ ok(getUploadMarkdown("important.txt") === 'important.txt(42 Bytes)');
});
test("isAnImage", function() {