i18n 0.2.1 → 0.3.0

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 (77) hide show
  1. data/README.textile +44 -9
  2. data/Rakefile +2 -1
  3. data/VERSION +1 -1
  4. data/lib/i18n.rb +60 -15
  5. data/lib/i18n/backend.rb +14 -0
  6. data/lib/i18n/backend/active_record.rb +69 -0
  7. data/lib/i18n/backend/active_record/store_procs.rb +37 -0
  8. data/lib/i18n/backend/active_record/translation.rb +82 -0
  9. data/lib/i18n/backend/active_record_missing.rb +55 -0
  10. data/lib/i18n/backend/base.rb +235 -0
  11. data/lib/i18n/backend/cache.rb +71 -0
  12. data/lib/i18n/backend/chain.rb +74 -0
  13. data/lib/i18n/backend/fallbacks.rb +51 -0
  14. data/lib/i18n/backend/gettext.rb +75 -0
  15. data/lib/i18n/backend/helpers.rb +53 -0
  16. data/lib/i18n/backend/metadata.rb +73 -0
  17. data/lib/i18n/backend/pluralization.rb +57 -0
  18. data/lib/i18n/backend/simple.rb +15 -227
  19. data/lib/i18n/core_ext/object/meta_class.rb +5 -0
  20. data/lib/i18n/{string.rb → core_ext/string/interpolate.rb} +2 -0
  21. data/lib/i18n/exceptions.rb +2 -0
  22. data/lib/i18n/gettext.rb +25 -0
  23. data/lib/i18n/helpers.rb +5 -0
  24. data/lib/i18n/helpers/gettext.rb +64 -0
  25. data/lib/i18n/locale.rb +6 -0
  26. data/lib/i18n/locale/fallbacks.rb +98 -0
  27. data/lib/i18n/locale/tag.rb +28 -0
  28. data/lib/i18n/locale/tag/parents.rb +24 -0
  29. data/lib/i18n/locale/tag/rfc4646.rb +76 -0
  30. data/lib/i18n/locale/tag/simple.rb +41 -0
  31. data/test/all.rb +7 -2
  32. data/test/api/basics.rb +3 -1
  33. data/test/api/interpolation.rb +35 -4
  34. data/test/api/lambda.rb +5 -3
  35. data/test/api/link.rb +4 -2
  36. data/test/api/localization/date.rb +2 -0
  37. data/test/api/localization/date_time.rb +3 -1
  38. data/test/api/localization/lambda.rb +4 -2
  39. data/test/api/localization/time.rb +3 -1
  40. data/test/api/pluralization.rb +12 -15
  41. data/test/api/translation.rb +5 -3
  42. data/test/backend/active_record/active_record_test.rb +40 -0
  43. data/test/backend/active_record/all.rb +3 -0
  44. data/test/backend/active_record/api_test.rb +54 -0
  45. data/test/backend/active_record/setup.rb +166 -0
  46. data/test/backend/active_record_missing/active_record_missing_test.rb +63 -0
  47. data/test/backend/all/api_test.rb +88 -0
  48. data/test/backend/cache/cache_test.rb +69 -0
  49. data/test/backend/chain/api_test.rb +80 -0
  50. data/test/backend/chain/chain_test.rb +64 -0
  51. data/test/backend/fallbacks/api_test.rb +84 -0
  52. data/test/backend/fallbacks/fallbacks_test.rb +57 -0
  53. data/test/backend/metadata/metadata_test.rb +65 -0
  54. data/test/backend/pluralization/api_test.rb +86 -0
  55. data/test/backend/pluralization/pluralization_test.rb +43 -0
  56. data/test/backend/simple/all.rb +2 -0
  57. data/test/backend/simple/api_test.rb +27 -20
  58. data/test/backend/simple/helpers_test.rb +26 -0
  59. data/test/backend/simple/lookup_test.rb +2 -1
  60. data/test/backend/simple/{setup/localization.rb → setup.rb} +29 -11
  61. data/test/backend/simple/translations_test.rb +1 -6
  62. data/test/{string_test.rb → core_ext/string/interpolate_test.rb} +4 -2
  63. data/test/fixtures/locales/de.po +67 -0
  64. data/test/fixtures/locales/en.rb +2 -0
  65. data/test/fixtures/locales/plurals.rb +113 -0
  66. data/test/gettext/api_test.rb +204 -0
  67. data/test/gettext/backend_test.rb +84 -0
  68. data/test/i18n_exceptions_test.rb +3 -1
  69. data/test/i18n_load_path_test.rb +8 -1
  70. data/test/i18n_test.rb +30 -7
  71. data/test/locale/fallbacks_test.rb +128 -0
  72. data/test/locale/tag/rfc4646_test.rb +145 -0
  73. data/test/locale/tag/simple_test.rb +35 -0
  74. data/test/test_helper.rb +11 -5
  75. data/test/with_options.rb +2 -0
  76. metadata +75 -11
  77. data/test/backend/simple/setup/base.rb +0 -21
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
4
 
3
5
  class I18nExceptionsTest < Test::Unit::TestCase
@@ -92,4 +94,4 @@ class I18nExceptionsTest < Test::Unit::TestCase
92
94
  I18n.backend.store_translations 'de', :foo => "{{scope}}"
93
95
  I18n.backend.translate 'de', :foo, :baz => 'baz'
94
96
  end
95
- end
97
+ end
@@ -1,8 +1,15 @@
1
1
  # encoding: utf-8
2
+
2
3
  require File.expand_path(File.dirname(__FILE__) + '/test_helper')
3
4
 
4
5
  class I18nLoadPathTest < Test::Unit::TestCase
5
- include Tests::Backend::Simple::Setup::Base
6
+ # include Tests::Backend::Simple::Setup::Base
7
+
8
+ def setup
9
+ I18n.locale = :en
10
+ I18n.backend = I18n::Backend::Simple.new
11
+ backend_store_translations(:en, :foo => {:bar => 'bar', :baz => 'baz'})
12
+ end
6
13
 
7
14
  def test_nested_load_paths_do_not_break_locale_loading
8
15
  I18n.load_path = [[locales_dir + '/en.yml']]
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
4
 
3
5
  class I18nTest < Test::Unit::TestCase
@@ -23,13 +25,13 @@ class I18nTest < Test::Unit::TestCase
23
25
  end
24
26
 
25
27
  def test_uses_en_us_as_default_locale_by_default
26
- assert_equal 'en', I18n.default_locale
28
+ assert_equal :en, I18n.default_locale
27
29
  end
28
30
 
29
31
  def test_can_set_default_locale
30
32
  assert_nothing_raised { I18n.default_locale = 'de' }
31
- assert_equal 'de', I18n.default_locale
32
- I18n.default_locale = 'en'
33
+ assert_equal :de, I18n.default_locale
34
+ I18n.default_locale = :en
33
35
  end
34
36
 
35
37
  def test_uses_default_locale_as_locale_by_default
@@ -38,9 +40,9 @@ class I18nTest < Test::Unit::TestCase
38
40
 
39
41
  def test_can_set_locale_to_thread_current
40
42
  assert_nothing_raised { I18n.locale = 'de' }
41
- assert_equal 'de', I18n.locale
42
- assert_equal 'de', Thread.current[:locale]
43
- I18n.locale = 'en'
43
+ assert_equal :de, I18n.locale
44
+ assert_equal :de, Thread.current[:locale]
45
+ I18n.locale = :en
44
46
  end
45
47
 
46
48
  def test_defaults_to_dot_as_separator
@@ -87,7 +89,7 @@ class I18nTest < Test::Unit::TestCase
87
89
  end
88
90
 
89
91
  def test_translate_given_no_locale_uses_i18n_locale
90
- I18n.backend.expects(:translate).with 'en', :foo, {}
92
+ I18n.backend.expects(:translate).with :en, :foo, {}
91
93
  I18n.translate :foo
92
94
  end
93
95
 
@@ -137,4 +139,25 @@ class I18nTest < Test::Unit::TestCase
137
139
  def test_localize_object_raises_argument_error
138
140
  assert_raises(I18n::ArgumentError) { I18n.l Object.new }
139
141
  end
142
+
143
+ def test_proc_exception_handler
144
+ I18n.exception_handler = Proc.new { |exception, locale, key, options|
145
+ "No exception here! [Proc handler]"
146
+ }
147
+ assert_equal "No exception here! [Proc handler]", I18n.translate(:test_proc_handler)
148
+ ensure
149
+ I18n.exception_handler = :default_exception_handler
150
+ end
151
+
152
+ def test_class_exception_handler
153
+ I18n.exception_handler = Class.new do
154
+ def call(exception, locale, key, options)
155
+ "No exception here! [Class handler]"
156
+ end
157
+ end.new
158
+ assert_equal "No exception here! [Class handler]", I18n.translate(:test_class_handler)
159
+ ensure
160
+ I18n.exception_handler = :default_exception_handler
161
+ end
162
+
140
163
  end
@@ -0,0 +1,128 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../test_helper.rb'
4
+ require 'i18n/locale/fallbacks'
5
+ require 'i18n/locale/tag'
6
+
7
+ include I18n::Locale
8
+
9
+ class I18nFallbacksDefaultsTest < Test::Unit::TestCase
10
+ def teardown
11
+ I18n.default_locale = :en
12
+ end
13
+
14
+ test "defaults reflect the I18n.default_locale if no default has been set manually" do
15
+ I18n.default_locale = :'en-US'
16
+ fallbacks = Fallbacks.new
17
+ assert_equal [:'en-US', :en], fallbacks.defaults
18
+ end
19
+
20
+ test "defaults reflect a manually passed default locale if any" do
21
+ fallbacks = Fallbacks.new(:'fi-FI')
22
+ assert_equal [:'fi-FI', :fi], fallbacks.defaults
23
+ I18n.default_locale = :'de-DE'
24
+ assert_equal [:'fi-FI', :fi], fallbacks.defaults
25
+ end
26
+
27
+ test "defaults allows to set multiple defaults" do
28
+ fallbacks = Fallbacks.new(:'fi-FI', :'se-FI')
29
+ assert_equal [:'fi-FI', :fi, :'se-FI', :se], fallbacks.defaults
30
+ end
31
+ end
32
+
33
+ class I18nFallbacksComputationTest < Test::Unit::TestCase
34
+ def setup
35
+ @fallbacks = Fallbacks.new(:'en-US')
36
+ end
37
+
38
+ test "with no mappings defined it returns [:es, :en-US] for :es" do
39
+ assert_equal [:es, :"en-US", :en], @fallbacks[:es]
40
+ end
41
+
42
+ test "with no mappings defined it returns [:es-ES, :es, :en-US] for :es-ES" do
43
+ assert_equal [:"es-ES", :es, :"en-US", :en], @fallbacks[:"es-ES"]
44
+ end
45
+
46
+ test "with no mappings defined it returns [:es-MX, :es, :en-US] for :es-MX" do
47
+ assert_equal [:"es-MX", :es, :"en-US", :en], @fallbacks[:"es-MX"]
48
+ end
49
+
50
+ test "with no mappings defined it returns [:es-Latn-ES, :es-Latn, :es, :en-US] for :es-Latn-ES" do
51
+ assert_equal [:"es-Latn-ES", :"es-Latn", :es, :"en-US", :en], @fallbacks[:'es-Latn-ES']
52
+ end
53
+
54
+ test "with no mappings defined it returns [:en, :en-US] for :en" do
55
+ assert_equal [:en, :"en-US"], @fallbacks[:en]
56
+ end
57
+
58
+ test "with no mappings defined it returns [:en-US, :en] for :en-US (special case: locale == default)" do
59
+ assert_equal [:"en-US", :en], @fallbacks[:"en-US"]
60
+ end
61
+
62
+ # Most people who speak Catalan also live in Spain, so it is safe to assume
63
+ # that they also speak Spanish as spoken in Spain.
64
+ test "with a Catalan mapping defined it returns [:ca, :es-ES, :es, :en-US] for :ca" do
65
+ @fallbacks.map(:ca => :"es-ES")
66
+ assert_equal [:ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:ca]
67
+ end
68
+
69
+ test "with a Catalan mapping defined it returns [:ca-ES, :ca, :es-ES, :es, :en-US] for :ca-ES" do
70
+ @fallbacks.map(:ca => :"es-ES")
71
+ assert_equal [:"ca-ES", :ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:"ca-ES"]
72
+ end
73
+
74
+ # People who speak Arabic as spoken in Palestine often times also speak
75
+ # Hebrew as spoken in Israel. However it is in no way safe to assume that
76
+ # everybody who speaks Arabic also speaks Hebrew.
77
+
78
+ test "with a Hebrew mapping defined it returns [:ar, :en-US] for :ar" do
79
+ @fallbacks.map(:"ar-PS" => :"he-IL")
80
+ assert_equal [:ar, :"en-US", :en], @fallbacks[:ar]
81
+ end
82
+
83
+ test "with a Hebrew mapping defined it returns [:ar-EG, :ar, :en-US] for :ar-EG" do
84
+ @fallbacks.map(:"ar-PS" => :"he-IL")
85
+ assert_equal [:"ar-EG", :ar, :"en-US", :en], @fallbacks[:"ar-EG"]
86
+ end
87
+
88
+ test "with a Hebrew mapping defined it returns [:ar-PS, :ar, :he-IL, :he, :en-US] for :ar-PS" do
89
+ @fallbacks.map(:"ar-PS" => :"he-IL")
90
+ assert_equal [:"ar-PS", :ar, :"he-IL", :he, :"en-US", :en], @fallbacks[:"ar-PS"]
91
+ end
92
+
93
+ # Sami people live in several scandinavian countries. In Finnland many people
94
+ # know Swedish and Finnish. Thus, it can be assumed that Sami living in
95
+ # Finnland also speak Swedish and Finnish.
96
+
97
+ test "with a Sami mapping defined it returns [:sms-FI, :sms, :se-FI, :se, :fi-FI, :fi, :en-US] for :sms-FI" do
98
+ @fallbacks.map(:sms => [:"se-FI", :"fi-FI"])
99
+ assert_equal [:"sms-FI", :sms, :"se-FI", :se, :"fi-FI", :fi, :"en-US", :en], @fallbacks[:"sms-FI"]
100
+ end
101
+
102
+ # Austrian people understand German as spoken in Germany
103
+
104
+ test "with a German mapping defined it returns [:de, :en-US] for de" do
105
+ @fallbacks.map(:"de-AT" => :"de-DE")
106
+ assert_equal [:de, :"en-US", :en], @fallbacks[:"de"]
107
+ end
108
+
109
+ test "with a German mapping defined it returns [:de-DE, :de, :en-US] for de-DE" do
110
+ @fallbacks.map(:"de-AT" => :"de-DE")
111
+ assert_equal [:"de-DE", :de, :"en-US", :en], @fallbacks[:"de-DE"]
112
+ end
113
+
114
+ test "with a German mapping defined it returns [:de-AT, :de, :de-DE, :en-US] for de-AT" do
115
+ @fallbacks.map(:"de-AT" => :"de-DE")
116
+ assert_equal [:"de-AT", :de, :"de-DE", :"en-US", :en], @fallbacks[:"de-AT"]
117
+ end
118
+
119
+ # Mapping :de => :en, :he => :en
120
+
121
+ test "with a mapping :de => :en, :he => :en defined it returns [:de, :en] for :de" do
122
+ assert_equal [:de, :"en-US", :en], @fallbacks[:de]
123
+ end
124
+
125
+ test "with a mapping :de => :en, :he => :en defined it [:he, :en] for :de" do
126
+ assert_equal [:he, :"en-US", :en], @fallbacks[:he]
127
+ end
128
+ end
@@ -0,0 +1,145 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../../test_helper.rb'
4
+
5
+ # Rfc4646::Parser
6
+
7
+ class I18nLocaleTagRfc4646ParserTest < Test::Unit::TestCase
8
+ include I18n::Locale
9
+
10
+ test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
11
+ assert_equal ['de', nil, nil, nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de')
12
+ end
13
+
14
+ test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
15
+ assert_equal ['de', nil, 'DE', nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de-DE')
16
+ end
17
+
18
+ test "Rfc4646::Parser given a valid lowercase tag 'de-latn-de-variant-x-phonebk' returns an array of subtags" do
19
+ assert_equal ['de', 'latn', 'de', 'variant', nil, 'x-phonebk', nil], Tag::Rfc4646::Parser.match('de-latn-de-variant-x-phonebk')
20
+ end
21
+
22
+ test "Rfc4646::Parser given a valid uppercase tag 'DE-LATN-DE-VARIANT-X-PHONEBK' returns an array of subtags" do
23
+ assert_equal ['DE', 'LATN', 'DE', 'VARIANT', nil, 'X-PHONEBK', nil], Tag::Rfc4646::Parser.match('DE-LATN-DE-VARIANT-X-PHONEBK')
24
+ end
25
+
26
+ test "Rfc4646::Parser given an invalid tag 'a-DE' it returns false" do
27
+ assert_equal false, Tag::Rfc4646::Parser.match('a-DE')
28
+ end
29
+
30
+ test "Rfc4646::Parser given an invalid tag 'de-419-DE' it returns false" do
31
+ assert_equal false, Tag::Rfc4646::Parser.match('de-419-DE')
32
+ end
33
+ end
34
+
35
+ # Tag for the locale 'de-Latn-DE-Variant-a-ext-x-phonebk-i-klingon'
36
+
37
+ class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
38
+ include I18n::Locale
39
+
40
+ def setup
41
+ subtags = %w(de Latn DE variant a-ext x-phonebk i-klingon)
42
+ @tag = Tag::Rfc4646.new *subtags
43
+ end
44
+
45
+ test "returns 'de' as the language subtag in lowercase" do
46
+ assert_equal 'de', @tag.language
47
+ end
48
+
49
+ test "returns 'Latn' as the script subtag in titlecase" do
50
+ assert_equal 'Latn', @tag.script
51
+ end
52
+
53
+ test "returns 'DE' as the region subtag in uppercase" do
54
+ assert_equal 'DE', @tag.region
55
+ end
56
+
57
+ test "returns 'variant' as the variant subtag in lowercase" do
58
+ assert_equal 'variant', @tag.variant
59
+ end
60
+
61
+ test "returns 'a-ext' as the extension subtag" do
62
+ assert_equal 'a-ext', @tag.extension
63
+ end
64
+
65
+ test "returns 'x-phonebk' as the privateuse subtag" do
66
+ assert_equal 'x-phonebk', @tag.privateuse
67
+ end
68
+
69
+ test "returns 'i-klingon' as the grandfathered subtag" do
70
+ assert_equal 'i-klingon', @tag.grandfathered
71
+ end
72
+
73
+ test "returns a formatted tag string from #to_s" do
74
+ assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon', @tag.to_s
75
+ end
76
+
77
+ test "returns an array containing the formatted subtags from #to_a" do
78
+ assert_equal %w(de Latn DE variant a-ext x-phonebk i-klingon), @tag.to_a
79
+ end
80
+ end
81
+
82
+ # Tag inheritance
83
+
84
+ class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
85
+ test "#parent returns 'de-Latn-DE-variant-a-ext-x-phonebk' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
86
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
87
+ assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk', tag.parent.to_s
88
+ end
89
+
90
+ test "#parent returns 'de-Latn-DE-variant-a-ext' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk'" do
91
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk)
92
+ assert_equal 'de-Latn-DE-variant-a-ext', tag.parent.to_s
93
+ end
94
+
95
+ test "#parent returns 'de-Latn-DE-variant' as the parent of 'de-Latn-DE-variant-a-ext'" do
96
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext)
97
+ assert_equal 'de-Latn-DE-variant', tag.parent.to_s
98
+ end
99
+
100
+ test "#parent returns 'de-Latn-DE' as the parent of 'de-Latn-DE-variant'" do
101
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant)
102
+ assert_equal 'de-Latn-DE', tag.parent.to_s
103
+ end
104
+
105
+ test "#parent returns 'de-Latn' as the parent of 'de-Latn-DE'" do
106
+ tag = Tag::Rfc4646.new *%w(de Latn DE)
107
+ assert_equal 'de-Latn', tag.parent.to_s
108
+ end
109
+
110
+ test "#parent returns 'de' as the parent of 'de-Latn'" do
111
+ tag = Tag::Rfc4646.new *%w(de Latn)
112
+ assert_equal 'de', tag.parent.to_s
113
+ end
114
+
115
+ # TODO RFC4647 says: "If no language tag matches the request, the "default" value is returned."
116
+ # where should we set the default language?
117
+ # test "#parent returns '' as the parent of 'de'" do
118
+ # tag = Tag::Rfc4646.new *%w(de)
119
+ # assert_equal '', tag.parent.to_s
120
+ # end
121
+
122
+ test "#parent returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
123
+ parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
124
+ de-Latn-DE-variant-a-ext-x-phonebk
125
+ de-Latn-DE-variant-a-ext
126
+ de-Latn-DE-variant
127
+ de-Latn-DE
128
+ de-Latn
129
+ de)
130
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
131
+ assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
132
+ end
133
+
134
+ test "returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
135
+ parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
136
+ de-Latn-DE-variant-a-ext-x-phonebk
137
+ de-Latn-DE-variant-a-ext
138
+ de-Latn-DE-variant
139
+ de-Latn-DE
140
+ de-Latn
141
+ de)
142
+ tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
143
+ assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
144
+ end
145
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ require File.dirname(__FILE__) + '/../../test_helper.rb'
4
+ require 'i18n/locale/tag'
5
+ require 'i18n/locale/tag/simple'
6
+
7
+ class I18nLocaleTagSimpleTest < Test::Unit::TestCase
8
+ include I18n::Locale
9
+
10
+ test "returns 'de' as the language subtag in lowercase" do
11
+ assert_equal %w(de Latn DE), Tag::Simple.new('de-Latn-DE').subtags
12
+ end
13
+
14
+ test "returns a formatted tag string from #to_s" do
15
+ assert_equal 'de-Latn-DE', Tag::Simple.new('de-Latn-DE').to_s
16
+ end
17
+
18
+ test "returns an array containing the formatted subtags from #to_a" do
19
+ assert_equal %w(de Latn DE), Tag::Simple.new('de-Latn-DE').to_a
20
+ end
21
+
22
+ # Tag inheritance
23
+
24
+ test "#parent returns 'de-Latn' as the parent of 'de-Latn-DE'" do
25
+ assert_equal 'de-Latn', Tag::Simple.new('de-Latn-DE').parent.to_s
26
+ end
27
+
28
+ test "#parent returns 'de' as the parent of 'de-Latn'" do
29
+ assert_equal 'de', Tag::Simple.new('de-Latn').parent.to_s
30
+ end
31
+
32
+ test "#self_and_parents returns an array of 3 tags for 'de-Latn-DE'" do
33
+ assert_equal %w(de-Latn-DE de-Latn de), Tag::Simple.new('de-Latn-DE').self_and_parents.map { |tag| tag.to_s}
34
+ end
35
+ end
@@ -1,28 +1,34 @@
1
1
  # encoding: utf-8
2
+
2
3
  $:.unshift "lib"
3
4
 
4
5
  require 'rubygems'
5
6
  require 'test/unit'
6
7
  require 'mocha'
7
8
  require 'i18n'
9
+ require 'i18n/core_ext/object/meta_class'
8
10
  require 'time'
9
11
  require 'yaml'
10
12
 
11
13
  require File.dirname(__FILE__) + '/with_options'
12
- require File.dirname(__FILE__) + '/backend/simple/setup/base'
13
- require File.dirname(__FILE__) + '/backend/simple/setup/localization'
14
+ require File.dirname(__FILE__) + '/backend/simple/setup'
15
+ require File.dirname(__FILE__) + '/backend/active_record/setup'
14
16
 
15
17
  Dir[File.dirname(__FILE__) + '/api/**/*.rb'].each do |filename|
16
18
  require filename
17
19
  end
18
20
 
19
21
  $KCODE = 'u' unless RUBY_VERSION >= '1.9'
20
-
22
+
21
23
  class Test::Unit::TestCase
24
+ def self.test(name, &block)
25
+ define_method("test: " + name, &block)
26
+ end
27
+
22
28
  def euc_jp(string)
23
29
  string.encode!(Encoding::EUC_JP)
24
30
  end
25
-
31
+
26
32
  def locales_dir
27
33
  File.dirname(__FILE__) + '/fixtures/locales'
28
34
  end
@@ -56,4 +62,4 @@ class Test::Unit::TestCase
56
62
  def evening_time
57
63
  Time.parse('2008-03-01 18:00 UTC')
58
64
  end
59
- end
65
+ end