提交 943d64b1 编写于 作者: S Sven Fuchs 提交者: David Heinemeier Hansson

Vendorize i18n 0.1.3 gem (fixes issues with incompatible character encodings...

Vendorize i18n 0.1.3 gem (fixes issues with incompatible character encodings in Ruby 1.9) (Akira Matsuda) [#2038 state:committed]
Signed-off-by: NDavid Heinemeier Hansson <david@loudthinking.com>
上级 77b0994c
*2.3.1 [RC2] (February 27th, 2009)*
* Vendorize i18n 0.1.3 gem (fixes issues with incompatible character encodings in Ruby 1.9) #2038 [Akira Matsuda]
* Update bundled memcache-client from 1.5.0.5 to 1.6.4.99. See http://www.mikeperham.com/2009/02/15/memcache-client-performance/ [Mike Perham]
* Ruby 1.9.1p0 fix: URI.unescape can decode multibyte chars. #2033 [MOROHASHI Kyosuke]
......
......@@ -22,8 +22,8 @@
# TODO I18n gem has not been released yet
# begin
# gem 'i18n', '~> 0.1.1'
# gem 'i18n', '~> 0.1.3'
# rescue Gem::LoadError
$:.unshift "#{File.dirname(__FILE__)}/vendor/i18n-0.1.1/lib"
$:.unshift "#{File.dirname(__FILE__)}/vendor/i18n-0.1.3/lib"
require 'i18n'
# end
Gem::Specification.new do |s|
s.name = "i18n"
s.version = "0.1.1"
s.date = "2008-10-26"
s.version = "0.1.3"
s.date = "2009-01-09"
s.summary = "Internationalization support for Ruby"
s.email = "rails-i18n@googlegroups.com"
s.homepage = "http://rails-i18n.org"
......
......@@ -151,12 +151,7 @@ def pluralize(locale, entry, count)
def interpolate(locale, string, values = {})
return string unless string.is_a?(String)
if string.respond_to?(:force_encoding)
original_encoding = string.encoding
string.force_encoding(Encoding::BINARY)
end
result = string.gsub(MATCH) do
string.gsub(MATCH) do
escaped, pattern, key = $1, $2, $2.to_sym
if escaped
......@@ -169,9 +164,6 @@ def interpolate(locale, string, values = {})
values[key].to_s
end
end
result.force_encoding(original_encoding) if original_encoding
result
end
# Loads a single translations file by delegating to #load_rb or
......
......@@ -253,6 +253,32 @@ def test_interpolate_given_a_value_hash_interpolates_into_unicode_string
assert_equal 'Häi David!', @backend.send(:interpolate, nil, 'Häi {{name}}!', :name => 'David')
end
def test_interpolate_given_an_unicode_value_hash_interpolates_to_the_string
assert_equal 'Hi ゆきひろ!', @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => 'ゆきひろ')
end
def test_interpolate_given_an_unicode_value_hash_interpolates_into_unicode_string
assert_equal 'こんにちは、ゆきひろさん!', @backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!', :name => 'ゆきひろ')
end
if Kernel.const_defined?(:Encoding)
def test_interpolate_given_a_non_unicode_multibyte_value_hash_interpolates_into_a_string_with_the_same_encoding
assert_equal euc_jp('Hi ゆきひろ!'), @backend.send(:interpolate, nil, 'Hi {{name}}!', :name => euc_jp('ゆきひろ'))
end
def test_interpolate_given_an_unicode_value_hash_into_a_non_unicode_multibyte_string_raises_encoding_compatibility_error
assert_raises(Encoding::CompatibilityError) do
@backend.send(:interpolate, nil, euc_jp('こんにちは、{{name}}さん!'), :name => 'ゆきひろ')
end
end
def test_interpolate_given_a_non_unicode_multibyte_value_hash_into_an_unicode_string_raises_encoding_compatibility_error
assert_raises(Encoding::CompatibilityError) do
@backend.send(:interpolate, nil, 'こんにちは、{{name}}さん!', :name => euc_jp('ゆきひろ'))
end
end
end
def test_interpolate_given_nil_as_a_string_returns_nil
assert_nil @backend.send(:interpolate, nil, nil, :name => 'David')
end
......@@ -272,6 +298,12 @@ def test_interpolate_given_an_empty_values_hash_raises_missing_interpolation_arg
def test_interpolate_given_a_string_containing_a_reserved_key_raises_reserved_interpolation_key
assert_raises(I18n::ReservedInterpolationKey) { @backend.send(:interpolate, nil, '{{default}}', {:default => nil}) }
end
private
def euc_jp(string)
string.encode!(Encoding::EUC_JP)
end
end
class I18nSimpleBackendLocalizeDateTest < Test::Unit::TestCase
......@@ -485,6 +517,10 @@ def test_load_translations_loads_from_different_file_formats
class I18nSimpleBackendLoadPathTest < Test::Unit::TestCase
include I18nSimpleBackendTestSetup
def teardown
I18n.load_path = []
end
def test_nested_load_paths_do_not_break_locale_loading
@backend = I18n::Backend::Simple.new
I18n.load_path = [[File.dirname(__FILE__) + '/locale/en.yml']]
......@@ -492,6 +528,14 @@ def test_nested_load_paths_do_not_break_locale_loading
assert_nothing_raised { @backend.send :init_translations }
assert_not_nil backend_get_translations
end
def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
@backend = I18n::Backend::Simple.new
I18n.load_path << Dir[File.dirname(__FILE__) + '/locale/*.{rb,yml}']
assert_nil backend_get_translations
assert_nothing_raised { @backend.send :init_translations }
assert_not_nil backend_get_translations
end
end
class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
......@@ -521,4 +565,4 @@ def test_reload_translations_uninitializes_translations
@backend.reload!
assert_equal @backend.initialized?, false
end
end
\ No newline at end of file
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册