i18n 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of i18n might be problematic. Click here for more details.
- data/CHANGELOG.textile +3 -12
- data/README.textile +17 -4
- data/lib/i18n.rb +37 -5
- data/lib/i18n/backend.rb +1 -0
- data/lib/i18n/backend/base.rb +32 -4
- data/lib/i18n/backend/cldr.rb +99 -0
- data/lib/i18n/backend/gettext.rb +3 -3
- data/lib/i18n/backend/interpolation_compiler.rb +1 -1
- data/lib/i18n/backend/metadata.rb +1 -1
- data/lib/i18n/config.rb +13 -1
- data/lib/i18n/core_ext/string/interpolate.rb +0 -9
- data/lib/i18n/exceptions.rb +31 -3
- data/lib/i18n/locale/fallbacks.rb +3 -3
- data/lib/i18n/tests/localization/procs.rb +24 -25
- data/lib/i18n/version.rb +1 -1
- metadata +16 -121
- data/ci/Gemfile.no-rails +0 -5
- data/ci/Gemfile.no-rails.lock +0 -14
- data/ci/Gemfile.rails-2.3.x +0 -9
- data/ci/Gemfile.rails-2.3.x.lock +0 -23
- data/ci/Gemfile.rails-3.x +0 -9
- data/ci/Gemfile.rails-3.x.lock +0 -23
- data/lib/i18n/core_ext/kernel/surpress_warnings.rb +0 -9
- data/lib/i18n/interpolate/ruby.rb +0 -31
- data/test/all.rb +0 -8
- data/test/api/all_features_test.rb +0 -58
- data/test/api/cascade_test.rb +0 -28
- data/test/api/chain_test.rb +0 -24
- data/test/api/fallbacks_test.rb +0 -30
- data/test/api/key_value_test.rb +0 -28
- data/test/api/memoize_test.rb +0 -60
- data/test/api/pluralization_test.rb +0 -30
- data/test/api/simple_test.rb +0 -28
- data/test/backend/cache_test.rb +0 -83
- data/test/backend/cascade_test.rb +0 -85
- data/test/backend/chain_test.rb +0 -67
- data/test/backend/exceptions_test.rb +0 -23
- data/test/backend/fallbacks_test.rb +0 -116
- data/test/backend/interpolation_compiler_test.rb +0 -102
- data/test/backend/key_value_test.rb +0 -46
- data/test/backend/memoize_test.rb +0 -47
- data/test/backend/metadata_test.rb +0 -67
- data/test/backend/pluralization_test.rb +0 -44
- data/test/backend/simple_test.rb +0 -79
- data/test/backend/transliterator_test.rb +0 -81
- data/test/core_ext/hash_test.rb +0 -30
- data/test/core_ext/string/interpolate_test.rb +0 -99
- data/test/gettext/api_test.rb +0 -206
- data/test/gettext/backend_test.rb +0 -93
- data/test/i18n/exceptions_test.rb +0 -116
- data/test/i18n/interpolate_test.rb +0 -61
- data/test/i18n/load_path_test.rb +0 -26
- data/test/i18n_test.rb +0 -236
- data/test/locale/fallbacks_test.rb +0 -124
- data/test/locale/tag/rfc4646_test.rb +0 -142
- data/test/locale/tag/simple_test.rb +0 -32
- data/test/run_all.rb +0 -21
- data/test/test_data/locales/de.po +0 -72
- data/test/test_data/locales/en.rb +0 -3
- data/test/test_data/locales/en.yml +0 -3
- data/test/test_data/locales/invalid/empty.yml +0 -1
- data/test/test_data/locales/plurals.rb +0 -113
- data/test/test_helper.rb +0 -56
@@ -73,9 +73,9 @@ module I18n
|
|
73
73
|
def map(mappings)
|
74
74
|
mappings.each do |from, to|
|
75
75
|
from, to = from.to_sym, Array(to)
|
76
|
-
to.each do |
|
76
|
+
to.each do |to|
|
77
77
|
@map[from] ||= []
|
78
|
-
@map[from] <<
|
78
|
+
@map[from] << to.to_sym
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -85,7 +85,7 @@ module I18n
|
|
85
85
|
def compute(tags, include_defaults = true)
|
86
86
|
result = Array(tags).collect do |tag|
|
87
87
|
tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym }
|
88
|
-
tags.each { |
|
88
|
+
tags.each { |tag| tags += compute(@map[tag]) if @map[tag] }
|
89
89
|
tags
|
90
90
|
end.flatten
|
91
91
|
result.push(*defaults) if include_defaults
|
@@ -1,5 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
class DateTime
|
4
|
+
def inspect
|
5
|
+
strftime('%a, %d %b %Y %H:%M:%S %Z')
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Date
|
10
|
+
def inspect
|
11
|
+
strftime('%a, %d %b %Y')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
3
15
|
module I18n
|
4
16
|
module Tests
|
5
17
|
module Localization
|
@@ -7,22 +19,22 @@ module I18n
|
|
7
19
|
test "localize: using day names from lambdas" do
|
8
20
|
setup_time_proc_translations
|
9
21
|
time = ::Time.utc(2008, 3, 1, 6, 0)
|
10
|
-
assert_match
|
11
|
-
assert_match
|
22
|
+
assert_match /Суббота/, I18n.l(time, :format => "%A, %d %B", :locale => :ru)
|
23
|
+
assert_match /суббота/, I18n.l(time, :format => "%d %B (%A)", :locale => :ru)
|
12
24
|
end
|
13
25
|
|
14
26
|
test "localize: using month names from lambdas" do
|
15
27
|
setup_time_proc_translations
|
16
28
|
time = ::Time.utc(2008, 3, 1, 6, 0)
|
17
|
-
assert_match
|
18
|
-
assert_match
|
29
|
+
assert_match /марта/, I18n.l(time, :format => "%d %B %Y", :locale => :ru)
|
30
|
+
assert_match /Март /, I18n.l(time, :format => "%B %Y", :locale => :ru)
|
19
31
|
end
|
20
32
|
|
21
33
|
test "localize: using abbreviated day names from lambdas" do
|
22
34
|
setup_time_proc_translations
|
23
35
|
time = ::Time.utc(2008, 3, 1, 6, 0)
|
24
|
-
assert_match
|
25
|
-
assert_match
|
36
|
+
assert_match /марта/, I18n.l(time, :format => "%d %b %Y", :locale => :ru)
|
37
|
+
assert_match /март /, I18n.l(time, :format => "%b %Y", :locale => :ru)
|
26
38
|
end
|
27
39
|
|
28
40
|
test "localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
|
@@ -52,45 +64,32 @@ module I18n
|
|
52
64
|
test "localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
|
53
65
|
setup_time_proc_translations
|
54
66
|
time = ::Time.utc(2008, 3, 1, 6, 0)
|
55
|
-
assert_equal
|
67
|
+
assert_equal [time, {}].inspect, I18n.l(time, :format => :proc, :locale => :ru)
|
56
68
|
end
|
57
69
|
|
58
70
|
test "localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
|
59
71
|
setup_time_proc_translations
|
60
72
|
time = ::Time.utc(2008, 3, 1, 6, 0)
|
61
73
|
options = { :foo => 'foo' }
|
62
|
-
assert_equal
|
74
|
+
assert_equal [time, options].inspect, I18n.l(time, options.merge(:format => :proc, :locale => :ru))
|
63
75
|
end
|
64
76
|
|
65
77
|
protected
|
66
78
|
|
67
|
-
def
|
68
|
-
args
|
69
|
-
case arg
|
70
|
-
when ::Time, ::DateTime
|
71
|
-
arg.strftime('%a, %d %b %Y %H:%M:%S %Z').sub('+0000', '+00:00')
|
72
|
-
when ::Date
|
73
|
-
arg.strftime('%a, %d %b %Y')
|
74
|
-
when Hash
|
75
|
-
arg.delete(:fallback)
|
76
|
-
arg.inspect
|
77
|
-
else
|
78
|
-
arg.inspect
|
79
|
-
end
|
80
|
-
end
|
81
|
-
"[#{args.join(', ')}]"
|
79
|
+
def filter_args(*args)
|
80
|
+
args.map { |arg| arg.delete(:fallback) if arg.is_a?(Hash) ; arg }.inspect
|
82
81
|
end
|
83
82
|
|
84
83
|
def setup_time_proc_translations
|
85
84
|
I18n.backend.store_translations :ru, {
|
86
85
|
:time => {
|
87
86
|
:formats => {
|
88
|
-
:proc => lambda { |*args|
|
87
|
+
:proc => lambda { |*args| filter_args(*args) }
|
89
88
|
}
|
90
89
|
},
|
91
90
|
:date => {
|
92
91
|
:formats => {
|
93
|
-
:proc => lambda { |*args|
|
92
|
+
:proc => lambda { |*args| filter_args(*args) }
|
94
93
|
},
|
95
94
|
:'day_names' => lambda { |key, options|
|
96
95
|
(options[:format] =~ /^%A/) ?
|
data/lib/i18n/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.5.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sven Fuchs
|
@@ -19,67 +19,9 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date:
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: activesupport
|
27
|
-
prerelease: false
|
28
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
hash: 7
|
34
|
-
segments:
|
35
|
-
- 3
|
36
|
-
- 0
|
37
|
-
- 0
|
38
|
-
version: 3.0.0
|
39
|
-
type: :development
|
40
|
-
version_requirements: *id001
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: sqlite3-ruby
|
43
|
-
prerelease: false
|
44
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
hash: 3
|
50
|
-
segments:
|
51
|
-
- 0
|
52
|
-
version: "0"
|
53
|
-
type: :development
|
54
|
-
version_requirements: *id002
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: mocha
|
57
|
-
prerelease: false
|
58
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
|
-
requirements:
|
61
|
-
- - ">="
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
hash: 3
|
64
|
-
segments:
|
65
|
-
- 0
|
66
|
-
version: "0"
|
67
|
-
type: :development
|
68
|
-
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: test_declarative
|
71
|
-
prerelease: false
|
72
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
hash: 3
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
version: "0"
|
81
|
-
type: :development
|
82
|
-
version_requirements: *id004
|
22
|
+
date: 2013-12-03 00:00:00 Z
|
23
|
+
dependencies: []
|
24
|
+
|
83
25
|
description: New wave Internationalization support for Ruby.
|
84
26
|
email: rails-i18n@googlegroups.com
|
85
27
|
executables: []
|
@@ -89,16 +31,13 @@ extensions: []
|
|
89
31
|
extra_rdoc_files: []
|
90
32
|
|
91
33
|
files:
|
92
|
-
-
|
93
|
-
-
|
94
|
-
- ci/Gemfile.rails-2.3.x
|
95
|
-
- ci/Gemfile.rails-2.3.x.lock
|
96
|
-
- ci/Gemfile.rails-3.x
|
97
|
-
- ci/Gemfile.rails-3.x.lock
|
34
|
+
- lib/i18n.rb
|
35
|
+
- lib/i18n/backend.rb
|
98
36
|
- lib/i18n/backend/base.rb
|
99
37
|
- lib/i18n/backend/cache.rb
|
100
38
|
- lib/i18n/backend/cascade.rb
|
101
39
|
- lib/i18n/backend/chain.rb
|
40
|
+
- lib/i18n/backend/cldr.rb
|
102
41
|
- lib/i18n/backend/fallbacks.rb
|
103
42
|
- lib/i18n/backend/flatten.rb
|
104
43
|
- lib/i18n/backend/gettext.rb
|
@@ -109,80 +48,36 @@ files:
|
|
109
48
|
- lib/i18n/backend/pluralization.rb
|
110
49
|
- lib/i18n/backend/simple.rb
|
111
50
|
- lib/i18n/backend/transliterator.rb
|
112
|
-
- lib/i18n/backend.rb
|
113
51
|
- lib/i18n/config.rb
|
114
52
|
- lib/i18n/core_ext/hash.rb
|
115
|
-
- lib/i18n/core_ext/kernel/surpress_warnings.rb
|
116
53
|
- lib/i18n/core_ext/string/interpolate.rb
|
117
54
|
- lib/i18n/exceptions.rb
|
55
|
+
- lib/i18n/gettext.rb
|
118
56
|
- lib/i18n/gettext/helpers.rb
|
119
57
|
- lib/i18n/gettext/po_parser.rb
|
120
|
-
- lib/i18n/
|
121
|
-
- lib/i18n/interpolate/ruby.rb
|
58
|
+
- lib/i18n/locale.rb
|
122
59
|
- lib/i18n/locale/fallbacks.rb
|
60
|
+
- lib/i18n/locale/tag.rb
|
123
61
|
- lib/i18n/locale/tag/parents.rb
|
124
62
|
- lib/i18n/locale/tag/rfc4646.rb
|
125
63
|
- lib/i18n/locale/tag/simple.rb
|
126
|
-
- lib/i18n/
|
127
|
-
- lib/i18n/locale.rb
|
64
|
+
- lib/i18n/tests.rb
|
128
65
|
- lib/i18n/tests/basics.rb
|
129
66
|
- lib/i18n/tests/defaults.rb
|
130
67
|
- lib/i18n/tests/interpolation.rb
|
131
68
|
- lib/i18n/tests/link.rb
|
69
|
+
- lib/i18n/tests/localization.rb
|
132
70
|
- lib/i18n/tests/localization/date.rb
|
133
71
|
- lib/i18n/tests/localization/date_time.rb
|
134
72
|
- lib/i18n/tests/localization/procs.rb
|
135
73
|
- lib/i18n/tests/localization/time.rb
|
136
|
-
- lib/i18n/tests/localization.rb
|
137
74
|
- lib/i18n/tests/lookup.rb
|
138
75
|
- lib/i18n/tests/pluralization.rb
|
139
76
|
- lib/i18n/tests/procs.rb
|
140
|
-
- lib/i18n/tests.rb
|
141
77
|
- lib/i18n/version.rb
|
142
|
-
- lib/i18n.rb
|
143
|
-
- test/all.rb
|
144
|
-
- test/api/all_features_test.rb
|
145
|
-
- test/api/cascade_test.rb
|
146
|
-
- test/api/chain_test.rb
|
147
|
-
- test/api/fallbacks_test.rb
|
148
|
-
- test/api/key_value_test.rb
|
149
|
-
- test/api/memoize_test.rb
|
150
|
-
- test/api/pluralization_test.rb
|
151
|
-
- test/api/simple_test.rb
|
152
|
-
- test/backend/cache_test.rb
|
153
|
-
- test/backend/cascade_test.rb
|
154
|
-
- test/backend/chain_test.rb
|
155
|
-
- test/backend/exceptions_test.rb
|
156
|
-
- test/backend/fallbacks_test.rb
|
157
|
-
- test/backend/interpolation_compiler_test.rb
|
158
|
-
- test/backend/key_value_test.rb
|
159
|
-
- test/backend/memoize_test.rb
|
160
|
-
- test/backend/metadata_test.rb
|
161
|
-
- test/backend/pluralization_test.rb
|
162
|
-
- test/backend/simple_test.rb
|
163
|
-
- test/backend/transliterator_test.rb
|
164
|
-
- test/core_ext/hash_test.rb
|
165
|
-
- test/core_ext/string/interpolate_test.rb
|
166
|
-
- test/gettext/api_test.rb
|
167
|
-
- test/gettext/backend_test.rb
|
168
|
-
- test/i18n/exceptions_test.rb
|
169
|
-
- test/i18n/interpolate_test.rb
|
170
|
-
- test/i18n/load_path_test.rb
|
171
|
-
- test/i18n_test.rb
|
172
|
-
- test/locale/fallbacks_test.rb
|
173
|
-
- test/locale/tag/rfc4646_test.rb
|
174
|
-
- test/locale/tag/simple_test.rb
|
175
|
-
- test/run_all.rb
|
176
|
-
- test/test_data/locales/de.po
|
177
|
-
- test/test_data/locales/en.rb
|
178
|
-
- test/test_data/locales/en.yml
|
179
|
-
- test/test_data/locales/invalid/empty.yml
|
180
|
-
- test/test_data/locales/plurals.rb
|
181
|
-
- test/test_helper.rb
|
182
78
|
- README.textile
|
183
79
|
- MIT-LICENSE
|
184
80
|
- CHANGELOG.textile
|
185
|
-
has_rdoc: true
|
186
81
|
homepage: http://github.com/svenfuchs/i18n
|
187
82
|
licenses: []
|
188
83
|
|
@@ -214,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
109
|
requirements: []
|
215
110
|
|
216
111
|
rubyforge_project: "[none]"
|
217
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.8.6
|
218
113
|
signing_key:
|
219
114
|
specification_version: 3
|
220
115
|
summary: New wave Internationalization support for Ruby
|
data/ci/Gemfile.no-rails
DELETED
data/ci/Gemfile.no-rails.lock
DELETED
data/ci/Gemfile.rails-2.3.x
DELETED
data/ci/Gemfile.rails-2.3.x.lock
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (2.3.10)
|
5
|
-
ffi (0.6.3)
|
6
|
-
rake (>= 0.8.7)
|
7
|
-
mocha (0.9.9)
|
8
|
-
rake
|
9
|
-
rake (0.8.7)
|
10
|
-
rufus-tokyo (1.0.7)
|
11
|
-
sqlite3-ruby (1.3.2)
|
12
|
-
test_declarative (0.0.4)
|
13
|
-
|
14
|
-
PLATFORMS
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
activesupport (~> 2.3)
|
19
|
-
ffi
|
20
|
-
mocha
|
21
|
-
rufus-tokyo
|
22
|
-
sqlite3-ruby
|
23
|
-
test_declarative
|
data/ci/Gemfile.rails-3.x
DELETED
data/ci/Gemfile.rails-3.x.lock
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (3.0.3)
|
5
|
-
ffi (0.6.3)
|
6
|
-
rake (>= 0.8.7)
|
7
|
-
mocha (0.9.9)
|
8
|
-
rake
|
9
|
-
rake (0.8.7)
|
10
|
-
rufus-tokyo (1.0.7)
|
11
|
-
sqlite3-ruby (1.3.2)
|
12
|
-
test_declarative (0.0.4)
|
13
|
-
|
14
|
-
PLATFORMS
|
15
|
-
ruby
|
16
|
-
|
17
|
-
DEPENDENCIES
|
18
|
-
activesupport (~> 3.0.0)
|
19
|
-
ffi
|
20
|
-
mocha
|
21
|
-
rufus-tokyo
|
22
|
-
sqlite3-ruby
|
23
|
-
test_declarative
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# heavily based on Masao Mutoh's gettext String interpolation extension
|
2
|
-
# http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
|
3
|
-
|
4
|
-
module I18n
|
5
|
-
INTERPOLATION_PATTERN = Regexp.union(
|
6
|
-
/%%/,
|
7
|
-
/%\{(\w+)\}/, # matches placeholders like "%{foo}"
|
8
|
-
/%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
|
9
|
-
)
|
10
|
-
|
11
|
-
class << self
|
12
|
-
def interpolate(string, values)
|
13
|
-
raise ReservedInterpolationKey.new($1.to_sym, string) if string =~ RESERVED_KEYS_PATTERN
|
14
|
-
raise ArgumentError.new('Interpolation values must be a Hash.') unless values.kind_of?(Hash)
|
15
|
-
interpolate_hash(string, values)
|
16
|
-
end
|
17
|
-
|
18
|
-
def interpolate_hash(string, values)
|
19
|
-
string.gsub(INTERPOLATION_PATTERN) do |match|
|
20
|
-
if match == '%%'
|
21
|
-
'%'
|
22
|
-
else
|
23
|
-
key = ($1 || $2).to_sym
|
24
|
-
value = values.key?(key) ? values[key] : raise(MissingInterpolationArgument.new(values, string))
|
25
|
-
value = value.call(values) if value.respond_to?(:call)
|
26
|
-
$3 ? sprintf("%#{$3}", value) : value
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|