about summary refs log tree commit diff
path: root/app/helpers
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-07-07 21:13:08 +0200
committerGitHub <noreply@github.com>2021-07-07 21:13:08 +0200
commite2844b7e58e1ebdf666c5fecc97a75620da7bddf (patch)
treecba236467d1ebd6ea655878971841473b8daae44 /app/helpers
parent225c6582d17b8e744c279e254d4e96062afb7a3b (diff)
Change number_to_human calls to always use 3-digits precision (#16469)
Fixes #16435
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/accounts_helper.rb6
-rw-r--r--app/helpers/application_helper.rb11
2 files changed, 14 insertions, 3 deletions
diff --git a/app/helpers/accounts_helper.rb b/app/helpers/accounts_helper.rb
index 134217734..db3da2b05 100644
--- a/app/helpers/accounts_helper.rb
+++ b/app/helpers/accounts_helper.rb
@@ -80,17 +80,17 @@ module AccountsHelper
   def account_description(account)
     prepend_str = [
       [
-        number_to_human(account.statuses_count, strip_insignificant_zeros: true),
+        number_to_human(account.statuses_count, precision: 3, strip_insignificant_zeros: true),
         I18n.t('accounts.posts', count: account.statuses_count),
       ].join(' '),
 
       [
-        number_to_human(account.following_count, strip_insignificant_zeros: true),
+        number_to_human(account.following_count, precision: 3, strip_insignificant_zeros: true),
         I18n.t('accounts.following', count: account.following_count),
       ].join(' '),
 
       [
-        number_to_human(account.followers_count, strip_insignificant_zeros: true),
+        number_to_human(account.followers_count, precision: 3, strip_insignificant_zeros: true),
         I18n.t('accounts.followers', count: account.followers_count),
       ].join(' '),
     ].join(', ')
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index bf5742d34..a39e8e5bf 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -14,6 +14,17 @@ module ApplicationHelper
     ku
   ).freeze
 
+  def friendly_number_to_human(number, **options)
+    # By default, the number of precision digits used by number_to_human
+    # is looked up from the locales definition, and rails-i18n comes with
+    # values that don't seem to make much sense for many languages, so
+    # override these values with a default of 3 digits of precision.
+    options[:precision] = 3
+    options[:strip_insignificant_zeros] = true
+
+    number_to_human(number, **options)
+  end
+
   def active_nav_class(*paths)
     paths.any? { |path| current_page?(path) } ? 'active' : ''
   end