i18n 1.0.0 → 1.14.7
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.
- checksums.yaml +4 -4
- data/README.md +75 -32
- data/lib/i18n/backend/base.rb +93 -34
- data/lib/i18n/backend/cache.rb +10 -11
- data/lib/i18n/backend/cache_file.rb +36 -0
- data/lib/i18n/backend/cascade.rb +3 -1
- data/lib/i18n/backend/chain.rb +39 -6
- data/lib/i18n/backend/fallbacks.rb +48 -15
- data/lib/i18n/backend/flatten.rb +10 -5
- data/lib/i18n/backend/gettext.rb +4 -2
- data/lib/i18n/backend/interpolation_compiler.rb +8 -8
- data/lib/i18n/backend/key_value.rb +31 -4
- data/lib/i18n/backend/lazy_loadable.rb +184 -0
- data/lib/i18n/backend/memoize.rb +10 -2
- data/lib/i18n/backend/metadata.rb +5 -3
- data/lib/i18n/backend/pluralization.rb +61 -18
- data/lib/i18n/backend/simple.rb +44 -24
- data/lib/i18n/backend/transliterator.rb +26 -24
- data/lib/i18n/backend.rb +5 -1
- data/lib/i18n/config.rb +22 -4
- data/lib/i18n/exceptions.rb +71 -18
- data/lib/i18n/gettext/helpers.rb +4 -2
- data/lib/i18n/gettext/po_parser.rb +7 -7
- data/lib/i18n/gettext.rb +2 -0
- data/lib/i18n/interpolate/ruby.rb +22 -6
- data/lib/i18n/locale/fallbacks.rb +33 -22
- data/lib/i18n/locale/tag/parents.rb +8 -6
- data/lib/i18n/locale/tag/simple.rb +2 -2
- data/lib/i18n/locale.rb +2 -0
- data/lib/i18n/middleware.rb +2 -0
- data/lib/i18n/tests/basics.rb +5 -7
- data/lib/i18n/tests/defaults.rb +8 -1
- data/lib/i18n/tests/interpolation.rb +34 -7
- data/lib/i18n/tests/link.rb +11 -1
- data/lib/i18n/tests/localization/date.rb +37 -10
- data/lib/i18n/tests/localization/date_time.rb +28 -7
- data/lib/i18n/tests/localization/procs.rb +9 -7
- data/lib/i18n/tests/localization/time.rb +27 -5
- data/lib/i18n/tests/lookup.rb +11 -5
- data/lib/i18n/tests/pluralization.rb +1 -1
- data/lib/i18n/tests/procs.rb +23 -7
- data/lib/i18n/tests.rb +2 -0
- data/lib/i18n/utils.rb +55 -0
- data/lib/i18n/version.rb +3 -1
- data/lib/i18n.rb +179 -58
- metadata +16 -61
- data/gemfiles/Gemfile.rails-3.2.x +0 -10
- data/gemfiles/Gemfile.rails-4.0.x +0 -10
- data/gemfiles/Gemfile.rails-4.1.x +0 -10
- data/gemfiles/Gemfile.rails-4.2.x +0 -10
- data/gemfiles/Gemfile.rails-5.0.x +0 -10
- data/gemfiles/Gemfile.rails-5.1.x +0 -10
- data/gemfiles/Gemfile.rails-master +0 -10
- data/lib/i18n/core_ext/hash.rb +0 -29
- data/lib/i18n/core_ext/kernel/suppress_warnings.rb +0 -8
- data/lib/i18n/core_ext/string/interpolate.rb +0 -9
- 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 -24
- data/test/api/memoize_test.rb +0 -56
- data/test/api/override_test.rb +0 -42
- data/test/api/pluralization_test.rb +0 -30
- data/test/api/simple_test.rb +0 -28
- data/test/backend/cache_test.rb +0 -109
- data/test/backend/cascade_test.rb +0 -86
- data/test/backend/chain_test.rb +0 -122
- data/test/backend/exceptions_test.rb +0 -36
- data/test/backend/fallbacks_test.rb +0 -219
- data/test/backend/interpolation_compiler_test.rb +0 -118
- data/test/backend/key_value_test.rb +0 -61
- data/test/backend/memoize_test.rb +0 -79
- data/test/backend/metadata_test.rb +0 -48
- data/test/backend/pluralization_test.rb +0 -45
- data/test/backend/simple_test.rb +0 -103
- data/test/backend/transliterator_test.rb +0 -84
- data/test/core_ext/hash_test.rb +0 -36
- data/test/gettext/api_test.rb +0 -214
- data/test/gettext/backend_test.rb +0 -92
- data/test/i18n/exceptions_test.rb +0 -117
- data/test/i18n/gettext_plural_keys_test.rb +0 -20
- data/test/i18n/interpolate_test.rb +0 -91
- data/test/i18n/load_path_test.rb +0 -34
- data/test/i18n/middleware_test.rb +0 -24
- data/test/i18n_test.rb +0 -462
- data/test/locale/fallbacks_test.rb +0 -133
- data/test/locale/tag/rfc4646_test.rb +0 -143
- data/test/locale/tag/simple_test.rb +0 -32
- data/test/run_all.rb +0 -20
- data/test/test_data/locales/de.po +0 -82
- 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 -0
- data/test/test_data/locales/invalid/syntax.yml +0 -4
- data/test/test_data/locales/plurals.rb +0 -113
- data/test/test_helper.rb +0 -61
data/test/backend/simple_test.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nBackendSimpleTest < I18n::TestCase
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
I18n.backend = I18n::Backend::Simple.new
|
7
|
-
I18n.load_path = [locales_dir + '/en.yml']
|
8
|
-
end
|
9
|
-
|
10
|
-
# useful because this way we can use the backend with no key for interpolation/pluralization
|
11
|
-
test "simple backend translate: given nil as a key it still interpolations the default value" do
|
12
|
-
assert_equal "Hi David", I18n.t(nil, :default => "Hi %{name}", :name => "David")
|
13
|
-
end
|
14
|
-
|
15
|
-
# loading translations
|
16
|
-
test "simple load_translations: given an unknown file type it raises I18n::UnknownFileType" do
|
17
|
-
assert_raise(I18n::UnknownFileType) { I18n.backend.load_translations("#{locales_dir}/en.xml") }
|
18
|
-
end
|
19
|
-
|
20
|
-
test "simple load_translations: given a Ruby file name it does not raise anything" do
|
21
|
-
assert_nothing_raised { I18n.backend.load_translations("#{locales_dir}/en.rb") }
|
22
|
-
end
|
23
|
-
|
24
|
-
test "simple load_translations: given no argument, it uses I18n.load_path" do
|
25
|
-
I18n.backend.load_translations
|
26
|
-
assert_equal({ :en => { :foo => { :bar => 'baz' } } }, I18n.backend.send(:translations))
|
27
|
-
end
|
28
|
-
|
29
|
-
test "simple load_rb: loads data from a Ruby file" do
|
30
|
-
data = I18n.backend.send(:load_rb, "#{locales_dir}/en.rb")
|
31
|
-
assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
|
32
|
-
end
|
33
|
-
|
34
|
-
test "simple load_yml: loads data from a YAML file" do
|
35
|
-
data = I18n.backend.send(:load_yml, "#{locales_dir}/en.yml")
|
36
|
-
assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
|
37
|
-
end
|
38
|
-
|
39
|
-
test "simple load_translations: loads data from known file formats" do
|
40
|
-
I18n.backend = I18n::Backend::Simple.new
|
41
|
-
I18n.backend.load_translations("#{locales_dir}/en.rb", "#{locales_dir}/en.yml")
|
42
|
-
expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
|
43
|
-
assert_equal expected, translations
|
44
|
-
end
|
45
|
-
|
46
|
-
test "simple load_translations: given file names as array it does not raise anything" do
|
47
|
-
assert_nothing_raised { I18n.backend.load_translations(["#{locales_dir}/en.rb", "#{locales_dir}/en.yml"]) }
|
48
|
-
end
|
49
|
-
|
50
|
-
# storing translations
|
51
|
-
|
52
|
-
test "simple store_translations: stores translations, ... no, really :-)" do
|
53
|
-
store_translations :'en', :foo => 'bar'
|
54
|
-
assert_equal Hash[:'en', {:foo => 'bar'}], translations
|
55
|
-
end
|
56
|
-
|
57
|
-
test "simple store_translations: deep_merges with existing translations" do
|
58
|
-
store_translations :'en', :foo => {:bar => 'bar'}
|
59
|
-
store_translations :'en', :foo => {:baz => 'baz'}
|
60
|
-
assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
|
61
|
-
end
|
62
|
-
|
63
|
-
test "simple store_translations: converts the given locale to a Symbol" do
|
64
|
-
store_translations 'en', :foo => 'bar'
|
65
|
-
assert_equal Hash[:'en', {:foo => 'bar'}], translations
|
66
|
-
end
|
67
|
-
|
68
|
-
test "simple store_translations: converts keys to Symbols" do
|
69
|
-
store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
|
70
|
-
assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
|
71
|
-
end
|
72
|
-
|
73
|
-
test "simple store_translations: do not store translations unavailable locales if enforce_available_locales is true" do
|
74
|
-
begin
|
75
|
-
I18n.enforce_available_locales = true
|
76
|
-
I18n.available_locales = [:en, :es]
|
77
|
-
store_translations(:fr, :foo => {:bar => 'barfr', :baz => 'bazfr'})
|
78
|
-
store_translations(:es, :foo => {:bar => 'bares', :baz => 'bazes'})
|
79
|
-
assert_nil translations[:fr]
|
80
|
-
assert_equal Hash[:foo, {:bar => 'bares', :baz => 'bazes'}], translations[:es]
|
81
|
-
ensure
|
82
|
-
I18n.config.enforce_available_locales = false
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
test "simple store_translations: store translations for unavailable locales if enforce_available_locales is false" do
|
87
|
-
I18n.available_locales = [:en, :es]
|
88
|
-
store_translations(:fr, :foo => {:bar => 'barfr', :baz => 'bazfr'})
|
89
|
-
assert_equal Hash[:foo, {:bar => 'barfr', :baz => 'bazfr'}], translations[:fr]
|
90
|
-
end
|
91
|
-
|
92
|
-
# reloading translations
|
93
|
-
|
94
|
-
test "simple reload_translations: unloads translations" do
|
95
|
-
I18n.backend.reload!
|
96
|
-
assert_nil translations
|
97
|
-
end
|
98
|
-
|
99
|
-
test "simple reload_translations: uninitializes the backend" do
|
100
|
-
I18n.backend.reload!
|
101
|
-
assert_equal false, I18n.backend.initialized?
|
102
|
-
end
|
103
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class I18nBackendTransliterator < I18n::TestCase
|
5
|
-
def setup
|
6
|
-
super
|
7
|
-
I18n.backend = I18n::Backend::Simple.new
|
8
|
-
@proc = lambda { |n| n.upcase }
|
9
|
-
@hash = { "ü" => "ue", "ö" => "oe", "a" => "a" }
|
10
|
-
@transliterator = I18n::Backend::Transliterator.get
|
11
|
-
end
|
12
|
-
|
13
|
-
test "transliteration rule can be a proc" do
|
14
|
-
store_translations(:xx, :i18n => {:transliterate => {:rule => @proc}})
|
15
|
-
assert_equal "HELLO", I18n.backend.transliterate(:xx, "hello")
|
16
|
-
end
|
17
|
-
|
18
|
-
test "transliteration rule can be a hash" do
|
19
|
-
store_translations(:xx, :i18n => {:transliterate => {:rule => @hash}})
|
20
|
-
assert_equal "ue", I18n.backend.transliterate(:xx, "ü")
|
21
|
-
end
|
22
|
-
|
23
|
-
test "transliteration rule must be a proc or hash" do
|
24
|
-
store_translations(:xx, :i18n => {:transliterate => {:rule => ""}})
|
25
|
-
assert_raise I18n::ArgumentError do
|
26
|
-
I18n.backend.transliterate(:xx, "ü")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
test "transliterator defaults to latin => ascii when no rule is given" do
|
31
|
-
assert_equal "AEroskobing", I18n.backend.transliterate(:xx, "Ærøskøbing")
|
32
|
-
end
|
33
|
-
|
34
|
-
test "default transliterator should not modify ascii characters" do
|
35
|
-
(0..127).each do |byte|
|
36
|
-
char = [byte].pack("U")
|
37
|
-
assert_equal char, @transliterator.transliterate(char)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
test "default transliterator correctly transliterates latin characters" do
|
42
|
-
# create string with range of Unicode's western characters with
|
43
|
-
# diacritics, excluding the division and multiplication signs which for
|
44
|
-
# some reason or other are floating in the middle of all the letters.
|
45
|
-
string = (0xC0..0x17E).to_a.reject {|c| [0xD7, 0xF7].include? c}.pack("U*")
|
46
|
-
string.split(//) do |char|
|
47
|
-
assert_match %r{^[a-zA-Z']*$}, @transliterator.transliterate(string)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
test "should replace non-ASCII chars not in map with a replacement char" do
|
52
|
-
assert_equal "abc?", @transliterator.transliterate("abcſ")
|
53
|
-
end
|
54
|
-
|
55
|
-
test "can replace non-ASCII chars not in map with a custom replacement string" do
|
56
|
-
assert_equal "abc#", @transliterator.transliterate("abcſ", "#")
|
57
|
-
end
|
58
|
-
|
59
|
-
test "default transliterator raises errors for invalid UTF-8" do
|
60
|
-
assert_raise ArgumentError do
|
61
|
-
@transliterator.transliterate("a\x92b")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
test "I18n.transliterate should transliterate using a default transliterator" do
|
66
|
-
assert_equal "aeo", I18n.transliterate("áèö")
|
67
|
-
end
|
68
|
-
|
69
|
-
test "I18n.transliterate should transliterate using a locale" do
|
70
|
-
store_translations(:xx, :i18n => {:transliterate => {:rule => @hash}})
|
71
|
-
assert_equal "ue", I18n.transliterate("ü", :locale => :xx)
|
72
|
-
end
|
73
|
-
|
74
|
-
test "default transliterator fails with custom rules with uncomposed input" do
|
75
|
-
char = [117, 776].pack("U*") # "ü" as ASCII "u" plus COMBINING DIAERESIS
|
76
|
-
transliterator = I18n::Backend::Transliterator.get(@hash)
|
77
|
-
assert_not_equal "ue", transliterator.transliterate(char)
|
78
|
-
end
|
79
|
-
|
80
|
-
test "DEFAULT_APPROXIMATIONS is frozen to prevent concurrency issues" do
|
81
|
-
assert I18n::Backend::Transliterator::HashTransliterator::DEFAULT_APPROXIMATIONS.frozen?
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
data/test/core_ext/hash_test.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'i18n/core_ext/hash'
|
3
|
-
|
4
|
-
class I18nCoreExtHashInterpolationTest < I18n::TestCase
|
5
|
-
test "#deep_symbolize_keys" do
|
6
|
-
hash = { 'foo' => { 'bar' => { 'baz' => 'bar' } } }
|
7
|
-
expected = { :foo => { :bar => { :baz => 'bar' } } }
|
8
|
-
assert_equal expected, hash.deep_symbolize_keys
|
9
|
-
end
|
10
|
-
|
11
|
-
test "#slice" do
|
12
|
-
hash = { :foo => 'bar', :baz => 'bar' }
|
13
|
-
expected = { :foo => 'bar' }
|
14
|
-
assert_equal expected, hash.slice(:foo)
|
15
|
-
end
|
16
|
-
|
17
|
-
test "#slice non-existent key" do
|
18
|
-
hash = { :foo => 'bar', :baz => 'bar' }
|
19
|
-
expected = { :foo => 'bar' }
|
20
|
-
assert_equal expected, hash.slice(:foo, :not_here)
|
21
|
-
end
|
22
|
-
|
23
|
-
test "#except" do
|
24
|
-
hash = { :foo => 'bar', :baz => 'bar' }
|
25
|
-
expected = { :foo => 'bar' }
|
26
|
-
assert_equal expected, hash.except(:baz)
|
27
|
-
end
|
28
|
-
|
29
|
-
test "#deep_merge!" do
|
30
|
-
hash = { :foo => { :bar => { :baz => 'bar' } }, :baz => 'bar' }
|
31
|
-
hash.deep_merge!(:foo => { :bar => { :baz => 'foo' } })
|
32
|
-
|
33
|
-
expected = { :foo => { :bar => { :baz => 'foo' } }, :baz => 'bar' }
|
34
|
-
assert_equal expected, hash
|
35
|
-
end
|
36
|
-
end
|
data/test/gettext/api_test.rb
DELETED
@@ -1,214 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'i18n/gettext/helpers'
|
4
|
-
|
5
|
-
include I18n::Gettext::Helpers
|
6
|
-
|
7
|
-
class I18nGettextApiTest < I18n::TestCase
|
8
|
-
def setup
|
9
|
-
super
|
10
|
-
I18n.locale = :en
|
11
|
-
I18n.backend.store_translations :de, {
|
12
|
-
'Hi Gettext!' => 'Hallo Gettext!',
|
13
|
-
'Sentence 1. Sentence 2.' => 'Satz 1. Satz 2.',
|
14
|
-
"An apple" => { :one => 'Ein Apfel', :other => '%{count} Äpfel' },
|
15
|
-
:special => { "A special apple" => { :one => 'Ein spezieller Apfel', :other => '%{count} spezielle Äpfel' } },
|
16
|
-
:foo => { :bar => 'bar-de' },
|
17
|
-
'foo.bar' => 'Foo Bar'
|
18
|
-
}, :separator => '|'
|
19
|
-
end
|
20
|
-
|
21
|
-
# N_
|
22
|
-
def test_N_returns_original_msg
|
23
|
-
assert_equal 'foo|bar', N_('foo|bar')
|
24
|
-
I18n.locale = :de
|
25
|
-
assert_equal 'Hi Gettext!', N_('Hi Gettext!')
|
26
|
-
end
|
27
|
-
|
28
|
-
# gettext
|
29
|
-
def test_gettext_uses_msg_as_default
|
30
|
-
assert_equal 'Hi Gettext!', _('Hi Gettext!')
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_gettext_uses_msg_as_key
|
34
|
-
I18n.locale = :de
|
35
|
-
assert_equal 'Hallo Gettext!', gettext('Hi Gettext!')
|
36
|
-
assert_equal 'Hallo Gettext!', _('Hi Gettext!')
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_gettext_uses_msg_containing_dots_as_default
|
40
|
-
assert_equal 'Sentence 1. Sentence 2.', gettext('Sentence 1. Sentence 2.')
|
41
|
-
assert_equal 'Sentence 1. Sentence 2.', _('Sentence 1. Sentence 2.')
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_gettext_uses_msg_containing_dots_as_key
|
45
|
-
I18n.locale = :de
|
46
|
-
assert_equal 'Satz 1. Satz 2.', gettext('Sentence 1. Sentence 2.')
|
47
|
-
assert_equal 'Satz 1. Satz 2.', _('Sentence 1. Sentence 2.')
|
48
|
-
end
|
49
|
-
|
50
|
-
# sgettext
|
51
|
-
def test_sgettext_defaults_to_the_last_token_of_a_scoped_msgid
|
52
|
-
assert_equal 'bar', sgettext('foo|bar')
|
53
|
-
assert_equal 'bar', s_('foo|bar')
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_sgettext_looks_up_a_scoped_translation
|
57
|
-
I18n.locale = :de
|
58
|
-
assert_equal 'bar-de', sgettext('foo|bar')
|
59
|
-
assert_equal 'bar-de', s_('foo|bar')
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_sgettext_ignores_dots
|
63
|
-
I18n.locale = :de
|
64
|
-
assert_equal 'Foo Bar', sgettext('foo.bar')
|
65
|
-
assert_equal 'Foo Bar', s_('foo.bar')
|
66
|
-
end
|
67
|
-
|
68
|
-
# pgettext
|
69
|
-
def test_pgettext_defaults_to_msgid
|
70
|
-
assert_equal 'bar', pgettext('foo', 'bar')
|
71
|
-
assert_equal 'bar', p_('foo', 'bar')
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_pgettext_looks_up_a_scoped_translation
|
75
|
-
I18n.locale = :de
|
76
|
-
assert_equal 'bar-de', pgettext('foo', 'bar')
|
77
|
-
assert_equal 'bar-de', p_('foo', 'bar')
|
78
|
-
end
|
79
|
-
|
80
|
-
# ngettext
|
81
|
-
def test_ngettext_looks_up_msg_id_as_default_singular
|
82
|
-
assert_equal 'An apple', ngettext('An apple', '%{count} apples', 1)
|
83
|
-
assert_equal 'An apple', n_('An apple', '%{count} apples', 1)
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_ngettext_looks_up_msg_id_plural_as_default_plural
|
87
|
-
assert_equal '2 apples', ngettext('An apple', '%{count} apples', 2)
|
88
|
-
assert_equal '2 apples', n_('An apple', '%{count} apples', 2)
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_ngettext_looks_up_a_singular
|
92
|
-
I18n.locale = :de
|
93
|
-
assert_equal 'Ein Apfel', ngettext('An apple', '%{count} apples', 1)
|
94
|
-
assert_equal 'Ein Apfel', n_('An apple', '%{count} apples', 1)
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_ngettext_looks_up_a_plural
|
98
|
-
I18n.locale = :de
|
99
|
-
assert_equal '2 Äpfel', ngettext('An apple', '%{count} apples', 2)
|
100
|
-
assert_equal '2 Äpfel', n_('An apple', '%{count} apples', 2)
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_ngettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
|
104
|
-
assert_equal 'An apple', ngettext(['An apple', '%{count} apples'], 1)
|
105
|
-
assert_equal 'An apple', n_(['An apple', '%{count} apples'], 1)
|
106
|
-
end
|
107
|
-
|
108
|
-
def test_ngettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
|
109
|
-
assert_equal '2 apples', ngettext(['An apple', '%{count} apples'], 2)
|
110
|
-
assert_equal '2 apples', n_(['An apple', '%{count} apples'], 2)
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_ngettext_looks_up_a_singular_with_alternative_syntax
|
114
|
-
I18n.locale = :de
|
115
|
-
assert_equal 'Ein Apfel', ngettext(['An apple', '%{count} apples'], 1)
|
116
|
-
assert_equal 'Ein Apfel', n_(['An apple', '%{count} apples'], 1)
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_ngettext_looks_up_a_plural_with_alternative_syntax
|
120
|
-
I18n.locale = :de
|
121
|
-
assert_equal '2 Äpfel', ngettext(['An apple', '%{count} apples'], 2)
|
122
|
-
assert_equal '2 Äpfel', n_(['An apple', '%{count} apples'], 2)
|
123
|
-
end
|
124
|
-
|
125
|
-
# nsgettext
|
126
|
-
def test_nsgettext_looks_up_msg_id_as_default_singular
|
127
|
-
assert_equal 'A special apple', nsgettext('special|A special apple', '%{count} special apples', 1)
|
128
|
-
assert_equal 'A special apple', ns_('special|A special apple', '%{count} special apples', 1)
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_nsgettext_looks_up_msg_id_plural_as_default_plural
|
132
|
-
assert_equal '2 special apples', nsgettext('special|A special apple', '%{count} special apples', 2)
|
133
|
-
assert_equal '2 special apples', ns_('special|A special apple', '%{count} special apples', 2)
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_nsgettext_looks_up_a_singular
|
137
|
-
I18n.locale = :de
|
138
|
-
assert_equal 'Ein spezieller Apfel', nsgettext('special|A special apple', '%{count} special apples', 1)
|
139
|
-
assert_equal 'Ein spezieller Apfel', ns_('special|A special apple', '%{count} special apples', 1)
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_nsgettext_looks_up_a_plural
|
143
|
-
I18n.locale = :de
|
144
|
-
assert_equal '2 spezielle Äpfel', nsgettext('special|A special apple', '%{count} special apples', 2)
|
145
|
-
assert_equal '2 spezielle Äpfel', ns_('special|A special apple', '%{count} special apples', 2)
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_nsgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
|
149
|
-
assert_equal 'A special apple', nsgettext(['special|A special apple', '%{count} special apples'], 1)
|
150
|
-
assert_equal 'A special apple', ns_(['special|A special apple', '%{count} special apples'], 1)
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_nsgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
|
154
|
-
assert_equal '2 special apples', nsgettext(['special|A special apple', '%{count} special apples'], 2)
|
155
|
-
assert_equal '2 special apples', ns_(['special|A special apple', '%{count} special apples'], 2)
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_nsgettext_looks_up_a_singular_with_alternative_syntax
|
159
|
-
I18n.locale = :de
|
160
|
-
assert_equal 'Ein spezieller Apfel', nsgettext(['special|A special apple', '%{count} special apples'], 1)
|
161
|
-
assert_equal 'Ein spezieller Apfel', ns_(['special|A special apple', '%{count} special apples'], 1)
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_nsgettext_looks_up_a_plural_with_alternative_syntax
|
165
|
-
I18n.locale = :de
|
166
|
-
assert_equal '2 spezielle Äpfel', nsgettext(['special|A special apple', '%{count} special apples'], 2)
|
167
|
-
assert_equal '2 spezielle Äpfel', ns_(['special|A special apple', '%{count} special apples'], 2)
|
168
|
-
end
|
169
|
-
|
170
|
-
# npgettext
|
171
|
-
def test_npgettext_looks_up_msg_id_as_default_singular
|
172
|
-
assert_equal 'A special apple', npgettext('special', 'A special apple', '%{count} special apples', 1)
|
173
|
-
assert_equal 'A special apple', np_('special', 'A special apple', '%{count} special apples', 1)
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_npgettext_looks_up_msg_id_plural_as_default_plural
|
177
|
-
assert_equal '2 special apples', npgettext('special', 'A special apple', '%{count} special apples', 2)
|
178
|
-
assert_equal '2 special apples', np_('special', 'A special apple', '%{count} special apples', 2)
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_npgettext_looks_up_a_singular
|
182
|
-
I18n.locale = :de
|
183
|
-
assert_equal 'Ein spezieller Apfel', npgettext('special', 'A special apple', '%{count} special apples', 1)
|
184
|
-
assert_equal 'Ein spezieller Apfel', np_('special', 'A special apple', '%{count} special apples', 1)
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_npgettext_looks_up_a_plural
|
188
|
-
I18n.locale = :de
|
189
|
-
assert_equal '2 spezielle Äpfel', npgettext('special', 'A special apple', '%{count} special apples', 2)
|
190
|
-
assert_equal '2 spezielle Äpfel', np_('special', 'A special apple', '%{count} special apples', 2)
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_npgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
|
194
|
-
assert_equal 'A special apple', npgettext('special', ['A special apple', '%{count} special apples'], 1)
|
195
|
-
assert_equal 'A special apple', np_('special', ['A special apple', '%{count} special apples'], 1)
|
196
|
-
end
|
197
|
-
|
198
|
-
def test_npgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
|
199
|
-
assert_equal '2 special apples', npgettext('special', ['A special apple', '%{count} special apples'], 2)
|
200
|
-
assert_equal '2 special apples', np_('special', ['A special apple', '%{count} special apples'], 2)
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_npgettext_looks_up_a_singular_with_alternative_syntax
|
204
|
-
I18n.locale = :de
|
205
|
-
assert_equal 'Ein spezieller Apfel', npgettext('special', ['A special apple', '%{count} special apples'], 1)
|
206
|
-
assert_equal 'Ein spezieller Apfel', np_('special', ['A special apple', '%{count} special apples'], 1)
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_npgettext_looks_up_a_plural_with_alternative_syntax
|
210
|
-
I18n.locale = :de
|
211
|
-
assert_equal '2 spezielle Äpfel', npgettext('special', ['A special apple', '%{count} special apples'], 2)
|
212
|
-
assert_equal '2 spezielle Äpfel', np_('special', ['A special apple', '%{count} special apples'], 2)
|
213
|
-
end
|
214
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class I18nGettextBackendTest < I18n::TestCase
|
6
|
-
include I18n::Gettext::Helpers
|
7
|
-
|
8
|
-
class Backend < I18n::Backend::Simple
|
9
|
-
include I18n::Backend::Gettext
|
10
|
-
end
|
11
|
-
|
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
|
19
|
-
|
20
|
-
def test_backend_loads_po_file
|
21
|
-
I18n.backend.send(:init_translations)
|
22
|
-
assert I18n.backend.send(:translations)[:de][:"Axis"]
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_looks_up_a_translation
|
26
|
-
I18n.locale = :de
|
27
|
-
assert_equal 'Auto', gettext('car')
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_uses_default_translation
|
31
|
-
assert_equal 'car', gettext('car')
|
32
|
-
end
|
33
|
-
|
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
|
40
|
-
|
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
|
46
|
-
|
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
|
52
|
-
|
53
|
-
def test_pluralizes_default_entry
|
54
|
-
assert_equal 'Axis', ngettext('Axis', 'Axis', 1)
|
55
|
-
assert_equal 'Axis', ngettext('Axis', 'Axis', 2)
|
56
|
-
end
|
57
|
-
|
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
|
67
|
-
|
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
|
76
|
-
|
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
|
86
|
-
|
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)
|
91
|
-
end
|
92
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nExceptionsTest < I18n::TestCase
|
4
|
-
def test_invalid_locale_stores_locale
|
5
|
-
force_invalid_locale
|
6
|
-
rescue I18n::ArgumentError => exception
|
7
|
-
assert_nil exception.locale
|
8
|
-
end
|
9
|
-
|
10
|
-
test "passing an invalid locale raises an InvalidLocale exception" do
|
11
|
-
force_invalid_locale do |exception|
|
12
|
-
assert_equal 'nil is not a valid locale', exception.message
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
test "MissingTranslation can be initialized without options" do
|
17
|
-
exception = I18n::MissingTranslation.new(:en, 'foo')
|
18
|
-
assert_equal({}, exception.options)
|
19
|
-
end
|
20
|
-
|
21
|
-
test "MissingTranslationData exception stores locale, key and options" do
|
22
|
-
force_missing_translation_data do |exception|
|
23
|
-
assert_equal 'de', exception.locale
|
24
|
-
assert_equal :foo, exception.key
|
25
|
-
assert_equal({:scope => :bar}, exception.options)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
test "MissingTranslationData message contains the locale and scoped key" do
|
30
|
-
force_missing_translation_data do |exception|
|
31
|
-
assert_equal 'translation missing: de.bar.foo', exception.message
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
test "InvalidPluralizationData stores entry, count and key" do
|
36
|
-
force_invalid_pluralization_data do |exception|
|
37
|
-
assert_equal({:other => "bar"}, exception.entry)
|
38
|
-
assert_equal 1, exception.count
|
39
|
-
assert_equal :one, exception.key
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
test "InvalidPluralizationData message contains count, data and missing key" do
|
44
|
-
force_invalid_pluralization_data do |exception|
|
45
|
-
assert_match '1', exception.message
|
46
|
-
assert_match '{:other=>"bar"}', exception.message
|
47
|
-
assert_match 'one', exception.message
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
test "MissingInterpolationArgument stores key and string" do
|
52
|
-
assert_raise(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
|
53
|
-
force_missing_interpolation_argument do |exception|
|
54
|
-
assert_equal :bar, exception.key
|
55
|
-
assert_equal "%{bar}", exception.string
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
test "MissingInterpolationArgument message contains the missing and given arguments" do
|
60
|
-
force_missing_interpolation_argument do |exception|
|
61
|
-
assert_equal 'missing interpolation argument :bar in "%{bar}" ({:baz=>"baz"} given)', exception.message
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
test "ReservedInterpolationKey stores key and string" do
|
66
|
-
force_reserved_interpolation_key do |exception|
|
67
|
-
assert_equal :scope, exception.key
|
68
|
-
assert_equal "%{scope}", exception.string
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
test "ReservedInterpolationKey message contains the reserved key" do
|
73
|
-
force_reserved_interpolation_key do |exception|
|
74
|
-
assert_equal 'reserved key :scope used in "%{scope}"', exception.message
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
test "MissingTranslationData#new can be initialized with just two arguments" do
|
79
|
-
assert I18n::MissingTranslationData.new('en', 'key')
|
80
|
-
end
|
81
|
-
|
82
|
-
private
|
83
|
-
|
84
|
-
def force_invalid_locale
|
85
|
-
I18n.translate(:foo, :locale => nil)
|
86
|
-
rescue I18n::ArgumentError => e
|
87
|
-
block_given? ? yield(e) : raise(e)
|
88
|
-
end
|
89
|
-
|
90
|
-
def force_missing_translation_data(options = {})
|
91
|
-
store_translations('de', :bar => nil)
|
92
|
-
I18n.translate(:foo, options.merge(:scope => :bar, :locale => :de))
|
93
|
-
rescue I18n::ArgumentError => e
|
94
|
-
block_given? ? yield(e) : raise(e)
|
95
|
-
end
|
96
|
-
|
97
|
-
def force_invalid_pluralization_data
|
98
|
-
store_translations('de', :foo => { :other => 'bar' })
|
99
|
-
I18n.translate(:foo, :count => 1, :locale => :de)
|
100
|
-
rescue I18n::ArgumentError => e
|
101
|
-
block_given? ? yield(e) : raise(e)
|
102
|
-
end
|
103
|
-
|
104
|
-
def force_missing_interpolation_argument
|
105
|
-
store_translations('de', :foo => "%{bar}")
|
106
|
-
I18n.translate(:foo, :baz => 'baz', :locale => :de)
|
107
|
-
rescue I18n::ArgumentError => e
|
108
|
-
block_given? ? yield(e) : raise(e)
|
109
|
-
end
|
110
|
-
|
111
|
-
def force_reserved_interpolation_key
|
112
|
-
store_translations('de', :foo => "%{scope}")
|
113
|
-
I18n.translate(:foo, :baz => 'baz', :locale => :de)
|
114
|
-
rescue I18n::ArgumentError => e
|
115
|
-
block_given? ? yield(e) : raise(e)
|
116
|
-
end
|
117
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class I18nGettextPluralKeysTest < I18n::TestCase
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
I18n::Gettext.plural_keys[:zz] = [:value1, :value2]
|
7
|
-
end
|
8
|
-
|
9
|
-
test "Returns the plural keys of the given locale if present" do
|
10
|
-
assert_equal I18n::Gettext.plural_keys(:zz), [:value1, :value2]
|
11
|
-
end
|
12
|
-
|
13
|
-
test "Returns the plural keys of :en if given locale not present" do
|
14
|
-
assert_equal I18n::Gettext.plural_keys(:yy), [:one, :other]
|
15
|
-
end
|
16
|
-
|
17
|
-
test "Returns the whole hash with no arguments" do
|
18
|
-
assert_equal I18n::Gettext.plural_keys, { :en => [:one, :other], :zz => [:value1, :value2] }
|
19
|
-
end
|
20
|
-
end
|