diff options
author | Go MAEDA <maeda@farend.jp> | 2024-01-04 06:55:14 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2024-01-04 06:55:14 +0000 |
commit | 1ab44859feac685719b1f8f4023fec6f89b78e08 (patch) | |
tree | d2a2f9753bdd3bf2bce21e3d74a5938a0d47bc9c /lib | |
parent | 82fc543ea1254bab3a727a338964472ba4906727 (diff) | |
download | redmine-1ab44859feac685719b1f8f4023fec6f89b78e08.tar.gz redmine-1ab44859feac685719b1f8f4023fec6f89b78e08.zip |
Support localized decimal separators for float values (#22024).
Patch by Liane Hampe (@liane_hampe).
git-svn-id: https://svn.redmine.org/redmine/trunk@22592 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/field_format.rb | 3 | ||||
-rw-r--r-- | lib/redmine/i18n.rb | 12 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index a27311141..5e81055f1 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -539,8 +539,9 @@ module Redmine end def validate_single_value(custom_field, value, customized=nil) + value = normalize_float(value) errs = super - errs << ::I18n.t('activerecord.errors.messages.invalid') unless (Kernel.Float(value) rescue nil) + errs << ::I18n.t('activerecord.errors.messages.invalid') unless Kernel.Float(value, exception: false) errs end diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb index 8434cd9be..dab486893 100644 --- a/lib/redmine/i18n.rb +++ b/lib/redmine/i18n.rb @@ -99,6 +99,18 @@ module Redmine end end + # Will consider language specific separator in user input + # and normalize them to a unified format to be accepted by Kernel.Float(). + # + # @param value [String] A string represenation of a float value. + # + # @note The delimiter cannot be used here if it is a decimal point since it + # will clash with the dot separator. + def normalize_float(value) + separator = ::I18n.t('number.format.separator') + value.gsub(/[#{separator}]/, separator => '.') + end + def day_name(day) ::I18n.t('date.day_names')[day % 7] end |