Support localized decimal separators for hours in the web UI (#21677).

Patch by Go MAEDA (@maeda).


git-svn-id: https://svn.redmine.org/redmine/trunk@22593 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2024-01-04 07:01:09 +00:00
parent 1ab44859fe
commit f7d2f9f00b
3 changed files with 15 additions and 2 deletions

View File

@@ -684,7 +684,7 @@ module ApplicationHelper
def html_hours(text) def html_hours(text)
text.gsub( text.gsub(
%r{(\d+)([\.:])(\d+)}, %r{(\d+)([\.,:])(\d+)},
'<span class="hours hours-int">\1</span><span class="hours hours-dec">\2\3</span>' '<span class="hours hours-int">\1</span><span class="hours hours-dec">\2\3</span>'
).html_safe ).html_safe
end end

View File

@@ -21,6 +21,8 @@ require 'redmine'
module Redmine module Redmine
module I18n module I18n
include ActionView::Helpers::NumberHelper
def self.included(base) def self.included(base)
base.extend Redmine::I18n base.extend Redmine::I18n
end end
@@ -95,7 +97,7 @@ module Redmine
m = ((hours - h) * 60).round m = ((hours - h) * 60).round
"%d:%02d" % [h, m] "%d:%02d" % [h, m]
else else
"%.2f" % hours.to_f number_with_delimiter(sprintf('%.2f', hours.to_f), delimiter: nil)
end end
end end

View File

@@ -2171,6 +2171,17 @@ class ApplicationHelperTest < Redmine::HelperTest
end end
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 def test_html_hours
assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">:45</span>', assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">:45</span>',
html_hours('0:45') html_hours('0:45')