i18n 0.6.11 → 0.7.0.beta1
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.
- checksums.yaml +7 -0
- data/README.md +3 -26
- data/gemfiles/Gemfile.rails-3.2.x +0 -2
- data/gemfiles/Gemfile.rails-3.2.x.lock +5 -9
- data/gemfiles/Gemfile.rails-4.0.x +0 -2
- data/gemfiles/Gemfile.rails-4.0.x.lock +7 -11
- data/gemfiles/Gemfile.rails-4.1.x +0 -2
- data/gemfiles/Gemfile.rails-4.1.x.lock +7 -11
- data/gemfiles/{Gemfile.rails-3.1.x → Gemfile.rails-master} +1 -3
- data/gemfiles/Gemfile.rails-master.lock +40 -0
- data/lib/i18n.rb +7 -30
- data/lib/i18n/backend/base.rb +0 -1
- data/lib/i18n/backend/interpolation_compiler.rb +1 -1
- data/lib/i18n/backend/key_value.rb +0 -1
- data/lib/i18n/config.rb +16 -6
- data/lib/i18n/exceptions.rb +4 -28
- data/lib/i18n/version.rb +1 -1
- data/test/api/key_value_test.rb +2 -6
- data/test/api/memoize_test.rb +2 -6
- data/test/api/override_test.rb +2 -3
- data/test/backend/cache_test.rb +1 -0
- data/test/backend/cascade_test.rb +1 -0
- data/test/backend/chain_test.rb +1 -0
- data/test/backend/exceptions_test.rb +1 -0
- data/test/backend/fallbacks_test.rb +8 -2
- data/test/backend/key_value_test.rb +2 -5
- data/test/backend/memoize_test.rb +2 -2
- data/test/backend/metadata_test.rb +1 -0
- data/test/backend/pluralization_test.rb +1 -0
- data/test/backend/simple_test.rb +2 -1
- data/test/backend/transliterator_test.rb +4 -5
- data/test/gettext/api_test.rb +1 -0
- data/test/gettext/backend_test.rb +73 -82
- data/test/i18n/exceptions_test.rb +0 -15
- data/test/i18n/interpolate_test.rb +2 -1
- data/test/i18n/load_path_test.rb +1 -0
- data/test/i18n_test.rb +35 -0
- data/test/locale/fallbacks_test.rb +1 -4
- data/test/locale/tag/rfc4646_test.rb +1 -0
- data/test/run_all.rb +1 -1
- data/test/test_helper.rb +20 -41
- metadata +19 -28
- data/gemfiles/Gemfile.rails-2.3.x +0 -11
- data/gemfiles/Gemfile.rails-2.3.x.lock +0 -30
- data/gemfiles/Gemfile.rails-3.0.x +0 -11
- data/gemfiles/Gemfile.rails-3.0.x.lock +0 -30
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -30
- data/lib/i18n/core_ext/string/interpolate.rb +0 -105
- data/test/all.rb +0 -8
- data/test/core_ext/string/interpolate_test.rb +0 -99
data/lib/i18n/version.rb
CHANGED
data/test/api/key_value_test.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
I18n::TestCase.setup_rufus_tokyo
|
4
|
-
|
5
3
|
class I18nKeyValueApiTest < I18n::TestCase
|
6
4
|
include I18n::Tests::Basics
|
7
5
|
include I18n::Tests::Defaults
|
@@ -15,14 +13,12 @@ class I18nKeyValueApiTest < I18n::TestCase
|
|
15
13
|
include I18n::Tests::Localization::Time
|
16
14
|
# include Tests::Api::Localization::Procs
|
17
15
|
|
18
|
-
STORE = Rufus::Tokyo::Cabinet.new('*')
|
19
|
-
|
20
16
|
def setup
|
21
|
-
I18n.backend = I18n::Backend::KeyValue.new(
|
17
|
+
I18n.backend = I18n::Backend::KeyValue.new({})
|
22
18
|
super
|
23
19
|
end
|
24
20
|
|
25
21
|
test "make sure we use the KeyValue backend" do
|
26
22
|
assert_equal I18n::Backend::KeyValue, I18n.backend.class
|
27
23
|
end
|
28
|
-
end if
|
24
|
+
end if I18n::TestCase.key_value?
|
data/test/api/memoize_test.rb
CHANGED
@@ -27,8 +27,6 @@ class I18nMemoizeBackendWithSimpleApiTest < I18n::TestCase
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
I18n::TestCase.setup_rufus_tokyo
|
31
|
-
|
32
30
|
class I18nMemoizeBackendWithKeyValueApiTest < I18n::TestCase
|
33
31
|
include I18n::Tests::Basics
|
34
32
|
include I18n::Tests::Defaults
|
@@ -47,14 +45,12 @@ class I18nMemoizeBackendWithKeyValueApiTest < I18n::TestCase
|
|
47
45
|
include I18n::Backend::Memoize
|
48
46
|
end
|
49
47
|
|
50
|
-
STORE = Rufus::Tokyo::Cabinet.new('*')
|
51
|
-
|
52
48
|
def setup
|
53
|
-
I18n.backend = MemoizeBackend.new(
|
49
|
+
I18n.backend = MemoizeBackend.new({})
|
54
50
|
super
|
55
51
|
end
|
56
52
|
|
57
53
|
test "make sure we use the MemoizeBackend backend" do
|
58
54
|
assert_equal MemoizeBackend, I18n.backend.class
|
59
55
|
end
|
60
|
-
end if
|
56
|
+
end if I18n::TestCase.key_value?
|
data/test/api/override_test.rb
CHANGED
@@ -16,9 +16,9 @@ class I18nOverrideTest < I18n::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def setup
|
19
|
+
super
|
19
20
|
@I18n = I18n.dup
|
20
21
|
@I18n.backend = I18n::Backend::Simple.new
|
21
|
-
super
|
22
22
|
end
|
23
23
|
|
24
24
|
test "make sure modules can overwrite I18n methods" do
|
@@ -26,8 +26,7 @@ class I18nOverrideTest < I18n::TestCase
|
|
26
26
|
@I18n.backend.store_translations('en', :foo => 'bar')
|
27
27
|
|
28
28
|
assert_equal 'rab', @I18n.translate(:foo, :locale => 'en')
|
29
|
-
|
30
|
-
# assert_equal 'rab', @I18n.t(:foo, :locale => 'en')
|
29
|
+
assert_equal 'rab', @I18n.t(:foo, :locale => 'en')
|
31
30
|
assert_equal 'rab', @I18n.translate!(:foo, :locale => 'en')
|
32
31
|
assert_equal 'rab', @I18n.t!(:foo, :locale => 'en')
|
33
32
|
end
|
data/test/backend/cache_test.rb
CHANGED
data/test/backend/chain_test.rb
CHANGED
@@ -6,6 +6,7 @@ class I18nBackendFallbacksTranslateTest < I18n::TestCase
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def setup
|
9
|
+
super
|
9
10
|
I18n.backend = Backend.new
|
10
11
|
store_translations(:en, :foo => 'Foo in :en', :bar => 'Bar in :en', :buz => 'Buz in :en')
|
11
12
|
store_translations(:de, :bar => 'Bar in :de', :baz => 'Baz in :de')
|
@@ -92,6 +93,7 @@ class I18nBackendFallbacksLocalizeTest < I18n::TestCase
|
|
92
93
|
end
|
93
94
|
|
94
95
|
def setup
|
96
|
+
super
|
95
97
|
I18n.backend = Backend.new
|
96
98
|
store_translations(:en, :date => { :formats => { :en => 'en' }, :day_names => %w(Sunday) })
|
97
99
|
store_translations(:de, :date => { :formats => { :de => 'de' } })
|
@@ -123,12 +125,16 @@ class I18nBackendFallbacksWithChainTest < I18n::TestCase
|
|
123
125
|
include I18n::Backend::Fallbacks
|
124
126
|
end
|
125
127
|
|
128
|
+
class Chain < I18n::Backend::Chain
|
129
|
+
include I18n::Backend::Fallbacks
|
130
|
+
end
|
131
|
+
|
126
132
|
def setup
|
133
|
+
super
|
127
134
|
backend = Backend.new
|
128
135
|
backend.store_translations(:de, :foo => 'FOO')
|
129
136
|
backend.store_translations(:'pt-BR', :foo => 'Baz in :pt-BR')
|
130
|
-
I18n.backend =
|
131
|
-
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
|
137
|
+
I18n.backend = Chain.new(I18n::Backend::Simple.new, backend)
|
132
138
|
end
|
133
139
|
|
134
140
|
test "falls back from de-DE to de when there is no translation for de-DE available" do
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
I18n::TestCase.setup_rufus_tokyo
|
4
|
-
|
5
3
|
class I18nBackendKeyValueTest < I18n::TestCase
|
6
4
|
def setup_backend!(subtree=true)
|
7
|
-
I18n.backend = I18n::Backend::KeyValue.new(
|
5
|
+
I18n.backend = I18n::Backend::KeyValue.new({}, subtree)
|
8
6
|
store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
|
9
7
|
end
|
10
8
|
|
@@ -42,5 +40,4 @@ class I18nBackendKeyValueTest < I18n::TestCase
|
|
42
40
|
I18n.t("foo", :raise => true)
|
43
41
|
end
|
44
42
|
end
|
45
|
-
|
46
|
-
end if defined?(Rufus::Tokyo::Cabinet)
|
43
|
+
end if I18n::TestCase.key_value?
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
|
3
|
-
require '
|
2
|
+
# TODO: change back to "require 'backend/simple'" when dropping support to Ruby 1.8.7.
|
3
|
+
require File.expand_path('../simple_test', __FILE__)
|
4
4
|
|
5
5
|
class I18nBackendMemoizeTest < I18nBackendSimpleTest
|
6
6
|
module MemoizeSpy
|
@@ -7,6 +7,7 @@ class I18nBackendPluralizationTest < I18n::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def setup
|
10
|
+
super
|
10
11
|
I18n.backend = Backend.new
|
11
12
|
@rule = lambda { |n| n == 1 ? :one : n == 0 || (2..10).include?(n % 100) ? :few : (11..19).include?(n % 100) ? :many : :other }
|
12
13
|
store_translations(:xx, :i18n => { :plural => { :rule => @rule } })
|
data/test/backend/simple_test.rb
CHANGED
@@ -2,6 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class I18nBackendSimpleTest < I18n::TestCase
|
4
4
|
def setup
|
5
|
+
super
|
5
6
|
I18n.backend = I18n::Backend::Simple.new
|
6
7
|
I18n.load_path = [locales_dir + '/en.yml']
|
7
8
|
end
|
@@ -78,6 +79,6 @@ class I18nBackendSimpleTest < I18n::TestCase
|
|
78
79
|
|
79
80
|
test "simple reload_translations: uninitializes the backend" do
|
80
81
|
I18n.backend.reload!
|
81
|
-
assert_equal I18n.backend.initialized
|
82
|
+
assert_equal false, I18n.backend.initialized?
|
82
83
|
end
|
83
84
|
end
|
@@ -3,6 +3,7 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
class I18nBackendTransliterator < I18n::TestCase
|
5
5
|
def setup
|
6
|
+
super
|
6
7
|
I18n.backend = I18n::Backend::Simple.new
|
7
8
|
@proc = lambda { |n| n.upcase }
|
8
9
|
@hash = { "ü" => "ue", "ö" => "oe", "a" => "a" }
|
@@ -55,11 +56,9 @@ class I18nBackendTransliterator < I18n::TestCase
|
|
55
56
|
assert_equal "abc#", @transliterator.transliterate("abcſ", "#")
|
56
57
|
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
@transliterator.transliterate("a\x92b")
|
62
|
-
end
|
59
|
+
test "default transliterator raises errors for invalid UTF-8" do
|
60
|
+
assert_raise ArgumentError do
|
61
|
+
@transliterator.transliterate("a\x92b")
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
data/test/gettext/api_test.rb
CHANGED
@@ -2,100 +2,91 @@
|
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
class I18nGettextBackendTest < I18n::TestCase
|
6
|
+
include I18n::Gettext::Helpers
|
7
7
|
|
8
|
-
class
|
9
|
-
include I18n::Gettext
|
10
|
-
|
11
|
-
class Backend < I18n::Backend::Simple
|
12
|
-
include I18n::Backend::Gettext
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup
|
16
|
-
I18n.backend = Backend.new
|
17
|
-
I18n.locale = :en
|
18
|
-
I18n.load_path = ["#{locales_dir}/de.po"]
|
19
|
-
@old_separator, I18n.default_separator = I18n.default_separator, '|'
|
20
|
-
end
|
8
|
+
class Backend < I18n::Backend::Simple
|
9
|
+
include I18n::Backend::Gettext
|
10
|
+
end
|
21
11
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
def setup
|
13
|
+
super
|
14
|
+
I18n.backend = Backend.new
|
15
|
+
I18n.locale = :en
|
16
|
+
I18n.load_path = ["#{locales_dir}/de.po"]
|
17
|
+
I18n.default_separator = '|'
|
18
|
+
end
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
def test_backend_loads_po_file
|
21
|
+
I18n.backend.send(:init_translations)
|
22
|
+
assert I18n.backend.send(:translations)[:de][:"Axis"]
|
23
|
+
end
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
25
|
+
def test_looks_up_a_translation
|
26
|
+
I18n.locale = :de
|
27
|
+
assert_equal 'Auto', gettext('car')
|
28
|
+
end
|
37
29
|
|
38
|
-
|
39
|
-
|
40
|
-
|
30
|
+
def test_uses_default_translation
|
31
|
+
assert_equal 'car', gettext('car')
|
32
|
+
end
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
34
|
+
def test_looks_up_a_namespaced_translation
|
35
|
+
I18n.locale = :de
|
36
|
+
assert_equal 'Räderzahl', sgettext('Car|Wheels count')
|
37
|
+
assert_equal 'Räderzahl', pgettext('Car', 'Wheels count')
|
38
|
+
assert_equal 'Räderzahl!', pgettext('New car', 'Wheels count')
|
39
|
+
end
|
48
40
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
41
|
+
def test_uses_namespaced_default_translation
|
42
|
+
assert_equal 'Wheels count', sgettext('Car|Wheels count')
|
43
|
+
assert_equal 'Wheels count', pgettext('Car', 'Wheels count')
|
44
|
+
assert_equal 'Wheels count', pgettext('New car', 'Wheels count')
|
45
|
+
end
|
54
46
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
def test_pluralizes_entry
|
48
|
+
I18n.locale = :de
|
49
|
+
assert_equal 'Achse', ngettext('Axis', 'Axis', 1)
|
50
|
+
assert_equal 'Achsen', ngettext('Axis', 'Axis', 2)
|
51
|
+
end
|
60
52
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
53
|
+
def test_pluralizes_default_entry
|
54
|
+
assert_equal 'Axis', ngettext('Axis', 'Axis', 1)
|
55
|
+
assert_equal 'Axis', ngettext('Axis', 'Axis', 2)
|
56
|
+
end
|
65
57
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
58
|
+
def test_pluralizes_namespaced_entry
|
59
|
+
I18n.locale = :de
|
60
|
+
assert_equal 'Rad', nsgettext('Car|wheel', 'wheels', 1)
|
61
|
+
assert_equal 'Räder', nsgettext('Car|wheel', 'wheels', 2)
|
62
|
+
assert_equal 'Rad', npgettext('Car', 'wheel', 'wheels', 1)
|
63
|
+
assert_equal 'Räder', npgettext('Car', 'wheel', 'wheels', 2)
|
64
|
+
assert_equal 'Rad!', npgettext('New car', 'wheel', 'wheels', 1)
|
65
|
+
assert_equal 'Räder!', npgettext('New car', 'wheel', 'wheels', 2)
|
66
|
+
end
|
75
67
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
68
|
+
def test_pluralizes_namespaced_default_entry
|
69
|
+
assert_equal 'wheel', nsgettext('Car|wheel', 'wheels', 1)
|
70
|
+
assert_equal 'wheels', nsgettext('Car|wheel', 'wheels', 2)
|
71
|
+
assert_equal 'wheel', npgettext('Car', 'wheel', 'wheels', 1)
|
72
|
+
assert_equal 'wheels', npgettext('Car', 'wheel', 'wheels', 2)
|
73
|
+
assert_equal 'wheel', npgettext('New car', 'wheel', 'wheels', 1)
|
74
|
+
assert_equal 'wheels', npgettext('New car', 'wheel', 'wheels', 2)
|
75
|
+
end
|
84
76
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
77
|
+
def test_pluralizes_namespaced_entry_with_alternative_syntax
|
78
|
+
I18n.locale = :de
|
79
|
+
assert_equal 'Rad', nsgettext(['Car|wheel', 'wheels'], 1)
|
80
|
+
assert_equal 'Räder', nsgettext(['Car|wheel', 'wheels'], 2)
|
81
|
+
assert_equal 'Rad', npgettext('Car', ['wheel', 'wheels'], 1)
|
82
|
+
assert_equal 'Räder', npgettext('Car', ['wheel', 'wheels'], 2)
|
83
|
+
assert_equal 'Rad!', npgettext('New car', ['wheel', 'wheels'], 1)
|
84
|
+
assert_equal 'Räder!', npgettext('New car', ['wheel', 'wheels'], 2)
|
85
|
+
end
|
94
86
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
87
|
+
def test_ngettextpluralizes_entry_with_dots
|
88
|
+
I18n.locale = :de
|
89
|
+
assert_equal 'Auf 1 Achse.', n_("On %{count} wheel.", "On %{count} wheels.", 1)
|
90
|
+
assert_equal 'Auf 2 Achsen.', n_("On %{count} wheel.", "On %{count} wheels.", 2)
|
100
91
|
end
|
101
92
|
end
|
@@ -27,21 +27,6 @@ class I18nExceptionsTest < I18n::TestCase
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
test "MissingTranslationData html_message is a span with the titlelized last key token" do
|
31
|
-
exception = I18n::MissingTranslationData.new(:de, :foo, :scope => :bar)
|
32
|
-
assert_equal '<span class="translation_missing" title="translation missing: de.bar.foo">Foo</span>', exception.html_message
|
33
|
-
end
|
34
|
-
|
35
|
-
test "MissingTranslationData html_message html escapes key names" do
|
36
|
-
exception = I18n::MissingTranslationData.new(:de, '<script>Evil</script>', :scope => '<iframe src="example.com" />')
|
37
|
-
assert_equal '<span class="translation_missing" title="translation missing: de.<iframe src="example.com" />.<script>Evil</script>"><Script>Evil</Script></span>', exception.html_message
|
38
|
-
end
|
39
|
-
|
40
|
-
test "ExceptionHandler returns the html_message if :rescue_format => :html was given" do
|
41
|
-
message = force_missing_translation_data(:rescue_format => :html)
|
42
|
-
assert_equal '<span class="translation_missing" title="translation missing: de.bar.foo">Foo</span>', message
|
43
|
-
end
|
44
|
-
|
45
30
|
test "InvalidPluralizationData stores entry and count" do
|
46
31
|
force_invalid_pluralization_data do |exception|
|
47
32
|
assert_equal [:bar], exception.entry
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'i18n/core_ext/string/interpolate'
|
3
2
|
|
4
3
|
# thanks to Masao's String extensions, some tests taken from Masao's tests
|
5
4
|
# http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb
|
@@ -62,6 +61,7 @@ end
|
|
62
61
|
|
63
62
|
class I18nMissingInterpolationCustomHandlerTest < I18n::TestCase
|
64
63
|
def setup
|
64
|
+
super
|
65
65
|
@old_handler = I18n.config.missing_interpolation_argument_handler
|
66
66
|
I18n.config.missing_interpolation_argument_handler = lambda do |key, values, string|
|
67
67
|
"missing key is #{key}, values are #{values.inspect}, given string is '#{string}'"
|
@@ -70,6 +70,7 @@ class I18nMissingInterpolationCustomHandlerTest < I18n::TestCase
|
|
70
70
|
|
71
71
|
def teardown
|
72
72
|
I18n.config.missing_interpolation_argument_handler = @old_handler
|
73
|
+
super
|
73
74
|
end
|
74
75
|
|
75
76
|
test "String interpolation can use custom missing interpolation handler" do
|