l10n 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/l10n.rb +11 -11
- data/lib/l10n/core_extensions.rb +0 -6
- data/lib/l10n/core_extensions/big_decimal_ext.rb +7 -10
- data/lib/l10n/core_extensions/numeric_ext.rb +25 -17
- data/lib/l10n/core_extensions/object_ext.rb +1 -1
- data/lib/l10n/numeric_column_conversions.rb +2 -2
- data/lib/l10n/numericality_validator.rb +29 -0
- data/lib/l10n/version.rb +1 -1
- metadata +17 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ee3166182fab8062a381f32dcd1f00a07aa4574
|
4
|
+
data.tar.gz: a0b4263d5bb0a39fc49c0ce978ba6ba56748189e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2950f6aab544f5f8e11b1cfa28be14d300625f064cabf34fb21f335c3c95f4ee59f92cd0cd10b6c5607b93583e01b852b236010f15e040d4a2b8c5d5211bf393
|
7
|
+
data.tar.gz: 960c3a947e1527a1458a168b0b15674b3278ad8b8a1873dd36b3fbe4866fd2e13a2b920b9de4d2c225678dabf02a5385471e41e8a496c60b28fe8849a2e0da7d
|
data/lib/l10n.rb
CHANGED
@@ -5,17 +5,17 @@ require 'action_view'
|
|
5
5
|
require 'action_dispatch'
|
6
6
|
require 'active_support/all'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
8
|
+
require_relative 'l10n/version'
|
9
|
+
require_relative 'l10n/core_extensions'
|
10
|
+
require_relative 'l10n/i18n_extensions'
|
11
|
+
require_relative 'l10n/inflections'
|
12
|
+
require_relative 'l10n/numeric_column_conversions'
|
13
|
+
require_relative 'l10n/column_translation'
|
14
|
+
require_relative 'l10n/translation_validator'
|
15
|
+
require_relative 'l10n/forms'
|
16
|
+
require_relative 'l10n/javascript_helper'
|
17
|
+
require_relative 'l10n/request'
|
18
|
+
require_relative 'l10n/engine'
|
19
19
|
|
20
20
|
files = Dir[File.join(File.dirname(__FILE__), 'locales/*.yml')]
|
21
21
|
I18n.load_path.concat(files)
|
data/lib/l10n/core_extensions.rb
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
module L10n
|
2
2
|
module CoreExtensions
|
3
3
|
module BigDecimalExt
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
alias_method :_active_support_to_formatted_s, :to_formatted_s
|
8
|
-
alias_method :to_s, :_active_support_to_formatted_s
|
9
|
-
alias_method :to_formatted_s, :_l10n_to_formatted_s
|
4
|
+
|
5
|
+
def to_localized_s
|
6
|
+
Numeric.localize(self)
|
10
7
|
end
|
11
|
-
|
12
|
-
def
|
8
|
+
|
9
|
+
def to_formatted_s(*args)
|
13
10
|
L10n.number_to_rounded(self, *args)
|
14
11
|
end
|
15
|
-
|
12
|
+
|
16
13
|
end
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
20
|
-
BigDecimal.
|
17
|
+
BigDecimal.prepend L10n::CoreExtensions::BigDecimalExt
|
@@ -1,12 +1,6 @@
|
|
1
1
|
module L10n
|
2
2
|
module CoreExtensions
|
3
3
|
module NumericExt
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
alias_method :_active_support_to_formatted_s, :to_formatted_s
|
8
|
-
alias_method :to_formatted_s, :_l10n_to_formatted_s
|
9
|
-
end
|
10
4
|
|
11
5
|
module ClassMethods
|
12
6
|
def delocalize(value)
|
@@ -17,28 +11,42 @@ module L10n
|
|
17
11
|
end
|
18
12
|
|
19
13
|
def localize(value)
|
20
|
-
return value unless value.is_a?(Numeric)
|
14
|
+
return value unless value.is_a?(Numeric) || value.is_a?(String)
|
21
15
|
separator = I18n.t(:'number.format.separator')
|
22
16
|
delimiter = I18n.t(:'number.format.delimiter')
|
23
17
|
value.to_s.gsub('.', 's').gsub(',', delimiter).gsub('s', separator)
|
24
18
|
end
|
25
|
-
end
|
19
|
+
end
|
26
20
|
|
27
|
-
|
28
|
-
|
21
|
+
module Localization
|
22
|
+
def to_localized_s
|
23
|
+
Numeric.localize(self)
|
24
|
+
end
|
29
25
|
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
options
|
35
|
-
|
27
|
+
module Formatting
|
28
|
+
# un-deprecate method
|
29
|
+
def to_formatted_s(format = :rounded, options = nil)
|
30
|
+
if options.nil? && format.is_a?(Hash)
|
31
|
+
options = format
|
32
|
+
format = :rounded
|
33
|
+
end
|
34
|
+
to_s(format, options || {})
|
36
35
|
end
|
37
|
-
_active_support_to_formatted_s(format, options || {})
|
38
36
|
end
|
39
37
|
|
40
38
|
end
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
|
-
Numeric.
|
42
|
+
Numeric.extend L10n::CoreExtensions::NumericExt::ClassMethods
|
43
|
+
|
44
|
+
# Ruby 2.4+ unifies Fixnum & Bignum into Integer.
|
45
|
+
numerics = 0.class == Integer ? [Integer] : [Fixnum, Bignum]
|
46
|
+
numerics << Float
|
47
|
+
numerics << Rational
|
48
|
+
|
49
|
+
numerics.each do |klass|
|
50
|
+
klass.include L10n::CoreExtensions::NumericExt::Localization
|
51
|
+
klass.prepend L10n::CoreExtensions::NumericExt::Formatting
|
52
|
+
end
|
@@ -7,7 +7,7 @@ module L10n
|
|
7
7
|
|
8
8
|
def write_attribute(attr_name, value)
|
9
9
|
column = column_for_attribute(attr_name.to_s)
|
10
|
-
if column && column.
|
10
|
+
if column && [:integer, :float, :decimal].include?(column.type) && value.is_a?(String)
|
11
11
|
value = Numeric.delocalize(value)
|
12
12
|
end
|
13
13
|
super(attr_name, value)
|
@@ -17,4 +17,4 @@ module L10n
|
|
17
17
|
|
18
18
|
end
|
19
19
|
|
20
|
-
ActiveRecord::Base.
|
20
|
+
ActiveRecord::Base.prepend L10n::NumericColumnConversions
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module L10n
|
2
|
+
module NumericalityValidatorExt
|
3
|
+
|
4
|
+
protected
|
5
|
+
|
6
|
+
def parse_raw_value_as_a_number(raw_value)
|
7
|
+
return if raw_value =~ /\A0[xX]/
|
8
|
+
if raw_value.is_a?(String)
|
9
|
+
return unless raw_value =~ numeric_exp_for_current_locale
|
10
|
+
raw_value = Numeric.delocalize(raw_value)
|
11
|
+
end
|
12
|
+
Kernel.Float(raw_value)
|
13
|
+
rescue ArgumentError, TypeError
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def numeric_exp_for_current_locale
|
20
|
+
separator = I18n.t(:'number.format.separator')
|
21
|
+
delimiter = I18n.t(:'number.format.delimiter')
|
22
|
+
@numeric_exp ||= {}
|
23
|
+
@numeric_exp[[delimiter, separator]] ||= /\A[+-]?\d{1,3}(#{Regexp.escape(delimiter)}?\d\d\d)*(#{Regexp.escape(separator)}\d\d*)?\z/
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActiveModel::Validations::NumericalityValidator.prepend L10n::NumericalityValidatorExt
|
data/lib/l10n/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: l10n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -30,70 +30,70 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.0.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 5.0.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 5.0.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 5.0.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: actionpack
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 5.0.1
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 5.0.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: railties
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 5.0.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 5.0.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 1.3.10
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.3.10
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: byebug
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/l10n/inflections.rb
|
162
162
|
- lib/l10n/javascript_helper.rb
|
163
163
|
- lib/l10n/numeric_column_conversions.rb
|
164
|
+
- lib/l10n/numericality_validator.rb
|
164
165
|
- lib/l10n/request.rb
|
165
166
|
- lib/l10n/translation_validator.rb
|
166
167
|
- lib/l10n/version.rb
|
@@ -186,8 +187,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
187
|
version: '0'
|
187
188
|
requirements: []
|
188
189
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.5
|
190
|
+
rubygems_version: 2.4.5
|
190
191
|
signing_key:
|
191
192
|
specification_version: 4
|
192
|
-
summary: I18n
|
193
|
+
summary: Make I18n roar again
|
193
194
|
test_files: []
|