Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[37859] Use the currency separator to fix languages where they differ

Oliver Günther0b99aa05be2c
diff --git a/modules/costs/app/helpers/costs/number_helper.rb b/modules/costs/app/helpers/costs/number_helper.rb
index 26e9734c741..d2f7428402d 100644
--- a/modules/costs/app/helpers/costs/number_helper.rb
+++ b/modules/costs/app/helpers/costs/number_helper.rb
@@ -36,7 +36,12 @@ module Costs::NumberHelper
# All locales seem to have their delimiters set to "".
# We thus remove all typical delimiters that are not the separator.
- separator = I18n.t(:'number.format.separator')
+ separator =
+ if I18n.exists?(:'number.currency.format.separator')
+ I18n.t(:'number.currency.format.separator')
+ else
+ I18n.t(:'number.format.separator', default: '.')
+ end
if separator
delimiters = Regexp.new('[ .,’˙]'.gsub(separator, ''))
diff --git a/modules/costs/spec/helpers/costs/number_helper_spec.rb b/modules/costs/spec/helpers/costs/number_helper_spec.rb
index 670160674c0..9b31d3041d9 100644
--- a/modules/costs/spec/helpers/costs/number_helper_spec.rb
+++ b/modules/costs/spec/helpers/costs/number_helper_spec.rb
@@ -30,7 +30,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Costs::NumberHelper, type: :helper do
describe '#parse_number_string' do
- context 'for a german local' do
+ context 'with a german local' do
it 'parses a string with delimiter and separator correctly' do
I18n.with_locale(:de) do
expect(helper.parse_number_string("123.456,78"))
@@ -81,7 +81,7 @@ describe Costs::NumberHelper, type: :helper do
end
end
- context 'for an english local' do
+ context 'with an english local' do
it 'parses a string with delimiter and separator correctly' do
I18n.with_locale(:en) do
expect(helper.parse_number_string("123,456.78"))
@@ -138,5 +138,56 @@ describe Costs::NumberHelper, type: :helper do
.to be_nil
end
end
+
+ context 'with a russian locale (Regression #37859)' do
+ it 'parses a string with delimiter and separator correctly' do
+ I18n.with_locale(:ru) do
+ expect(helper.parse_number_string("123.456,78"))
+ .to eql "123456.78"
+ end
+ end
+
+ it 'parses a string with space delimiter and separator correctly' do
+ I18n.with_locale(:de) do
+ expect(helper.parse_number_string("123 456,78"))
+ .to eql "123456.78"
+ end
+ end
+
+ it 'parses a string without delimiter and separator correctly' do
+ I18n.with_locale(:de) do
+ expect(helper.parse_number_string("12345678"))
+ .to eql "12345678"
+ end
+ end
+
+ it 'parses a string without delimiter and with separator correctly' do
+ I18n.with_locale(:de) do
+ expect(helper.parse_number_string("123456,78"))
+ .to eql "123456.78"
+ end
+ end
+
+ it 'parses a string with delimiter and without separator correctly' do
+ I18n.with_locale(:de) do
+ expect(helper.parse_number_string("12.345.678"))
+ .to eql "12345678"
+ end
+ end
+
+ it 'parses a string with space delimiter and without separator correctly' do
+ I18n.with_locale(:de) do
+ expect(helper.parse_number_string("12 345 678"))
+ .to eql "12345678"
+ end
+ end
+
+ it 'returns alphabetical values instead of a delimiter unchanged' do
+ I18n.with_locale(:de) do
+ expect(helper.parse_number_string("123456a78"))
+ .to eql "123456a78"
+ end
+ end
+ end
end
end