i18n 0.5.3 → 0.5.4

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.

Files changed (58) hide show
  1. checksums.yaml +15 -0
  2. data/CHANGELOG.textile +12 -3
  3. data/README.textile +4 -17
  4. data/lib/i18n.rb +5 -9
  5. data/lib/i18n/backend.rb +0 -1
  6. data/lib/i18n/backend/base.rb +4 -32
  7. data/lib/i18n/backend/gettext.rb +3 -3
  8. data/lib/i18n/backend/interpolation_compiler.rb +1 -1
  9. data/lib/i18n/backend/metadata.rb +1 -1
  10. data/lib/i18n/config.rb +1 -1
  11. data/lib/i18n/core_ext/kernel/surpress_warnings.rb +9 -0
  12. data/lib/i18n/core_ext/string/interpolate.rb +9 -0
  13. data/lib/i18n/exceptions.rb +1 -7
  14. data/lib/i18n/interpolate/ruby.rb +31 -0
  15. data/lib/i18n/locale/fallbacks.rb +3 -3
  16. data/lib/i18n/tests/localization/procs.rb +27 -26
  17. data/lib/i18n/version.rb +1 -1
  18. data/test/all.rb +8 -0
  19. data/test/api/all_features_test.rb +58 -0
  20. data/test/api/cascade_test.rb +28 -0
  21. data/test/api/chain_test.rb +24 -0
  22. data/test/api/fallbacks_test.rb +30 -0
  23. data/test/api/key_value_test.rb +28 -0
  24. data/test/api/memoize_test.rb +60 -0
  25. data/test/api/pluralization_test.rb +30 -0
  26. data/test/api/simple_test.rb +28 -0
  27. data/test/backend/cache_test.rb +83 -0
  28. data/test/backend/cascade_test.rb +85 -0
  29. data/test/backend/chain_test.rb +67 -0
  30. data/test/backend/exceptions_test.rb +23 -0
  31. data/test/backend/fallbacks_test.rb +116 -0
  32. data/test/backend/interpolation_compiler_test.rb +102 -0
  33. data/test/backend/key_value_test.rb +46 -0
  34. data/test/backend/memoize_test.rb +47 -0
  35. data/test/backend/metadata_test.rb +67 -0
  36. data/test/backend/pluralization_test.rb +44 -0
  37. data/test/backend/simple_test.rb +79 -0
  38. data/test/backend/transliterator_test.rb +81 -0
  39. data/test/core_ext/hash_test.rb +30 -0
  40. data/test/core_ext/string/interpolate_test.rb +99 -0
  41. data/test/gettext/api_test.rb +206 -0
  42. data/test/gettext/backend_test.rb +93 -0
  43. data/test/i18n/exceptions_test.rb +120 -0
  44. data/test/i18n/interpolate_test.rb +61 -0
  45. data/test/i18n/load_path_test.rb +26 -0
  46. data/test/i18n_test.rb +323 -0
  47. data/test/locale/fallbacks_test.rb +124 -0
  48. data/test/locale/tag/rfc4646_test.rb +142 -0
  49. data/test/locale/tag/simple_test.rb +32 -0
  50. data/test/run_all.rb +21 -0
  51. data/test/test_data/locales/de.po +72 -0
  52. data/test/test_data/locales/en.rb +3 -0
  53. data/test/test_data/locales/en.yml +3 -0
  54. data/test/test_data/locales/invalid/empty.yml +0 -0
  55. data/test/test_data/locales/plurals.rb +113 -0
  56. data/test/test_helper.rb +56 -0
  57. metadata +64 -48
  58. data/lib/i18n/backend/cldr.rb +0 -99
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ class I18nBackendPluralizationTest < Test::Unit::TestCase
4
+ class Backend < I18n::Backend::Simple
5
+ include I18n::Backend::Pluralization
6
+ include I18n::Backend::Fallbacks
7
+ end
8
+
9
+ def setup
10
+ I18n.backend = Backend.new
11
+ @rule = lambda { |n| n == 1 ? :one : n == 0 || (2..10).include?(n % 100) ? :few : (11..19).include?(n % 100) ? :many : :other }
12
+ store_translations(:xx, :i18n => { :plural => { :rule => @rule } })
13
+ @entry = { :zero => 'zero', :one => 'one', :few => 'few', :many => 'many', :other => 'other' }
14
+ end
15
+
16
+ test "pluralization picks a pluralizer from :'i18n.pluralize'" do
17
+ assert_equal @rule, I18n.backend.send(:pluralizer, :xx)
18
+ end
19
+
20
+ test "pluralization picks :one for 1" do
21
+ assert_equal 'one', I18n.t(:count => 1, :default => @entry, :locale => :xx)
22
+ end
23
+
24
+ test "pluralization picks :few for 2" do
25
+ assert_equal 'few', I18n.t(:count => 2, :default => @entry, :locale => :xx)
26
+ end
27
+
28
+ test "pluralization picks :many for 11" do
29
+ assert_equal 'many', I18n.t(:count => 11, :default => @entry, :locale => :xx)
30
+ end
31
+
32
+ test "pluralization picks zero for 0 if the key is contained in the data" do
33
+ assert_equal 'zero', I18n.t(:count => 0, :default => @entry, :locale => :xx)
34
+ end
35
+
36
+ test "pluralization picks few for 0 if the key is not contained in the data" do
37
+ @entry.delete(:zero)
38
+ assert_equal 'few', I18n.t(:count => 0, :default => @entry, :locale => :xx)
39
+ end
40
+
41
+ test "Fallbacks can pick up rules from fallback locales, too" do
42
+ assert_equal @rule, I18n.backend.send(:pluralizer, :'xx-XX')
43
+ end
44
+ end
@@ -0,0 +1,79 @@
1
+ require 'test_helper'
2
+
3
+ class I18nBackendSimpleTest < Test::Unit::TestCase
4
+ def setup
5
+ I18n.backend = I18n::Backend::Simple.new
6
+ I18n.load_path = [locales_dir + '/en.yml']
7
+ end
8
+
9
+ # useful because this way we can use the backend with no key for interpolation/pluralization
10
+ test "simple backend translate: given nil as a key it still interpolations the default value" do
11
+ assert_equal "Hi David", I18n.t(nil, :default => "Hi %{name}", :name => "David")
12
+ end
13
+
14
+ # loading translations
15
+ test "simple load_translations: given an unknown file type it raises I18n::UnknownFileType" do
16
+ assert_raise(I18n::UnknownFileType) { I18n.backend.load_translations("#{locales_dir}/en.xml") }
17
+ end
18
+
19
+ test "simple load_translations: given a Ruby file name it does not raise anything" do
20
+ assert_nothing_raised { I18n.backend.load_translations("#{locales_dir}/en.rb") }
21
+ end
22
+
23
+ test "simple load_translations: given no argument, it uses I18n.load_path" do
24
+ I18n.backend.load_translations
25
+ assert_equal({ :en => { :foo => { :bar => 'baz' } } }, I18n.backend.send(:translations))
26
+ end
27
+
28
+ test "simple load_rb: loads data from a Ruby file" do
29
+ data = I18n.backend.send(:load_rb, "#{locales_dir}/en.rb")
30
+ assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
31
+ end
32
+
33
+ test "simple load_yml: loads data from a YAML file" do
34
+ data = I18n.backend.send(:load_yml, "#{locales_dir}/en.yml")
35
+ assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
36
+ end
37
+
38
+ test "simple load_translations: loads data from known file formats" do
39
+ I18n.backend = I18n::Backend::Simple.new
40
+ I18n.backend.load_translations("#{locales_dir}/en.rb", "#{locales_dir}/en.yml")
41
+ expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
42
+ assert_equal expected, translations
43
+ end
44
+
45
+ # storing translations
46
+
47
+ test "simple store_translations: stores translations, ... no, really :-)" do
48
+ I18n.backend.store_translations :'en', :foo => 'bar'
49
+ assert_equal Hash[:'en', {:foo => 'bar'}], translations
50
+ end
51
+
52
+ test "simple store_translations: deep_merges with existing translations" do
53
+ I18n.backend.store_translations :'en', :foo => {:bar => 'bar'}
54
+ I18n.backend.store_translations :'en', :foo => {:baz => 'baz'}
55
+ assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
56
+ end
57
+
58
+ test "simple store_translations: converts the given locale to a Symbol" do
59
+ I18n.backend.store_translations 'en', :foo => 'bar'
60
+ assert_equal Hash[:'en', {:foo => 'bar'}], translations
61
+ end
62
+
63
+ test "simple store_translations: converts keys to Symbols" do
64
+ I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
65
+ assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
66
+ end
67
+
68
+ # reloading translations
69
+
70
+ test "simple reload_translations: unloads translations" do
71
+ I18n.backend.reload!
72
+ assert_nil translations
73
+ end
74
+
75
+ test "simple reload_translations: uninitializes the backend" do
76
+ I18n.backend.reload!
77
+ assert_equal I18n.backend.initialized?, false
78
+ end
79
+ end
@@ -0,0 +1,81 @@
1
+ # :coding: utf-8
2
+ require 'test_helper'
3
+
4
+ class I18nBackendTransliterator < Test::Unit::TestCase
5
+ def setup
6
+ I18n.backend = I18n::Backend::Simple.new
7
+ @proc = lambda { |n| n.upcase }
8
+ @hash = { :"ü" => "ue", :"ö" => "oe" }
9
+ @transliterator = I18n::Backend::Transliterator.get
10
+ end
11
+
12
+ test "transliteration rule can be a proc" do
13
+ store_translations(:xx, :i18n => {:transliterate => {:rule => @proc}})
14
+ assert_equal "HELLO", I18n.backend.transliterate(:xx, "hello")
15
+ end
16
+
17
+ test "transliteration rule can be a hash" do
18
+ store_translations(:xx, :i18n => {:transliterate => {:rule => @hash}})
19
+ assert_equal "ue", I18n.backend.transliterate(:xx, "ü")
20
+ end
21
+
22
+ test "transliteration rule must be a proc or hash" do
23
+ store_translations(:xx, :i18n => {:transliterate => {:rule => ""}})
24
+ assert_raise I18n::ArgumentError do
25
+ I18n.backend.transliterate(:xx, "ü")
26
+ end
27
+ end
28
+
29
+ test "transliterator defaults to latin => ascii when no rule is given" do
30
+ assert_equal "AEroskobing", I18n.backend.transliterate(:xx, "Ærøskøbing")
31
+ end
32
+
33
+ test "default transliterator should not modify ascii characters" do
34
+ (0..127).each do |byte|
35
+ char = [byte].pack("U")
36
+ assert_equal char, @transliterator.transliterate(char)
37
+ end
38
+ end
39
+
40
+ test "default transliterator correctly transliterates latin characters" do
41
+ # create string with range of Unicode's western characters with
42
+ # diacritics, excluding the division and multiplication signs which for
43
+ # some reason or other are floating in the middle of all the letters.
44
+ string = (0xC0..0x17E).to_a.reject {|c| [0xD7, 0xF7].include? c}.pack("U*")
45
+ string.split(//) do |char|
46
+ assert_match %r{^[a-zA-Z']*$}, @transliterator.transliterate(string)
47
+ end
48
+ end
49
+
50
+ test "should replace non-ASCII chars not in map with a replacement char" do
51
+ assert_equal "abc?", @transliterator.transliterate("abcſ")
52
+ end
53
+
54
+ test "can replace non-ASCII chars not in map with a custom replacement string" do
55
+ assert_equal "abc#", @transliterator.transliterate("abcſ", "#")
56
+ end
57
+
58
+ if RUBY_VERSION >= "1.9"
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
+ end
65
+
66
+ test "I18n.transliterate should transliterate using a default transliterator" do
67
+ assert_equal "aeo", I18n.transliterate("áèö")
68
+ end
69
+
70
+ test "I18n.transliterate should transliterate using a locale" do
71
+ store_translations(:xx, :i18n => {:transliterate => {:rule => @hash}})
72
+ assert_equal "ue", I18n.transliterate("ü", :locale => :xx)
73
+ end
74
+
75
+ test "default transliterator fails with custom rules with uncomposed input" do
76
+ char = [117, 776].pack("U*") # "ü" as ASCII "u" plus COMBINING DIAERESIS
77
+ transliterator = I18n::Backend::Transliterator.get(@hash)
78
+ assert_not_equal "ue", transliterator.transliterate(char)
79
+ end
80
+
81
+ end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+ require 'i18n/core_ext/hash'
3
+
4
+ class I18nCoreExtHashInterpolationTest < Test::Unit::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 "#except" do
18
+ hash = { :foo => 'bar', :baz => 'bar' }
19
+ expected = { :foo => 'bar' }
20
+ assert_equal expected, hash.except(:baz)
21
+ end
22
+
23
+ test "#deep_merge!" do
24
+ hash = { :foo => { :bar => { :baz => 'bar' } }, :baz => 'bar' }
25
+ hash.deep_merge!(:foo => { :bar => { :baz => 'foo' } })
26
+
27
+ expected = { :foo => { :bar => { :baz => 'foo' } }, :baz => 'bar' }
28
+ assert_equal expected, hash
29
+ end
30
+ end
@@ -0,0 +1,99 @@
1
+ require 'test_helper'
2
+
3
+ # thanks to Masao's String extensions these should work the same in
4
+ # Ruby 1.8 (patched) and Ruby 1.9 (native)
5
+ # some tests taken from Masao's tests
6
+ # http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb
7
+
8
+ class I18nCoreExtStringInterpolationTest < Test::Unit::TestCase
9
+ test "String interpolates a single argument" do
10
+ assert_equal "Masao", "%s" % "Masao"
11
+ end
12
+
13
+ test "String interpolates an array argument" do
14
+ assert_equal "1 message", "%d %s" % [1, 'message']
15
+ end
16
+
17
+ test "String interpolates a hash argument w/ named placeholders" do
18
+ assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh' }
19
+ end
20
+
21
+ test "String interpolates a hash argument w/ named placeholders (reverse order)" do
22
+ assert_equal "Mutoh, Masao", "%{last}, %{first}" % { :first => 'Masao', :last => 'Mutoh' }
23
+ end
24
+
25
+ test "String interpolates named placeholders with sprintf syntax" do
26
+ assert_equal "10, 43.4", "%<integer>d, %<float>.1f" % {:integer => 10, :float => 43.4}
27
+ end
28
+
29
+ test "String interpolates named placeholders with sprintf syntax, does not recurse" do
30
+ assert_equal "%<not_translated>s", "%{msg}" % { :msg => '%<not_translated>s', :not_translated => 'should not happen' }
31
+ end
32
+
33
+ test "String interpolation does not replace anything when no placeholders are given" do
34
+ assert_equal("aaa", "aaa" % {:num => 1})
35
+ assert_equal("bbb", "bbb" % [1])
36
+ end
37
+
38
+ test "String interpolation sprintf behaviour equals Ruby 1.9 behaviour" do
39
+ assert_equal("1", "%<num>d" % {:num => 1})
40
+ assert_equal("0b1", "%<num>#b" % {:num => 1})
41
+ assert_equal("foo", "%<msg>s" % {:msg => "foo"})
42
+ assert_equal("1.000000", "%<num>f" % {:num => 1.0})
43
+ assert_equal(" 1", "%<num>3.0f" % {:num => 1.0})
44
+ assert_equal("100.00", "%<num>2.2f" % {:num => 100.0})
45
+ assert_equal("0x64", "%<num>#x" % {:num => 100.0})
46
+ assert_raise(ArgumentError) { "%<num>,d" % {:num => 100} }
47
+ assert_raise(ArgumentError) { "%<num>/d" % {:num => 100} }
48
+ end
49
+
50
+ test "String interpolation old-style sprintf still works" do
51
+ assert_equal("foo 1.000000", "%s %f" % ["foo", 1.0])
52
+ end
53
+
54
+ test "String interpolation raises an ArgumentError when the string has extra placeholders (Array)" do
55
+ assert_raise(ArgumentError) do # Ruby 1.9 msg: "too few arguments"
56
+ "%s %s" % %w(Masao)
57
+ end
58
+ end
59
+
60
+ test "String interpolation raises a KeyError when the string has extra placeholders (Hash)" do
61
+ assert_raise(KeyError) do # Ruby 1.9 msg: "key not found"
62
+ "%{first} %{last}" % { :first => 'Masao' }
63
+ end
64
+ end
65
+
66
+ test "String interpolation does not raise when passed extra values (Array)" do
67
+ assert_nothing_raised do
68
+ assert_equal "Masao", "%s" % %w(Masao Mutoh)
69
+ end
70
+ end
71
+
72
+ test "String interpolation does not raise when passed extra values (Hash)" do
73
+ assert_nothing_raised do
74
+ assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh', :salutation => 'Mr.' }
75
+ end
76
+ end
77
+
78
+ test "% acts as escape character in String interpolation" do
79
+ assert_equal "%{first}", "%%{first}" % { :first => 'Masao' }
80
+ assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
81
+ assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
82
+ end
83
+
84
+ test "% can be used in Ruby's own sprintf behavior" do
85
+ assert_equal "70%", "%d%%" % 70
86
+ assert_equal "70-100%", "%d-%d%%" % [70, 100]
87
+ assert_equal "+2.30%", "%+.2f%%" % 2.3
88
+ end
89
+
90
+ def test_sprintf_mix_unformatted_and_formatted_named_placeholders
91
+ assert_equal("foo 1.000000", "%{name} %<num>f" % {:name => "foo", :num => 1.0})
92
+ end
93
+
94
+ def test_string_interpolation_raises_an_argument_error_when_mixing_named_and_unnamed_placeholders
95
+ assert_raise(ArgumentError) { "%{name} %f" % [1.0] }
96
+ assert_raise(ArgumentError) { "%{name} %f" % [1.0, 2.0] }
97
+ end
98
+ end
99
+
@@ -0,0 +1,206 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+ require 'i18n/gettext/helpers'
4
+
5
+ include I18n::Gettext::Helpers
6
+
7
+ class I18nGettextApiTest < Test::Unit::TestCase
8
+ def setup
9
+ I18n.locale = :en
10
+ I18n.backend.store_translations :de, {
11
+ 'Hi Gettext!' => 'Hallo Gettext!',
12
+ 'Sentence 1. Sentence 2.' => 'Satz 1. Satz 2.',
13
+ "An apple" => { :one => 'Ein Apfel', :other => '%{count} Äpfel' },
14
+ :special => { "A special apple" => { :one => 'Ein spezieller Apfel', :other => '%{count} spezielle Äpfel' } },
15
+ :foo => { :bar => 'bar-de' },
16
+ 'foo.bar' => 'Foo Bar'
17
+ }, :separator => '|'
18
+ end
19
+
20
+ # gettext
21
+ def test_gettext_uses_msg_as_default
22
+ assert_equal 'Hi Gettext!', _('Hi Gettext!')
23
+ end
24
+
25
+ def test_gettext_uses_msg_as_key
26
+ I18n.locale = :de
27
+ assert_equal 'Hallo Gettext!', gettext('Hi Gettext!')
28
+ assert_equal 'Hallo Gettext!', _('Hi Gettext!')
29
+ end
30
+
31
+ def test_gettext_uses_msg_containing_dots_as_default
32
+ assert_equal 'Sentence 1. Sentence 2.', gettext('Sentence 1. Sentence 2.')
33
+ assert_equal 'Sentence 1. Sentence 2.', _('Sentence 1. Sentence 2.')
34
+ end
35
+
36
+ def test_gettext_uses_msg_containing_dots_as_key
37
+ I18n.locale = :de
38
+ assert_equal 'Satz 1. Satz 2.', gettext('Sentence 1. Sentence 2.')
39
+ assert_equal 'Satz 1. Satz 2.', _('Sentence 1. Sentence 2.')
40
+ end
41
+
42
+ # sgettext
43
+ def test_sgettext_defaults_to_the_last_token_of_a_scoped_msgid
44
+ assert_equal 'bar', sgettext('foo|bar')
45
+ assert_equal 'bar', s_('foo|bar')
46
+ end
47
+
48
+ def test_sgettext_looks_up_a_scoped_translation
49
+ I18n.locale = :de
50
+ assert_equal 'bar-de', sgettext('foo|bar')
51
+ assert_equal 'bar-de', s_('foo|bar')
52
+ end
53
+
54
+ def test_sgettext_ignores_dots
55
+ I18n.locale = :de
56
+ assert_equal 'Foo Bar', sgettext('foo.bar')
57
+ assert_equal 'Foo Bar', s_('foo.bar')
58
+ end
59
+
60
+ # pgettext
61
+ def test_pgettext_defaults_to_msgid
62
+ assert_equal 'bar', pgettext('foo', 'bar')
63
+ assert_equal 'bar', p_('foo', 'bar')
64
+ end
65
+
66
+ def test_pgettext_looks_up_a_scoped_translation
67
+ I18n.locale = :de
68
+ assert_equal 'bar-de', pgettext('foo', 'bar')
69
+ assert_equal 'bar-de', p_('foo', 'bar')
70
+ end
71
+
72
+ # ngettext
73
+ def test_ngettext_looks_up_msg_id_as_default_singular
74
+ assert_equal 'An apple', ngettext('An apple', '%{count} apples', 1)
75
+ assert_equal 'An apple', n_('An apple', '%{count} apples', 1)
76
+ end
77
+
78
+ def test_ngettext_looks_up_msg_id_plural_as_default_plural
79
+ assert_equal '2 apples', ngettext('An apple', '%{count} apples', 2)
80
+ assert_equal '2 apples', n_('An apple', '%{count} apples', 2)
81
+ end
82
+
83
+ def test_ngettext_looks_up_a_singular
84
+ I18n.locale = :de
85
+ assert_equal 'Ein Apfel', ngettext('An apple', '%{count} apples', 1)
86
+ assert_equal 'Ein Apfel', n_('An apple', '%{count} apples', 1)
87
+ end
88
+
89
+ def test_ngettext_looks_up_a_plural
90
+ I18n.locale = :de
91
+ assert_equal '2 Äpfel', ngettext('An apple', '%{count} apples', 2)
92
+ assert_equal '2 Äpfel', n_('An apple', '%{count} apples', 2)
93
+ end
94
+
95
+ def test_ngettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
96
+ assert_equal 'An apple', ngettext(['An apple', '%{count} apples'], 1)
97
+ assert_equal 'An apple', n_(['An apple', '%{count} apples'], 1)
98
+ end
99
+
100
+ def test_ngettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
101
+ assert_equal '2 apples', ngettext(['An apple', '%{count} apples'], 2)
102
+ assert_equal '2 apples', n_(['An apple', '%{count} apples'], 2)
103
+ end
104
+
105
+ def test_ngettext_looks_up_a_singular_with_alternative_syntax
106
+ I18n.locale = :de
107
+ assert_equal 'Ein Apfel', ngettext(['An apple', '%{count} apples'], 1)
108
+ assert_equal 'Ein Apfel', n_(['An apple', '%{count} apples'], 1)
109
+ end
110
+
111
+ def test_ngettext_looks_up_a_plural_with_alternative_syntax
112
+ I18n.locale = :de
113
+ assert_equal '2 Äpfel', ngettext(['An apple', '%{count} apples'], 2)
114
+ assert_equal '2 Äpfel', n_(['An apple', '%{count} apples'], 2)
115
+ end
116
+
117
+ # nsgettext
118
+ def test_nsgettext_looks_up_msg_id_as_default_singular
119
+ assert_equal 'A special apple', nsgettext('special|A special apple', '%{count} special apples', 1)
120
+ assert_equal 'A special apple', ns_('special|A special apple', '%{count} special apples', 1)
121
+ end
122
+
123
+ def test_nsgettext_looks_up_msg_id_plural_as_default_plural
124
+ assert_equal '2 special apples', nsgettext('special|A special apple', '%{count} special apples', 2)
125
+ assert_equal '2 special apples', ns_('special|A special apple', '%{count} special apples', 2)
126
+ end
127
+
128
+ def test_nsgettext_looks_up_a_singular
129
+ I18n.locale = :de
130
+ assert_equal 'Ein spezieller Apfel', nsgettext('special|A special apple', '%{count} special apples', 1)
131
+ assert_equal 'Ein spezieller Apfel', ns_('special|A special apple', '%{count} special apples', 1)
132
+ end
133
+
134
+ def test_nsgettext_looks_up_a_plural
135
+ I18n.locale = :de
136
+ assert_equal '2 spezielle Äpfel', nsgettext('special|A special apple', '%{count} special apples', 2)
137
+ assert_equal '2 spezielle Äpfel', ns_('special|A special apple', '%{count} special apples', 2)
138
+ end
139
+
140
+ def test_nsgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
141
+ assert_equal 'A special apple', nsgettext(['special|A special apple', '%{count} special apples'], 1)
142
+ assert_equal 'A special apple', ns_(['special|A special apple', '%{count} special apples'], 1)
143
+ end
144
+
145
+ def test_nsgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
146
+ assert_equal '2 special apples', nsgettext(['special|A special apple', '%{count} special apples'], 2)
147
+ assert_equal '2 special apples', ns_(['special|A special apple', '%{count} special apples'], 2)
148
+ end
149
+
150
+ def test_nsgettext_looks_up_a_singular_with_alternative_syntax
151
+ I18n.locale = :de
152
+ assert_equal 'Ein spezieller Apfel', nsgettext(['special|A special apple', '%{count} special apples'], 1)
153
+ assert_equal 'Ein spezieller Apfel', ns_(['special|A special apple', '%{count} special apples'], 1)
154
+ end
155
+
156
+ def test_nsgettext_looks_up_a_plural_with_alternative_syntax
157
+ I18n.locale = :de
158
+ assert_equal '2 spezielle Äpfel', nsgettext(['special|A special apple', '%{count} special apples'], 2)
159
+ assert_equal '2 spezielle Äpfel', ns_(['special|A special apple', '%{count} special apples'], 2)
160
+ end
161
+
162
+ # npgettext
163
+ def test_npgettext_looks_up_msg_id_as_default_singular
164
+ assert_equal 'A special apple', npgettext('special', 'A special apple', '%{count} special apples', 1)
165
+ assert_equal 'A special apple', np_('special', 'A special apple', '%{count} special apples', 1)
166
+ end
167
+
168
+ def test_npgettext_looks_up_msg_id_plural_as_default_plural
169
+ assert_equal '2 special apples', npgettext('special', 'A special apple', '%{count} special apples', 2)
170
+ assert_equal '2 special apples', np_('special', 'A special apple', '%{count} special apples', 2)
171
+ end
172
+
173
+ def test_npgettext_looks_up_a_singular
174
+ I18n.locale = :de
175
+ assert_equal 'Ein spezieller Apfel', npgettext('special', 'A special apple', '%{count} special apples', 1)
176
+ assert_equal 'Ein spezieller Apfel', np_('special', 'A special apple', '%{count} special apples', 1)
177
+ end
178
+
179
+ def test_npgettext_looks_up_a_plural
180
+ I18n.locale = :de
181
+ assert_equal '2 spezielle Äpfel', npgettext('special', 'A special apple', '%{count} special apples', 2)
182
+ assert_equal '2 spezielle Äpfel', np_('special', 'A special apple', '%{count} special apples', 2)
183
+ end
184
+
185
+ def test_npgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
186
+ assert_equal 'A special apple', npgettext('special', ['A special apple', '%{count} special apples'], 1)
187
+ assert_equal 'A special apple', np_('special', ['A special apple', '%{count} special apples'], 1)
188
+ end
189
+
190
+ def test_npgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
191
+ assert_equal '2 special apples', npgettext('special', ['A special apple', '%{count} special apples'], 2)
192
+ assert_equal '2 special apples', np_('special', ['A special apple', '%{count} special apples'], 2)
193
+ end
194
+
195
+ def test_npgettext_looks_up_a_singular_with_alternative_syntax
196
+ I18n.locale = :de
197
+ assert_equal 'Ein spezieller Apfel', npgettext('special', ['A special apple', '%{count} special apples'], 1)
198
+ assert_equal 'Ein spezieller Apfel', np_('special', ['A special apple', '%{count} special apples'], 1)
199
+ end
200
+
201
+ def test_npgettext_looks_up_a_plural_with_alternative_syntax
202
+ I18n.locale = :de
203
+ assert_equal '2 spezielle Äpfel', npgettext('special', ['A special apple', '%{count} special apples'], 2)
204
+ assert_equal '2 spezielle Äpfel', np_('special', ['A special apple', '%{count} special apples'], 2)
205
+ end
206
+ end