]> source.dussan.org Git - redmine.git/commitdiff
Support localized decimal separators for hours in the web UI (#21677).
authorGo MAEDA <maeda@farend.jp>
Thu, 4 Jan 2024 07:01:09 +0000 (07:01 +0000)
committerGo MAEDA <maeda@farend.jp>
Thu, 4 Jan 2024 07:01:09 +0000 (07:01 +0000)
Patch by Go MAEDA (@maeda).

git-svn-id: https://svn.redmine.org/redmine/trunk@22593 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
lib/redmine/i18n.rb
test/helpers/application_helper_test.rb

index dcf1da35b76a97aebe5592907946904a9e6ce7e8..a82163b76a89d9acf045822779bb1c6608242020 100644 (file)
@@ -684,7 +684,7 @@ module ApplicationHelper
 
   def html_hours(text)
     text.gsub(
-      %r{(\d+)([\.:])(\d+)},
+      %r{(\d+)([\.,:])(\d+)},
       '<span class="hours hours-int">\1</span><span class="hours hours-dec">\2\3</span>'
     ).html_safe
   end
index dab4868932ab477baf71c756aa8c24c037716a63..6c4d2aad75d783a47b0e5770012f67829070072d 100644 (file)
@@ -21,6 +21,8 @@ require 'redmine'
 
 module Redmine
   module I18n
+    include ActionView::Helpers::NumberHelper
+
     def self.included(base)
       base.extend Redmine::I18n
     end
@@ -95,7 +97,7 @@ module Redmine
         m = ((hours - h) * 60).round
         "%d:%02d" % [h, m]
       else
-        "%.2f" % hours.to_f
+        number_with_delimiter(sprintf('%.2f', hours.to_f), delimiter: nil)
       end
     end
 
index 8dccb8b7eaf65d022c708f8e132e2ecfd2df5d6a..82b1c32782502f0261fc07c3221e33266dd4652d 100644 (file)
@@ -2171,6 +2171,17 @@ class ApplicationHelperTest < Redmine::HelperTest
     end
   end
 
+  def test_format_hours_should_use_locale_decimal_separator
+    to_test = {'en' => '0.75', 'de' => '0,75'}
+    with_settings :timespan_format => 'decimal' do
+      to_test.each do |locale, expected|
+        with_locale locale do
+          assert_equal expected, format_hours(0.75)
+        end
+      end
+    end
+  end
+
   def test_html_hours
     assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">:45</span>',
                  html_hours('0:45')