i18n-complements 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e315e195eaf2ffc7641dafa65b29f64daf5270cf
|
4
|
+
data.tar.gz: ade2b242b65632eb4164c42ae859af019604f4d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03d540be38622615ed373e3f48aeb9288b58c16b12fbb5bb5aba1e9bd4e1270806b9ac04faeda0e7596b1a7ea61cf54165549970295ed5e19328e7c1ac3fe07a
|
7
|
+
data.tar.gz: 9fe8dc68f570ca829850deebdf3fd1f5bac7c5afbbb3c7bc0aaa8650412dbb1bb2b5ce8b95f631cfe41faffbc9a027077bb81c777835bdd89f747910feed8d7d
|
@@ -53,10 +53,10 @@ module I18nComplements
|
|
53
53
|
formatcy = I18n.translate("number.currency.formats.#{self.code}".to_sym, :locale => options[:locale], :default => {})
|
54
54
|
formatcy[:negative_format] ||= "-" + formatcy[:format] if formatcy[:format]
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
formatter = {}
|
57
|
+
formatter[:separator] = formatcy[:separator] || defaultt[:separator] || defaults[:separator] || ','
|
58
|
+
formatter[:delimiter] = formatcy[:delimiter] || defaultt[:delimiter] || defaults[:delimiter] || ''
|
59
|
+
formatter[:precision] = formatcy[:precision] || self.precision || defaultt[:precision] || 3
|
60
60
|
format = formatcy[:format] || defaultt[:format] || "%n-%u" # defaults[:format] ||
|
61
61
|
negative_format = formatcy[:negative_format] || defaultt[:negative_format] || defaults[:negative_format] || "-" + format
|
62
62
|
unit = formatcy[:unit] || self.unit || self.code
|
@@ -68,10 +68,10 @@ module I18nComplements
|
|
68
68
|
|
69
69
|
value = amount.to_s
|
70
70
|
integers, decimals = value.split(/\./)
|
71
|
-
value = integers.gsub(/^0+[1-9]+/, '').gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{
|
71
|
+
value = integers.gsub(/^0+[1-9]+/, '').gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{formatter[:delimiter]}")
|
72
72
|
unless decimals.to_s.match(/^\s*$/)
|
73
|
-
|
74
|
-
value
|
73
|
+
value << formatter[:separator]
|
74
|
+
value << decimals.gsub(/0+$/, '').ljust(formatter[:precision], '0').scan(/.{1,3}/).join(formatter[:delimiter])
|
75
75
|
end
|
76
76
|
return format.gsub(/%n/, value).gsub(/%u/, unit).gsub(/%s/, "\u{00A0}")
|
77
77
|
end
|
data/test/test_currencies.rb
CHANGED
@@ -45,9 +45,12 @@ class TestCurrencies < Test::Unit::TestCase
|
|
45
45
|
|
46
46
|
def test_number_formatting_with_currency
|
47
47
|
number = 413500
|
48
|
-
assert_equal "¥413,500", ::I18n.localize(number, :locale => :eng, :currency=>"JPY")
|
49
|
-
assert_equal "413\u{00A0}500\u{00A0}¥", ::I18n.localize(number, :locale => :fra, :currency=>"JPY")
|
50
|
-
assert_equal "413,500円", ::I18n.localize(number, :locale => :jpn, :currency=>"JPY")
|
48
|
+
assert_equal "¥413,500", ::I18n.localize(number, :locale => :eng, :currency => "JPY")
|
49
|
+
assert_equal "413\u{00A0}500\u{00A0}¥", ::I18n.localize(number, :locale => :fra, :currency => "JPY")
|
50
|
+
assert_equal "413,500円", ::I18n.localize(number, :locale => :jpn, :currency => "JPY")
|
51
|
+
assert_equal "€0.325,1", ::I18n.localize(0.3251, :locale => :eng, :currency => "EUR")
|
52
|
+
assert_equal "0,325\u{00A0}1\u{00A0}F", ::I18n.localize(0.3251, :locale => :fra, :currency => "FRF")
|
53
|
+
assert_equal "€123,852.325,1", ::I18n.localize(123852.3251, :locale => :eng, :currency => "EUR")
|
51
54
|
end
|
52
55
|
|
53
56
|
def test_number_formatting_with_currency_with_core_extensions
|