i18n 0.2.0 → 0.2.1

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.

@@ -1,23 +1,23 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
3
-
4
- class I18nSimpleBackendLookupTest < Test::Unit::TestCase
5
- include Tests::Backend::Simple::Setup::Base
6
-
7
- # useful because this way we can use the backend with no key for interpolation/pluralization
8
- def test_lookup_given_nil_as_a_key_returns_nil
9
- assert_nil I18n.backend.send(:lookup, :en, nil)
10
- end
11
-
12
- def test_lookup_given_nested_keys_looks_up_a_nested_hash_value
13
- assert_equal 'bar', I18n.backend.send(:lookup, :en, :bar, [:foo])
14
- end
15
-
16
- def test_lookup_using_a_custom_separator
17
- assert_equal 'bar', I18n.backend.send(:lookup, :en, 'foo|bar', [], '|')
18
- end
19
-
20
- def test_default_using_a_custom_separator
21
- assert_equal 'bar', I18n.backend.send(:default, :en, :'does_not_exist', :'foo|bar', :separator => '|')
22
- end
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
3
+
4
+ class I18nSimpleBackendLookupTest < Test::Unit::TestCase
5
+ include Tests::Backend::Simple::Setup::Base
6
+
7
+ # useful because this way we can use the backend with no key for interpolation/pluralization
8
+ def test_lookup_given_nil_as_a_key_returns_nil
9
+ assert_nil I18n.backend.send(:lookup, :en, nil)
10
+ end
11
+
12
+ def test_lookup_given_nested_keys_looks_up_a_nested_hash_value
13
+ assert_equal 'bar', I18n.backend.send(:lookup, :en, :bar, [:foo])
14
+ end
15
+
16
+ def test_lookup_using_a_custom_separator
17
+ assert_equal 'bar', I18n.backend.send(:lookup, :en, 'foo|bar', [], '|')
18
+ end
19
+
20
+ def test_default_using_a_custom_separator
21
+ assert_equal 'bar', I18n.backend.send(:default, :en, :'does_not_exist', :'foo|bar', :separator => '|')
22
+ end
23
23
  end
@@ -1,21 +1,21 @@
1
- module Tests
2
- module Backend
3
- module Simple
4
- module Setup
5
- module Base
6
- def setup
7
- super
8
- I18n.backend = I18n::Backend::Simple.new
9
- backend_store_translations :en, :foo => {:bar => 'bar', :baz => 'baz'}
10
- end
11
-
12
- def teardown
13
- super
14
- I18n.load_path = []
15
- I18n.backend = nil
16
- end
17
- end
18
- end
19
- end
20
- end
1
+ module Tests
2
+ module Backend
3
+ module Simple
4
+ module Setup
5
+ module Base
6
+ def setup
7
+ super
8
+ I18n.backend = I18n::Backend::Simple.new
9
+ backend_store_translations :en, :foo => {:bar => 'bar', :baz => 'baz'}
10
+ end
11
+
12
+ def teardown
13
+ super
14
+ I18n.load_path = []
15
+ I18n.backend = nil
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
21
  end
@@ -1,129 +1,129 @@
1
- module Tests
2
- module Backend
3
- module Simple
4
- module Setup
5
- module Localization
6
- include Base
7
-
8
- def setup
9
- super
10
- setup_datetime_translations
11
- setup_datetime_lambda_translations
12
- @old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
13
- end
14
-
15
- def teardown
16
- super
17
- @old_timezone ? ENV['TZ'] = @old_timezone : ENV.delete('TZ')
18
- end
19
-
20
- def setup_datetime_translations
21
- backend_store_translations :de, {
22
- :date => {
23
- :formats => {
24
- :default => "%d.%m.%Y",
25
- :short => "%d. %b",
26
- :long => "%d. %B %Y",
27
- :long_ordinalized => lambda { |date, options|
28
- tz = " (#{options[:timezone]})" if options[:timezone]
29
- "#{date.day}ter %B %Y#{tz}"
30
- }
31
- },
32
- :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
33
- :abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
34
- :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
35
- :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil),
36
- :order => [:day, :month, :year]
37
- },
38
- :time => {
39
- :formats => {
40
- :default => "%a, %d. %b %Y %H:%M:%S %z",
41
- :short => "%d. %b %H:%M",
42
- :long => "%d. %B %Y %H:%M",
43
- :long_ordinalized => lambda { |date, options|
44
- tz = " (#{options[:timezone]})" if options[:timezone]
45
- "#{date.day}ter %B %Y, %H:%M Uhr#{tz}"
46
- }
47
- },
48
- :am => 'am',
49
- :pm => 'pm'
50
- },
51
- :datetime => {
52
- :distance_in_words => {
53
- :half_a_minute => 'half a minute',
54
- :less_than_x_seconds => {
55
- :one => 'less than 1 second',
56
- :other => 'less than {{count}} seconds'
57
- },
58
- :x_seconds => {
59
- :one => '1 second',
60
- :other => '{{count}} seconds'
61
- },
62
- :less_than_x_minutes => {
63
- :one => 'less than a minute',
64
- :other => 'less than {{count}} minutes'
65
- },
66
- :x_minutes => {
67
- :one => '1 minute',
68
- :other => '{{count}} minutes'
69
- },
70
- :about_x_hours => {
71
- :one => 'about 1 hour',
72
- :other => 'about {{count}} hours'
73
- },
74
- :x_days => {
75
- :one => '1 day',
76
- :other => '{{count}} days'
77
- },
78
- :about_x_months => {
79
- :one => 'about 1 month',
80
- :other => 'about {{count}} months'
81
- },
82
- :x_months => {
83
- :one => '1 month',
84
- :other => '{{count}} months'
85
- },
86
- :about_x_years => {
87
- :one => 'about 1 year',
88
- :other => 'about {{count}} year'
89
- },
90
- :over_x_years => {
91
- :one => 'over 1 year',
92
- :other => 'over {{count}} years'
93
- }
94
- }
95
- }
96
- }
97
- end
98
-
99
- def setup_datetime_lambda_translations
100
- backend_store_translations 'ru', {
101
- :date => {
102
- :'day_names' => lambda { |key, options|
103
- (options[:format] =~ /^%A/) ?
104
- %w(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота) :
105
- %w(воскресенье понедельник вторник среда четверг пятница суббота)
106
- },
107
- :'abbr_day_names' => %w(Вс Пн Вт Ср Чт Пт Сб),
108
- :'month_names' => lambda { |key, options|
109
- (options[:format] =~ /(%d|%e)(\s*)?(%B)/) ?
110
- %w(января февраля марта апреля мая июня июля августа сентября октября ноября декабря).unshift(nil) :
111
- %w(Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь).unshift(nil)
112
- },
113
- :'abbr_month_names' => lambda { |key, options|
114
- (options[:format] =~ /(%d|%e)(\s*)(%b)/) ?
115
- %w(янв. февр. марта апр. мая июня июля авг. сент. окт. нояб. дек.).unshift(nil) :
116
- %w(янв. февр. март апр. май июнь июль авг. сент. окт. нояб. дек.).unshift(nil)
117
- },
118
- },
119
- :time => {
120
- :am => "утра",
121
- :pm => "вечера"
122
- }
123
- }
124
- end
125
- end
126
- end
127
- end
128
- end
1
+ module Tests
2
+ module Backend
3
+ module Simple
4
+ module Setup
5
+ module Localization
6
+ include Base
7
+
8
+ def setup
9
+ super
10
+ setup_datetime_translations
11
+ setup_datetime_lambda_translations
12
+ @old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
13
+ end
14
+
15
+ def teardown
16
+ super
17
+ @old_timezone ? ENV['TZ'] = @old_timezone : ENV.delete('TZ')
18
+ end
19
+
20
+ def setup_datetime_translations
21
+ backend_store_translations :de, {
22
+ :date => {
23
+ :formats => {
24
+ :default => "%d.%m.%Y",
25
+ :short => "%d. %b",
26
+ :long => "%d. %B %Y",
27
+ :long_ordinalized => lambda { |date, options|
28
+ tz = " (#{options[:timezone]})" if options[:timezone]
29
+ "#{date.day}ter %B %Y#{tz}"
30
+ }
31
+ },
32
+ :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
33
+ :abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
34
+ :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
35
+ :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil),
36
+ :order => [:day, :month, :year]
37
+ },
38
+ :time => {
39
+ :formats => {
40
+ :default => "%a, %d. %b %Y %H:%M:%S %z",
41
+ :short => "%d. %b %H:%M",
42
+ :long => "%d. %B %Y %H:%M",
43
+ :long_ordinalized => lambda { |date, options|
44
+ tz = " (#{options[:timezone]})" if options[:timezone]
45
+ "#{date.day}ter %B %Y, %H:%M Uhr#{tz}"
46
+ }
47
+ },
48
+ :am => 'am',
49
+ :pm => 'pm'
50
+ },
51
+ :datetime => {
52
+ :distance_in_words => {
53
+ :half_a_minute => 'half a minute',
54
+ :less_than_x_seconds => {
55
+ :one => 'less than 1 second',
56
+ :other => 'less than {{count}} seconds'
57
+ },
58
+ :x_seconds => {
59
+ :one => '1 second',
60
+ :other => '{{count}} seconds'
61
+ },
62
+ :less_than_x_minutes => {
63
+ :one => 'less than a minute',
64
+ :other => 'less than {{count}} minutes'
65
+ },
66
+ :x_minutes => {
67
+ :one => '1 minute',
68
+ :other => '{{count}} minutes'
69
+ },
70
+ :about_x_hours => {
71
+ :one => 'about 1 hour',
72
+ :other => 'about {{count}} hours'
73
+ },
74
+ :x_days => {
75
+ :one => '1 day',
76
+ :other => '{{count}} days'
77
+ },
78
+ :about_x_months => {
79
+ :one => 'about 1 month',
80
+ :other => 'about {{count}} months'
81
+ },
82
+ :x_months => {
83
+ :one => '1 month',
84
+ :other => '{{count}} months'
85
+ },
86
+ :about_x_years => {
87
+ :one => 'about 1 year',
88
+ :other => 'about {{count}} year'
89
+ },
90
+ :over_x_years => {
91
+ :one => 'over 1 year',
92
+ :other => 'over {{count}} years'
93
+ }
94
+ }
95
+ }
96
+ }
97
+ end
98
+
99
+ def setup_datetime_lambda_translations
100
+ backend_store_translations 'ru', {
101
+ :date => {
102
+ :'day_names' => lambda { |key, options|
103
+ (options[:format] =~ /^%A/) ?
104
+ %w(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота) :
105
+ %w(воскресенье понедельник вторник среда четверг пятница суббота)
106
+ },
107
+ :'abbr_day_names' => %w(Вс Пн Вт Ср Чт Пт Сб),
108
+ :'month_names' => lambda { |key, options|
109
+ (options[:format] =~ /(%d|%e)(\s*)?(%B)/) ?
110
+ %w(января февраля марта апреля мая июня июля августа сентября октября ноября декабря).unshift(nil) :
111
+ %w(Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь).unshift(nil)
112
+ },
113
+ :'abbr_month_names' => lambda { |key, options|
114
+ (options[:format] =~ /(%d|%e)(\s*)(%b)/) ?
115
+ %w(янв. февр. марта апр. мая июня июля авг. сент. окт. нояб. дек.).unshift(nil) :
116
+ %w(янв. февр. март апр. май июнь июль авг. сент. окт. нояб. дек.).unshift(nil)
117
+ },
118
+ },
119
+ :time => {
120
+ :am => "утра",
121
+ :pm => "вечера"
122
+ }
123
+ }
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
129
  end
@@ -1,88 +1,88 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
3
-
4
- class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
5
- include Tests::Backend::Simple::Setup::Base
6
-
7
- def test_load_translations_with_unknown_file_type_raises_exception
8
- assert_raises(I18n::UnknownFileType) { I18n.backend.load_translations "#{locales_dir}/en.xml" }
9
- end
10
-
11
- def test_load_translations_with_ruby_file_type_does_not_raise_exception
12
- assert_nothing_raised { I18n.backend.load_translations "#{locales_dir}/en.rb" }
13
- end
14
-
15
- def test_load_rb_loads_data_from_ruby_file
16
- data = I18n.backend.send :load_rb, "#{locales_dir}/en.rb"
17
- assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
18
- end
19
-
20
- def test_load_rb_loads_data_from_yaml_file
21
- data = I18n.backend.send :load_yml, "#{locales_dir}/en.yml"
22
- assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
23
- end
24
-
25
- def test_load_translations_loads_from_different_file_formats
26
- I18n.backend = I18n::Backend::Simple.new
27
- I18n.backend.load_translations "#{locales_dir}/en.rb", "#{locales_dir}/en.yml"
28
- expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
29
- assert_equal expected, backend_get_translations
30
- end
31
- end
32
-
33
- class I18nSimpleBackendStoreTranslationsTest < Test::Unit::TestCase
34
- include Tests::Backend::Simple::Setup::Base
35
-
36
- def test_store_translations_adds_translations # no, really :-)
37
- I18n.backend.store_translations :'en', :foo => 'bar'
38
- assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
39
- end
40
-
41
- def test_store_translations_deep_merges_translations
42
- I18n.backend.store_translations :'en', :foo => {:bar => 'bar'}
43
- I18n.backend.store_translations :'en', :foo => {:baz => 'baz'}
44
- assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
45
- end
46
-
47
- def test_store_translations_forces_locale_to_sym
48
- I18n.backend.store_translations 'en', :foo => 'bar'
49
- assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
50
- end
51
-
52
- def test_store_translations_converts_keys_to_symbols
53
- # backend_reset_translations!
54
- I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
55
- assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
56
- end
57
-
58
- def test_deep_symbolize_keys_works
59
- result = I18n.backend.send :deep_symbolize_keys, 'foo' => {'bar' => {'baz' => 'bar'}}
60
- expected = {:foo => {:bar => {:baz => 'bar'}}}
61
- assert_equal expected, result
62
- end
63
- end
64
-
65
- class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
66
- include Tests::Backend::Simple::Setup::Base
67
-
68
- def setup
69
- I18n.backend = I18n::Backend::Simple.new
70
- I18n.load_path = [locales_dir + '/en.yml']
71
- assert_nil backend_get_translations
72
- I18n.backend.send :init_translations
73
- end
74
-
75
- def test_setup
76
- assert_not_nil backend_get_translations
77
- end
78
-
79
- def test_reload_translations_unloads_translations
80
- I18n.backend.reload!
81
- assert_nil backend_get_translations
82
- end
83
-
84
- def test_reload_translations_uninitializes_translations
85
- I18n.backend.reload!
86
- assert_equal I18n.backend.initialized?, false
87
- end
88
- end
1
+ # encoding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
3
+
4
+ class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase
5
+ include Tests::Backend::Simple::Setup::Base
6
+
7
+ def test_load_translations_with_unknown_file_type_raises_exception
8
+ assert_raises(I18n::UnknownFileType) { I18n.backend.load_translations "#{locales_dir}/en.xml" }
9
+ end
10
+
11
+ def test_load_translations_with_ruby_file_type_does_not_raise_exception
12
+ assert_nothing_raised { I18n.backend.load_translations "#{locales_dir}/en.rb" }
13
+ end
14
+
15
+ def test_load_rb_loads_data_from_ruby_file
16
+ data = I18n.backend.send :load_rb, "#{locales_dir}/en.rb"
17
+ assert_equal({ :en => { :fuh => { :bah => 'bas' } } }, data)
18
+ end
19
+
20
+ def test_load_rb_loads_data_from_yaml_file
21
+ data = I18n.backend.send :load_yml, "#{locales_dir}/en.yml"
22
+ assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
23
+ end
24
+
25
+ def test_load_translations_loads_from_different_file_formats
26
+ I18n.backend = I18n::Backend::Simple.new
27
+ I18n.backend.load_translations "#{locales_dir}/en.rb", "#{locales_dir}/en.yml"
28
+ expected = { :en => { :fuh => { :bah => "bas" }, :foo => { :bar => "baz" } } }
29
+ assert_equal expected, backend_get_translations
30
+ end
31
+ end
32
+
33
+ class I18nSimpleBackendStoreTranslationsTest < Test::Unit::TestCase
34
+ include Tests::Backend::Simple::Setup::Base
35
+
36
+ def test_store_translations_adds_translations # no, really :-)
37
+ I18n.backend.store_translations :'en', :foo => 'bar'
38
+ assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
39
+ end
40
+
41
+ def test_store_translations_deep_merges_translations
42
+ I18n.backend.store_translations :'en', :foo => {:bar => 'bar'}
43
+ I18n.backend.store_translations :'en', :foo => {:baz => 'baz'}
44
+ assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
45
+ end
46
+
47
+ def test_store_translations_forces_locale_to_sym
48
+ I18n.backend.store_translations 'en', :foo => 'bar'
49
+ assert_equal Hash[:'en', {:foo => 'bar'}], backend_get_translations
50
+ end
51
+
52
+ def test_store_translations_converts_keys_to_symbols
53
+ # backend_reset_translations!
54
+ I18n.backend.store_translations 'en', 'foo' => {'bar' => 'bar', 'baz' => 'baz'}
55
+ assert_equal Hash[:'en', {:foo => {:bar => 'bar', :baz => 'baz'}}], backend_get_translations
56
+ end
57
+
58
+ def test_deep_symbolize_keys_works
59
+ result = I18n.backend.send :deep_symbolize_keys, 'foo' => {'bar' => {'baz' => 'bar'}}
60
+ expected = {:foo => {:bar => {:baz => 'bar'}}}
61
+ assert_equal expected, result
62
+ end
63
+ end
64
+
65
+ class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase
66
+ include Tests::Backend::Simple::Setup::Base
67
+
68
+ def setup
69
+ I18n.backend = I18n::Backend::Simple.new
70
+ I18n.load_path = [locales_dir + '/en.yml']
71
+ assert_nil backend_get_translations
72
+ I18n.backend.send :init_translations
73
+ end
74
+
75
+ def test_setup
76
+ assert_not_nil backend_get_translations
77
+ end
78
+
79
+ def test_reload_translations_unloads_translations
80
+ I18n.backend.reload!
81
+ assert_nil backend_get_translations
82
+ end
83
+
84
+ def test_reload_translations_uninitializes_translations
85
+ I18n.backend.reload!
86
+ assert_equal I18n.backend.initialized?, false
87
+ end
88
+ end