summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-09-23 15:57:18 +0200
committerGitHub <noreply@github.com>2019-09-23 15:57:18 +0200
commited18e3f195a09d1d6b530eee1c6db3183c9d1f42 (patch)
tree4ccb891e3842337ce60a36565c8865debbad1cbd /core
parentf1146c261d7c6f09cf27828ea2d719b82bf0fd09 (diff)
parenta51e8b1ff0af4f001844c6d92e920da6a4db79d9 (diff)
Merge pull request #32273 from Calinou/humanize-size-fix-i18n
Fix i18n in `String::humanize_size()`
Diffstat (limited to 'core')
-rw-r--r--core/ustring.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 237e86aaf1..dee554716f 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3285,18 +3285,26 @@ static int _humanize_digits(int p_num) {
String String::humanize_size(size_t p_size) {
uint64_t _div = 1;
- static const char *prefix[] = { " B", " KiB", " MiB", " GiB", " TiB", " PiB", " EiB", "" };
+ Vector<String> prefixes;
+ prefixes.push_back(RTR("B"));
+ prefixes.push_back(RTR("KiB"));
+ prefixes.push_back(RTR("MiB"));
+ prefixes.push_back(RTR("GiB"));
+ prefixes.push_back(RTR("TiB"));
+ prefixes.push_back(RTR("PiB"));
+ prefixes.push_back(RTR("EiB"));
+
int prefix_idx = 0;
- while (p_size > (_div * 1024) && prefix[prefix_idx][0]) {
+ while (prefix_idx < prefixes.size() && p_size > (_div * 1024)) {
_div *= 1024;
prefix_idx++;
}
- int digits = prefix_idx > 0 ? _humanize_digits(p_size / _div) : 0;
- double divisor = prefix_idx > 0 ? _div : 1;
+ const int digits = prefix_idx > 0 ? _humanize_digits(p_size / _div) : 0;
+ const double divisor = prefix_idx > 0 ? _div : 1;
- return String::num(p_size / divisor).pad_decimals(digits) + RTR(prefix[prefix_idx]);
+ return String::num(p_size / divisor).pad_decimals(digits) + " " + prefixes[prefix_idx];
}
bool String::is_abs_path() const {