svenfuchs-i18n 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/i18n.gemspec +1 -1
- data/lib/i18n/backend/simple.rb +1 -9
- data/test/simple_backend_test.rb +33 -1
- metadata +1 -1
data/i18n.gemspec
CHANGED
data/lib/i18n/backend/simple.rb
CHANGED
@@ -151,12 +151,7 @@ module I18n
|
|
151
151
|
def interpolate(locale, string, values = {})
|
152
152
|
return string unless string.is_a?(String)
|
153
153
|
|
154
|
-
|
155
|
-
original_encoding = string.encoding
|
156
|
-
string.force_encoding(Encoding::BINARY)
|
157
|
-
end
|
158
|
-
|
159
|
-
result = string.gsub(MATCH) do
|
154
|
+
string.gsub(MATCH) do
|
160
155
|
escaped, pattern, key = $1, $2, $2.to_sym
|
161
156
|
|
162
157
|
if escaped
|
@@ -169,9 +164,6 @@ module I18n
|
|
169
164
|
values[key].to_s
|
170
165
|
end
|
171
166
|
end
|
172
|
-
|
173
|
-
result.force_encoding(original_encoding) if original_encoding
|
174
|
-
result
|
175
167
|
end
|
176
168
|
|
177
169
|
# Loads a single translations file by delegating to #load_rb or
|
data/test/simple_backend_test.rb
CHANGED
@@ -253,6 +253,32 @@ class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase
|
|
253
253
|
assert_equal 'Häi David!', @backend.send(:interpolate, nil, 'Häi {{name}}!', :name => 'David')
|
254
254
|
end
|
255
255
|
|
256
|
+
def test_interpolate_given_an_unicode_value_hash_interpolates_to_the_string
|
257
|
+
assert_equal 'Hi ゆきひろ!', @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => 'ゆきひろ')
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_interpolate_given_an_unicode_value_hash_interpolates_into_unicode_string
|
261
|
+
assert_equal 'こんにちは、ゆきひろさん!', @backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!', :name => 'ゆきひろ')
|
262
|
+
end
|
263
|
+
|
264
|
+
if Kernel.const_defined?(:Encoding)
|
265
|
+
def test_interpolate_given_a_non_unicode_multibyte_value_hash_interpolates_into_a_string_with_the_same_encoding
|
266
|
+
assert_equal euc_jp('Hi ゆきひろ!'), @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => euc_jp('ゆきひろ'))
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_interpolate_given_an_unicode_value_hash_into_a_non_unicode_multibyte_string_raises_encoding_compatibility_error
|
270
|
+
assert_raises(Encoding::CompatibilityError) do
|
271
|
+
@backend.send(:interpolate, nil, euc_jp('こんにちは、{{name}}さん!'), :name => 'ゆきひろ')
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_interpolate_given_a_non_unicode_multibyte_value_hash_into_an_unicode_string_raises_encoding_compatibility_error
|
276
|
+
assert_raises(Encoding::CompatibilityError) do
|
277
|
+
@backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!', :name => euc_jp('ゆきひろ'))
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
256
282
|
def test_interpolate_given_nil_as_a_string_returns_nil
|
257
283
|
assert_nil @backend.send(:interpolate, nil, nil, :name => 'David')
|
258
284
|
end
|
@@ -272,6 +298,12 @@ class I18nSimpleBackendInterpolateTest < Test::Unit::TestCase
|
|
272
298
|
def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key
|
273
299
|
assert_raises(I18n::ReservedInterpolationKey) { @backend.send(:interpolate, nil, '{{default}}', {:default => nil}) }
|
274
300
|
end
|
301
|
+
|
302
|
+
private
|
303
|
+
|
304
|
+
def euc_jp(string)
|
305
|
+
string.encode!(Encoding::EUC_JP)
|
306
|
+
end
|
275
307
|
end
|
276
308
|
|
277
309
|
class I18nSimpleBackendLocalizeDateTest < Test::Unit::TestCase
|
@@ -533,4 +565,4 @@ class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
|
|
533
565
|
@backend.reload!
|
534
566
|
assert_equal @backend.initialized?, false
|
535
567
|
end
|
536
|
-
end
|
568
|
+
end
|