activesupport 2.3.6.pre → 2.3.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (123) hide show
  1. data/CHANGELOG +9 -5
  2. data/lib/active_support/buffered_logger.rb +1 -1
  3. data/lib/active_support/cache/memory_store.rb +7 -1
  4. data/lib/active_support/cache/strategy/local_cache.rb +1 -1
  5. data/lib/active_support/core_ext/array/conversions.rb +1 -1
  6. data/lib/active_support/core_ext/array/random_access.rb +11 -1
  7. data/lib/active_support/core_ext/class/attribute_accessors.rb +35 -28
  8. data/lib/active_support/core_ext/date/calculations.rb +14 -4
  9. data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
  10. data/lib/active_support/core_ext/module/aliasing.rb +1 -1
  11. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  12. data/lib/active_support/core_ext/module/attribute_accessors.rb +33 -26
  13. data/lib/active_support/core_ext/module/synchronization.rb +1 -1
  14. data/lib/active_support/core_ext/object/blank.rb +20 -2
  15. data/lib/active_support/core_ext/string/output_safety.rb +10 -2
  16. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -4
  17. data/lib/active_support/core_ext/time.rb +8 -4
  18. data/lib/active_support/core_ext/time/calculations.rb +11 -2
  19. data/lib/active_support/deprecation.rb +3 -2
  20. data/lib/active_support/inflections.rb +1 -1
  21. data/lib/active_support/inflector.rb +4 -1
  22. data/lib/active_support/json/backends/yaml.rb +10 -7
  23. data/lib/active_support/json/decoding.rb +1 -1
  24. data/lib/active_support/memoizable.rb +1 -1
  25. data/lib/active_support/multibyte/unicode_database.rb +2 -2
  26. data/lib/active_support/multibyte/utils.rb +6 -7
  27. data/lib/active_support/ordered_hash.rb +24 -30
  28. data/lib/active_support/testing/assertions.rb +14 -0
  29. data/lib/active_support/values/time_zone.rb +84 -76
  30. data/lib/active_support/vendor.rb +1 -1
  31. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n.rb +92 -34
  32. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend.rb +2 -0
  33. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record.rb +9 -13
  34. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/missing.rb +1 -1
  35. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/store_procs.rb +6 -6
  36. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/translation.rb +14 -9
  37. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/base.rb +23 -16
  38. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/cache.rb +1 -0
  39. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/cascade.rb +22 -8
  40. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/chain.rb +2 -1
  41. data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/cldr.rb +100 -0
  42. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/fallbacks.rb +20 -3
  43. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/fast.rb +14 -13
  44. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/gettext.rb +1 -1
  45. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/helpers.rb +4 -16
  46. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/interpolation_compiler.rb +2 -2
  47. data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/links.rb +34 -0
  48. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/metadata.rb +0 -0
  49. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/pluralization.rb +1 -1
  50. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/simple.rb +0 -0
  51. data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/except.rb +8 -0
  52. data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/slice.rb +8 -0
  53. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/core_ext/object/meta_class.rb +0 -0
  54. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/core_ext/string/interpolate.rb +1 -1
  55. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/exceptions.rb +1 -1
  56. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/gettext.rb +0 -0
  57. data/lib/active_support/vendor/{i18n-0.3.3/vendor → i18n-0.3.7/i18n/gettext}/po_parser.rb +0 -0
  58. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/helpers.rb +0 -0
  59. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/helpers/gettext.rb +3 -2
  60. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale.rb +0 -0
  61. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/fallbacks.rb +0 -0
  62. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag.rb +0 -0
  63. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/parents.rb +0 -0
  64. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/rfc4646.rb +0 -0
  65. data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/simple.rb +0 -0
  66. data/lib/active_support/vendor/i18n-0.3.7/i18n/version.rb +3 -0
  67. metadata +42 -96
  68. data/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile +0 -76
  69. data/lib/active_support/vendor/i18n-0.3.3/MIT-LICENSE +0 -20
  70. data/lib/active_support/vendor/i18n-0.3.3/README.textile +0 -81
  71. data/lib/active_support/vendor/i18n-0.3.3/Rakefile +0 -24
  72. data/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml +0 -144
  73. data/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb +0 -71
  74. data/lib/active_support/vendor/i18n-0.3.3/contributors.txt +0 -17
  75. data/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec +0 -165
  76. data/lib/active_support/vendor/i18n-0.3.3/init.rb +0 -1
  77. data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb +0 -3
  78. data/lib/active_support/vendor/i18n-0.3.3/test/all.rb +0 -8
  79. data/lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb +0 -15
  80. data/lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb +0 -40
  81. data/lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb +0 -92
  82. data/lib/active_support/vendor/i18n-0.3.3/test/api/link.rb +0 -55
  83. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb +0 -91
  84. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb +0 -90
  85. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb +0 -54
  86. data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb +0 -84
  87. data/lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb +0 -45
  88. data/lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb +0 -35
  89. data/lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb +0 -40
  90. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb +0 -29
  91. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb +0 -40
  92. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb +0 -31
  93. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb +0 -26
  94. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb +0 -33
  95. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb +0 -31
  96. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb +0 -33
  97. data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb +0 -21
  98. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb +0 -60
  99. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb +0 -52
  100. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb +0 -72
  101. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb +0 -66
  102. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb +0 -64
  103. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb +0 -57
  104. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb +0 -50
  105. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb +0 -26
  106. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb +0 -107
  107. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb +0 -67
  108. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb +0 -43
  109. data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb +0 -77
  110. data/lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb +0 -94
  111. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb +0 -201
  112. data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb +0 -91
  113. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_exceptions_test.rb +0 -97
  114. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb +0 -23
  115. data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb +0 -172
  116. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb +0 -126
  117. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb +0 -143
  118. data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb +0 -33
  119. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po +0 -72
  120. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb +0 -3
  121. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml +0 -3
  122. data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb +0 -113
  123. data/lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb +0 -100
@@ -1,77 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
-
5
- class I18nBackendSimpleTest < Test::Unit::TestCase
6
- def setup
7
- I18n.backend = I18n::Backend::Simple.new
8
- I18n.load_path = [locales_dir + '/en.yml']
9
- end
10
-
11
- # useful because this way we can use the backend with no key for interpolation/pluralization
12
- define_method "test simple backend lookup: given nil as a key it returns nil" do
13
- assert_nil I18n.backend.send(:lookup, :en, nil)
14
- end
15
-
16
- # loading translations
17
-
18
- define_method "test simple load_translations: given an unknown file type it raises I18n::UnknownFileType" do
19
- assert_raises(I18n::UnknownFileType) { I18n.backend.load_translations("#{locales_dir}/en.xml") }
20
- end
21
-
22
- define_method "test simple load_translations: given a Ruby file name it does not raise anything" do
23
- assert_nothing_raised { I18n.backend.load_translations("#{locales_dir}/en.rb") }
24
- end
25
-
26
- define_method "test simple load_rb: loads data from a Ruby file" do
27
- data = I18n.backend.send(:load_rb, "#{locales_dir}/en.rb")
28
- assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
29
- end
30
-
31
- define_method "test simple load_yml: loads data from a YAML file" do
32
- data = I18n.backend.send(:load_yml, "#{locales_dir}/en.yml")
33
- assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
34
- end
35
-
36
- define_method "test simple load_translations: loads data from known file formats" do
37
- I18n.backend = I18n::Backend::Simple.new
38
- I18n.backend.load_translations("#{locales_dir}/en.rb", "#{locales_dir}/en.yml")
39
- expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
40
- assert_equal expected, translations
41
- end
42
-
43
- # storing translations
44
-
45
- define_method "test simple store_translations: stores translations, ... no, really :-)" do
46
- I18n.backend.store_translations :'en', :foo => 'bar'
47
- assert_equal Hash[:'en', {:foo => 'bar'}], translations
48
- end
49
-
50
- define_method "test simple store_translations: deep_merges with existing translations" do
51
- I18n.backend.store_translations :'en', :foo => {:bar => 'bar'}
52
- I18n.backend.store_translations :'en', :foo => {:baz => 'baz'}
53
- assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
54
- end
55
-
56
- define_method "test simple store_translations: converts the given locale to a Symbol" do
57
- I18n.backend.store_translations 'en', :foo => 'bar'
58
- assert_equal Hash[:'en', {:foo => 'bar'}], translations
59
- end
60
-
61
- define_method "test simple store_translations: converts keys to Symbols" do
62
- I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
63
- assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], translations
64
- end
65
-
66
- # reloading translations
67
-
68
- define_method "test simple reload_translations: unloads translations" do
69
- I18n.backend.reload!
70
- assert_nil translations
71
- end
72
-
73
- define_method "test simple reload_translations: uninitializes the backend" do
74
- I18n.backend.reload!
75
- assert_equal I18n.backend.initialized?, false
76
- end
77
- end
@@ -1,94 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
4
-
5
- # thanks to Masao's String extensions these should work the same in
6
- # Ruby 1.8 (patched) and Ruby 1.9 (native)
7
- # some tests taken from Masao's tests
8
- # http://github.com/mutoh/gettext/blob/edbbe1fa8238fa12c7f26f2418403015f0270e47/test/test_string.rb
9
-
10
- class I18nCoreExtStringInterpolationTest < Test::Unit::TestCase
11
- define_method "test: String interpolates a single argument" do
12
- assert_equal "Masao", "%s" % "Masao"
13
- end
14
-
15
- define_method "test: String interpolates an array argument" do
16
- assert_equal "1 message", "%d %s" % [1, 'message']
17
- end
18
-
19
- define_method "test: String interpolates a hash argument w/ named placeholders" do
20
- assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh' }
21
- end
22
-
23
- define_method "test: String interpolates a hash argument w/ named placeholders (reverse order)" do
24
- assert_equal "Mutoh, Masao", "%{last}, %{first}" % { :first => 'Masao', :last => 'Mutoh' }
25
- end
26
-
27
- define_method "test: String interpolates named placeholders with sprintf syntax" do
28
- assert_equal "10, 43.4", "%<integer>d, %<float>.1f" % {:integer => 10, :float => 43.4}
29
- end
30
-
31
- define_method "test: String interpolates named placeholders with sprintf syntax, does not recurse" do
32
- assert_equal "%<not_translated>s", "%{msg}" % { :msg => '%<not_translated>s', :not_translated => 'should not happen' }
33
- end
34
-
35
- define_method "test: String interpolation does not replace anything when no placeholders are given" do
36
- assert_equal("aaa", "aaa" % {:num => 1})
37
- assert_equal("bbb", "bbb" % [1])
38
- end
39
-
40
- define_method "test: String interpolation sprintf behaviour equals Ruby 1.9 behaviour" do
41
- assert_equal("1", "%<num>d" % {:num => 1})
42
- assert_equal("0b1", "%<num>#b" % {:num => 1})
43
- assert_equal("foo", "%<msg>s" % {:msg => "foo"})
44
- assert_equal("1.000000", "%<num>f" % {:num => 1.0})
45
- assert_equal(" 1", "%<num>3.0f" % {:num => 1.0})
46
- assert_equal("100.00", "%<num>2.2f" % {:num => 100.0})
47
- assert_equal("0x64", "%<num>#x" % {:num => 100.0})
48
- assert_raise(ArgumentError) { "%<num>,d" % {:num => 100} }
49
- assert_raise(ArgumentError) { "%<num>/d" % {:num => 100} }
50
- end
51
-
52
- define_method "test: String interpolation old-style sprintf still works" do
53
- assert_equal("foo 1.000000", "%s %f" % ["foo", 1.0])
54
- end
55
-
56
- define_method "test: String interpolation raises an ArgumentError when the string has extra placeholders (Array)" do
57
- assert_raises(ArgumentError) do # Ruby 1.9 msg: "too few arguments"
58
- "%s %s" % %w(Masao)
59
- end
60
- end
61
-
62
- define_method "test: String interpolation raises a KeyError when the string has extra placeholders (Hash)" do
63
- assert_raises(KeyError) do # Ruby 1.9 msg: "key not found"
64
- "%{first} %{last}" % { :first => 'Masao' }
65
- end
66
- end
67
-
68
- define_method "test: String interpolation does not raise when passed extra values (Array)" do
69
- assert_nothing_raised do
70
- assert_equal "Masao", "%s" % %w(Masao Mutoh)
71
- end
72
- end
73
-
74
- define_method "test: String interpolation does not raise when passed extra values (Hash)" do
75
- assert_nothing_raised do
76
- assert_equal "Masao Mutoh", "%{first} %{last}" % { :first => 'Masao', :last => 'Mutoh', :salutation => 'Mr.' }
77
- end
78
- end
79
-
80
- define_method "test: % acts as escape character in String interpolation" do
81
- assert_equal "%{first}", "%%{first}" % { :first => 'Masao' }
82
- assert_equal("% 1", "%% %<num>d" % {:num => 1.0})
83
- assert_equal("%{num} %<num>d", "%%{num} %%<num>d" % {:num => 1})
84
- end
85
-
86
- def test_sprintf_mix_unformatted_and_formatted_named_placeholders
87
- assert_equal("foo 1.000000", "%{name} %<num>f" % {:name => "foo", :num => 1.0})
88
- end
89
-
90
- def test_string_interpolation_raises_an_argument_error_when_mixing_named_and_unnamed_placeholders
91
- assert_raises(ArgumentError) { "%{name} %f" % [1.0] }
92
- assert_raises(ArgumentError) { "%{name} %f" % [1.0, 2.0] }
93
- end
94
- end
@@ -1,201 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
- require 'i18n/backend/gettext'
5
- require 'i18n/helpers/gettext'
6
-
7
- include I18n::Helpers::Gettext
8
-
9
- class I18nGettextApiTest < Test::Unit::TestCase
10
- def setup
11
- I18n.locale = :en
12
- I18n.backend.store_translations :de, {
13
- 'Hi Gettext!' => 'Hallo Gettext!',
14
- 'Sentence 1. Sentence 2.' => 'Satz 1. Satz 2.',
15
- "An apple" => { :one => 'Ein Apfel', :other => '{{count}} Äpfel' },
16
- :special => { "A special apple" => { :one => 'Ein spezieller Apfel', :other => '{{count}} spezielle Äpfel' } },
17
- :foo => { :bar => 'bar-de' }
18
- }
19
- end
20
-
21
- # gettext
22
- def test_gettext_uses_msg_as_default
23
- assert_equal 'Hi Gettext!', _('Hi Gettext!')
24
- end
25
-
26
- def test_gettext_uses_msg_as_key
27
- I18n.locale = :de
28
- assert_equal 'Hallo Gettext!', gettext('Hi Gettext!')
29
- assert_equal 'Hallo Gettext!', _('Hi Gettext!')
30
- end
31
-
32
- def test_gettext_uses_msg_containing_dots_as_default
33
- assert_equal 'Sentence 1. Sentence 2.', gettext('Sentence 1. Sentence 2.')
34
- assert_equal 'Sentence 1. Sentence 2.', _('Sentence 1. Sentence 2.')
35
- end
36
-
37
- def test_gettext_uses_msg_containing_dots_as_key
38
- I18n.locale = :de
39
- assert_equal 'Satz 1. Satz 2.', gettext('Sentence 1. Sentence 2.')
40
- assert_equal 'Satz 1. Satz 2.', _('Sentence 1. Sentence 2.')
41
- end
42
-
43
- # sgettext
44
- def test_sgettext_defaults_to_the_last_token_of_a_scoped_msgid
45
- assert_equal 'bar', sgettext('foo|bar')
46
- assert_equal 'bar', s_('foo|bar')
47
- end
48
-
49
- def test_sgettext_looks_up_a_scoped_translation
50
- I18n.locale = :de
51
- assert_equal 'bar-de', sgettext('foo|bar')
52
- assert_equal 'bar-de', s_('foo|bar')
53
- end
54
-
55
- # pgettext
56
- def test_pgettext_defaults_to_msgid
57
- assert_equal 'bar', pgettext('foo', 'bar')
58
- assert_equal 'bar', p_('foo', 'bar')
59
- end
60
-
61
- def test_pgettext_looks_up_a_scoped_translation
62
- I18n.locale = :de
63
- assert_equal 'bar-de', pgettext('foo', 'bar')
64
- assert_equal 'bar-de', p_('foo', 'bar')
65
- end
66
-
67
- # ngettext
68
- def test_ngettext_looks_up_msg_id_as_default_singular
69
- assert_equal 'An apple', ngettext('An apple', '{{count}} apples', 1)
70
- assert_equal 'An apple', n_('An apple', '{{count}} apples', 1)
71
- end
72
-
73
- def test_ngettext_looks_up_msg_id_plural_as_default_plural
74
- assert_equal '2 apples', ngettext('An apple', '{{count}} apples', 2)
75
- assert_equal '2 apples', n_('An apple', '{{count}} apples', 2)
76
- end
77
-
78
- def test_ngettext_looks_up_a_singular
79
- I18n.locale = :de
80
- assert_equal 'Ein Apfel', ngettext('An apple', '{{count}} apples', 1)
81
- assert_equal 'Ein Apfel', n_('An apple', '{{count}} apples', 1)
82
- end
83
-
84
- def test_ngettext_looks_up_a_plural
85
- I18n.locale = :de
86
- assert_equal '2 Äpfel', ngettext('An apple', '{{count}} apples', 2)
87
- assert_equal '2 Äpfel', n_('An apple', '{{count}} apples', 2)
88
- end
89
-
90
- def test_ngettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
91
- assert_equal 'An apple', ngettext(['An apple', '{{count}} apples'], 1)
92
- assert_equal 'An apple', n_(['An apple', '{{count}} apples'], 1)
93
- end
94
-
95
- def test_ngettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
96
- assert_equal '2 apples', ngettext(['An apple', '{{count}} apples'], 2)
97
- assert_equal '2 apples', n_(['An apple', '{{count}} apples'], 2)
98
- end
99
-
100
- def test_ngettext_looks_up_a_singular_with_alternative_syntax
101
- I18n.locale = :de
102
- assert_equal 'Ein Apfel', ngettext(['An apple', '{{count}} apples'], 1)
103
- assert_equal 'Ein Apfel', n_(['An apple', '{{count}} apples'], 1)
104
- end
105
-
106
- def test_ngettext_looks_up_a_plural_with_alternative_syntax
107
- I18n.locale = :de
108
- assert_equal '2 Äpfel', ngettext(['An apple', '{{count}} apples'], 2)
109
- assert_equal '2 Äpfel', n_(['An apple', '{{count}} apples'], 2)
110
- end
111
-
112
- # nsgettext
113
- def test_nsgettext_looks_up_msg_id_as_default_singular
114
- assert_equal 'A special apple', nsgettext('special|A special apple', '{{count}} special apples', 1)
115
- assert_equal 'A special apple', ns_('special|A special apple', '{{count}} special apples', 1)
116
- end
117
-
118
- def test_nsgettext_looks_up_msg_id_plural_as_default_plural
119
- assert_equal '2 special apples', nsgettext('special|A special apple', '{{count}} special apples', 2)
120
- assert_equal '2 special apples', ns_('special|A special apple', '{{count}} special apples', 2)
121
- end
122
-
123
- def test_nsgettext_looks_up_a_singular
124
- I18n.locale = :de
125
- assert_equal 'Ein spezieller Apfel', nsgettext('special|A special apple', '{{count}} special apples', 1)
126
- assert_equal 'Ein spezieller Apfel', ns_('special|A special apple', '{{count}} special apples', 1)
127
- end
128
-
129
- def test_nsgettext_looks_up_a_plural
130
- I18n.locale = :de
131
- assert_equal '2 spezielle Äpfel', nsgettext('special|A special apple', '{{count}} special apples', 2)
132
- assert_equal '2 spezielle Äpfel', ns_('special|A special apple', '{{count}} special apples', 2)
133
- end
134
-
135
- def test_nsgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
136
- assert_equal 'A special apple', nsgettext(['special|A special apple', '{{count}} special apples'], 1)
137
- assert_equal 'A special apple', ns_(['special|A special apple', '{{count}} special apples'], 1)
138
- end
139
-
140
- def test_nsgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
141
- assert_equal '2 special apples', nsgettext(['special|A special apple', '{{count}} special apples'], 2)
142
- assert_equal '2 special apples', ns_(['special|A special apple', '{{count}} special apples'], 2)
143
- end
144
-
145
- def test_nsgettext_looks_up_a_singular_with_alternative_syntax
146
- I18n.locale = :de
147
- assert_equal 'Ein spezieller Apfel', nsgettext(['special|A special apple', '{{count}} special apples'], 1)
148
- assert_equal 'Ein spezieller Apfel', ns_(['special|A special apple', '{{count}} special apples'], 1)
149
- end
150
-
151
- def test_nsgettext_looks_up_a_plural_with_alternative_syntax
152
- I18n.locale = :de
153
- assert_equal '2 spezielle Äpfel', nsgettext(['special|A special apple', '{{count}} special apples'], 2)
154
- assert_equal '2 spezielle Äpfel', ns_(['special|A special apple', '{{count}} special apples'], 2)
155
- end
156
-
157
- # npgettext
158
- def test_npgettext_looks_up_msg_id_as_default_singular
159
- assert_equal 'A special apple', npgettext('special', 'A special apple', '{{count}} special apples', 1)
160
- assert_equal 'A special apple', np_('special', 'A special apple', '{{count}} special apples', 1)
161
- end
162
-
163
- def test_npgettext_looks_up_msg_id_plural_as_default_plural
164
- assert_equal '2 special apples', npgettext('special', 'A special apple', '{{count}} special apples', 2)
165
- assert_equal '2 special apples', np_('special', 'A special apple', '{{count}} special apples', 2)
166
- end
167
-
168
- def test_npgettext_looks_up_a_singular
169
- I18n.locale = :de
170
- assert_equal 'Ein spezieller Apfel', npgettext('special', 'A special apple', '{{count}} special apples', 1)
171
- assert_equal 'Ein spezieller Apfel', np_('special', 'A special apple', '{{count}} special apples', 1)
172
- end
173
-
174
- def test_npgettext_looks_up_a_plural
175
- I18n.locale = :de
176
- assert_equal '2 spezielle Äpfel', npgettext('special', 'A special apple', '{{count}} special apples', 2)
177
- assert_equal '2 spezielle Äpfel', np_('special', 'A special apple', '{{count}} special apples', 2)
178
- end
179
-
180
- def test_npgettext_looks_up_msg_id_as_default_singular_with_alternative_syntax
181
- assert_equal 'A special apple', npgettext('special', ['A special apple', '{{count}} special apples'], 1)
182
- assert_equal 'A special apple', np_('special', ['A special apple', '{{count}} special apples'], 1)
183
- end
184
-
185
- def test_npgettext_looks_up_msg_id_plural_as_default_plural_with_alternative_syntax
186
- assert_equal '2 special apples', npgettext('special', ['A special apple', '{{count}} special apples'], 2)
187
- assert_equal '2 special apples', np_('special', ['A special apple', '{{count}} special apples'], 2)
188
- end
189
-
190
- def test_npgettext_looks_up_a_singular_with_alternative_syntax
191
- I18n.locale = :de
192
- assert_equal 'Ein spezieller Apfel', npgettext('special', ['A special apple', '{{count}} special apples'], 1)
193
- assert_equal 'Ein spezieller Apfel', np_('special', ['A special apple', '{{count}} special apples'], 1)
194
- end
195
-
196
- def test_npgettext_looks_up_a_plural_with_alternative_syntax
197
- I18n.locale = :de
198
- assert_equal '2 spezielle Äpfel', npgettext('special', ['A special apple', '{{count}} special apples'], 2)
199
- assert_equal '2 spezielle Äpfel', np_('special', ['A special apple', '{{count}} special apples'], 2)
200
- end
201
- end
@@ -1,91 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
4
- require 'i18n/backend/gettext'
5
- require 'i18n/helpers/gettext'
6
-
7
- class I18nGettextBackendTest < Test::Unit::TestCase
8
- include I18n::Helpers::Gettext
9
-
10
- class Backend
11
- include I18n::Backend::Base
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
- end
20
-
21
- def teardown
22
- I18n.load_path = nil
23
- I18n.backend = nil
24
- end
25
-
26
- def test_backend_loads_po_file
27
- I18n.backend.send(:init_translations)
28
- assert I18n.backend.send(:translations)[:de][:"Axis"]
29
- end
30
-
31
- def test_looks_up_a_translation
32
- I18n.locale = :de
33
- assert_equal 'Auto', gettext('car')
34
- end
35
-
36
- def test_uses_default_translation
37
- assert_equal 'car', gettext('car')
38
- end
39
-
40
- def test_looks_up_a_namespaced_translation
41
- I18n.locale = :de
42
- assert_equal 'Räderzahl', sgettext('Car|Wheels count')
43
- assert_equal 'Räderzahl', pgettext('Car', 'Wheels count')
44
- end
45
-
46
- def test_uses_namespaced_default_translation
47
- assert_equal 'Wheels count', sgettext('Car|Wheels count')
48
- assert_equal 'Wheels count', pgettext('Car', 'Wheels count')
49
- end
50
-
51
- def test_pluralizes_entry
52
- I18n.locale = :de
53
- assert_equal 'Achse', ngettext('Axis', 'Axis', 1)
54
- assert_equal 'Achsen', ngettext('Axis', 'Axis', 2)
55
- end
56
-
57
- def test_pluralizes_default_entry
58
- assert_equal 'Axis', ngettext('Axis', 'Axis', 1)
59
- assert_equal 'Axis', ngettext('Axis', 'Axis', 2)
60
- end
61
-
62
- def test_pluralizes_namespaced_entry
63
- I18n.locale = :de
64
- assert_equal 'Rad', nsgettext('Car|wheel', 'wheels', 1)
65
- assert_equal 'Räder', nsgettext('Car|wheel', 'wheels', 2)
66
- assert_equal 'Rad', npgettext('Car', 'wheel', 'wheels', 1)
67
- assert_equal 'Räder', npgettext('Car', 'wheel', 'wheels', 2)
68
- end
69
-
70
- def test_pluralizes_namespaced_default_entry
71
- assert_equal 'wheel', nsgettext('Car|wheel', 'wheels', 1)
72
- assert_equal 'wheels', nsgettext('Car|wheel', 'wheels', 2)
73
- assert_equal 'wheel', npgettext('Car', 'wheel', 'wheels', 1)
74
- assert_equal 'wheels', npgettext('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
- end
84
-
85
- def test_ngettextpluralizes_entry_with_dots
86
- I18n.locale = :de
87
- assert_equal 'Auf 1 Achse.', n_("On %{count} wheel.", "On %{count} wheels.", 1)
88
- assert_equal 'Auf 2 Achsen.', n_("On %{count} wheel.", "On %{count} wheels.", 2)
89
- end
90
-
91
- end