i18n 0.4.0 → 0.4.1
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/lib/i18n/backend/base.rb +14 -5
- data/lib/i18n/version.rb +1 -1
- metadata +9 -4
data/lib/i18n/backend/base.rb
CHANGED
@@ -11,6 +11,7 @@ module I18n
|
|
11
11
|
RESERVED_KEYS = [:scope, :default, :separator, :resolve]
|
12
12
|
RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
|
13
13
|
DEPRECATED_INTERPOLATION_SYNTAX_PATTERN = /(\\)?\{\{([^\}]+)\}\}/
|
14
|
+
INTERPOLATION_SYNTAX_PATTERN = /%\{([^\}]+)\}/
|
14
15
|
|
15
16
|
# Accepts a list of paths to translation files. Loads translations from
|
16
17
|
# plain Ruby (*.rb) or YAML files (*.yml). See #load_rb and #load_yml
|
@@ -150,7 +151,8 @@ module I18n
|
|
150
151
|
# interpolation).
|
151
152
|
def interpolate(locale, string, values = {})
|
152
153
|
return string unless string.is_a?(::String) && !values.empty?
|
153
|
-
|
154
|
+
original_values = values.dup
|
155
|
+
|
154
156
|
preserve_encoding(string) do
|
155
157
|
string = string.gsub(DEPRECATED_INTERPOLATION_SYNTAX_PATTERN) do
|
156
158
|
escaped, key = $1, $2.to_sym
|
@@ -162,10 +164,17 @@ module I18n
|
|
162
164
|
end
|
163
165
|
end
|
164
166
|
|
167
|
+
keys = string.scan(INTERPOLATION_SYNTAX_PATTERN).flatten
|
168
|
+
return string if keys.empty?
|
169
|
+
|
165
170
|
values.each do |key, value|
|
166
|
-
|
167
|
-
|
168
|
-
|
171
|
+
if keys.include?(key.to_s)
|
172
|
+
value = value.call(values) if interpolate_lambda?(value, string, key)
|
173
|
+
value = value.to_s unless value.is_a?(::String)
|
174
|
+
values[key] = value
|
175
|
+
else
|
176
|
+
values.delete(key)
|
177
|
+
end
|
169
178
|
end
|
170
179
|
|
171
180
|
string % values
|
@@ -174,7 +183,7 @@ module I18n
|
|
174
183
|
if string =~ RESERVED_KEYS_PATTERN
|
175
184
|
raise ReservedInterpolationKey.new($1.to_sym, string)
|
176
185
|
else
|
177
|
-
raise MissingInterpolationArgument.new(
|
186
|
+
raise MissingInterpolationArgument.new(original_values, string)
|
178
187
|
end
|
179
188
|
end
|
180
189
|
|
data/lib/i18n/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 13
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Sven Fuchs
|
@@ -18,7 +19,7 @@ autorequire:
|
|
18
19
|
bindir: bin
|
19
20
|
cert_chain: []
|
20
21
|
|
21
|
-
date: 2010-05
|
22
|
+
date: 2010-06-05 00:00:00 +02:00
|
22
23
|
default_executable:
|
23
24
|
dependencies: []
|
24
25
|
|
@@ -79,16 +80,20 @@ rdoc_options: []
|
|
79
80
|
require_paths:
|
80
81
|
- lib
|
81
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
82
84
|
requirements:
|
83
85
|
- - ">="
|
84
86
|
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
85
88
|
segments:
|
86
89
|
- 0
|
87
90
|
version: "0"
|
88
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
89
93
|
requirements:
|
90
94
|
- - ">="
|
91
95
|
- !ruby/object:Gem::Version
|
96
|
+
hash: 23
|
92
97
|
segments:
|
93
98
|
- 1
|
94
99
|
- 3
|
@@ -97,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
102
|
requirements: []
|
98
103
|
|
99
104
|
rubyforge_project: "[none]"
|
100
|
-
rubygems_version: 1.3.
|
105
|
+
rubygems_version: 1.3.7
|
101
106
|
signing_key:
|
102
107
|
specification_version: 3
|
103
108
|
summary: New wave Internationalization support for Ruby
|