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.
- data/CHANGELOG +9 -5
- data/lib/active_support/buffered_logger.rb +1 -1
- data/lib/active_support/cache/memory_store.rb +7 -1
- data/lib/active_support/cache/strategy/local_cache.rb +1 -1
- data/lib/active_support/core_ext/array/conversions.rb +1 -1
- data/lib/active_support/core_ext/array/random_access.rb +11 -1
- data/lib/active_support/core_ext/class/attribute_accessors.rb +35 -28
- data/lib/active_support/core_ext/date/calculations.rb +14 -4
- data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
- data/lib/active_support/core_ext/module/aliasing.rb +1 -1
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
- data/lib/active_support/core_ext/module/attribute_accessors.rb +33 -26
- data/lib/active_support/core_ext/module/synchronization.rb +1 -1
- data/lib/active_support/core_ext/object/blank.rb +20 -2
- data/lib/active_support/core_ext/string/output_safety.rb +10 -2
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -4
- data/lib/active_support/core_ext/time.rb +8 -4
- data/lib/active_support/core_ext/time/calculations.rb +11 -2
- data/lib/active_support/deprecation.rb +3 -2
- data/lib/active_support/inflections.rb +1 -1
- data/lib/active_support/inflector.rb +4 -1
- data/lib/active_support/json/backends/yaml.rb +10 -7
- data/lib/active_support/json/decoding.rb +1 -1
- data/lib/active_support/memoizable.rb +1 -1
- data/lib/active_support/multibyte/unicode_database.rb +2 -2
- data/lib/active_support/multibyte/utils.rb +6 -7
- data/lib/active_support/ordered_hash.rb +24 -30
- data/lib/active_support/testing/assertions.rb +14 -0
- data/lib/active_support/values/time_zone.rb +84 -76
- data/lib/active_support/vendor.rb +1 -1
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n.rb +92 -34
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend.rb +2 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record.rb +9 -13
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/missing.rb +1 -1
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/store_procs.rb +6 -6
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/active_record/translation.rb +14 -9
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/base.rb +23 -16
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/cache.rb +1 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/cascade.rb +22 -8
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/chain.rb +2 -1
- data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/cldr.rb +100 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/fallbacks.rb +20 -3
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/fast.rb +14 -13
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/gettext.rb +1 -1
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/helpers.rb +4 -16
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/interpolation_compiler.rb +2 -2
- data/lib/active_support/vendor/i18n-0.3.7/i18n/backend/links.rb +34 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/metadata.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/pluralization.rb +1 -1
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/backend/simple.rb +0 -0
- data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/except.rb +8 -0
- data/lib/active_support/vendor/i18n-0.3.7/i18n/core_ext/hash/slice.rb +8 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/core_ext/object/meta_class.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/core_ext/string/interpolate.rb +1 -1
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/exceptions.rb +1 -1
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/gettext.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/vendor → i18n-0.3.7/i18n/gettext}/po_parser.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/helpers.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/helpers/gettext.rb +3 -2
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/fallbacks.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/parents.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/rfc4646.rb +0 -0
- data/lib/active_support/vendor/{i18n-0.3.3/lib → i18n-0.3.7}/i18n/locale/tag/simple.rb +0 -0
- data/lib/active_support/vendor/i18n-0.3.7/i18n/version.rb +3 -0
- metadata +42 -96
- data/lib/active_support/vendor/i18n-0.3.3/CHANGELOG.textile +0 -76
- data/lib/active_support/vendor/i18n-0.3.3/MIT-LICENSE +0 -20
- data/lib/active_support/vendor/i18n-0.3.3/README.textile +0 -81
- data/lib/active_support/vendor/i18n-0.3.3/Rakefile +0 -24
- data/lib/active_support/vendor/i18n-0.3.3/benchmark/example.yml +0 -144
- data/lib/active_support/vendor/i18n-0.3.3/benchmark/run.rb +0 -71
- data/lib/active_support/vendor/i18n-0.3.3/contributors.txt +0 -17
- data/lib/active_support/vendor/i18n-0.3.3/i18n.gemspec +0 -165
- data/lib/active_support/vendor/i18n-0.3.3/init.rb +0 -1
- data/lib/active_support/vendor/i18n-0.3.3/lib/i18n/version.rb +0 -3
- data/lib/active_support/vendor/i18n-0.3.3/test/all.rb +0 -8
- data/lib/active_support/vendor/i18n-0.3.3/test/api/basics.rb +0 -15
- data/lib/active_support/vendor/i18n-0.3.3/test/api/defaults.rb +0 -40
- data/lib/active_support/vendor/i18n-0.3.3/test/api/interpolation.rb +0 -92
- data/lib/active_support/vendor/i18n-0.3.3/test/api/link.rb +0 -55
- data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date.rb +0 -91
- data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/date_time.rb +0 -90
- data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/procs.rb +0 -54
- data/lib/active_support/vendor/i18n-0.3.3/test/api/localization/time.rb +0 -84
- data/lib/active_support/vendor/i18n-0.3.3/test/api/lookup.rb +0 -45
- data/lib/active_support/vendor/i18n-0.3.3/test/api/pluralization.rb +0 -35
- data/lib/active_support/vendor/i18n-0.3.3/test/api/procs.rb +0 -40
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/active_record_test.rb +0 -29
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/all_features_test.rb +0 -40
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/cascade_test.rb +0 -31
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/chain_test.rb +0 -26
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fallbacks_test.rb +0 -33
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/fast_test.rb +0 -31
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/pluralization_test.rb +0 -33
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/api/simple_test.rb +0 -21
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record/missing_test.rb +0 -60
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/active_record_test.rb +0 -52
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cache_test.rb +0 -72
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/cascade_test.rb +0 -66
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/chain_test.rb +0 -64
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fallbacks_test.rb +0 -57
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/fast_test.rb +0 -50
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/helpers_test.rb +0 -26
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/interpolation_compiler_test.rb +0 -107
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/metadata_test.rb +0 -67
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/pluralization_test.rb +0 -43
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/backend/simple_test.rb +0 -77
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/core_ext/string/interpolate_test.rb +0 -94
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/api_test.rb +0 -201
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/gettext/backend_test.rb +0 -91
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_exceptions_test.rb +0 -97
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_load_path_test.rb +0 -23
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/i18n_test.rb +0 -172
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/fallbacks_test.rb +0 -126
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/rfc4646_test.rb +0 -143
- data/lib/active_support/vendor/i18n-0.3.3/test/cases/locale/tag/simple_test.rb +0 -33
- data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/de.po +0 -72
- data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.rb +0 -3
- data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/en.yml +0 -3
- data/lib/active_support/vendor/i18n-0.3.3/test/fixtures/locales/plurals.rb +0 -113
- data/lib/active_support/vendor/i18n-0.3.3/test/test_helper.rb +0 -100
@@ -1,97 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
4
|
-
|
5
|
-
class I18nExceptionsTest < Test::Unit::TestCase
|
6
|
-
def test_invalid_locale_stores_locale
|
7
|
-
force_invalid_locale
|
8
|
-
rescue I18n::ArgumentError => e
|
9
|
-
assert_nil e.locale
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_invalid_locale_message
|
13
|
-
force_invalid_locale
|
14
|
-
rescue I18n::ArgumentError => e
|
15
|
-
assert_equal 'nil is not a valid locale', e.message
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_missing_translation_data_stores_locale_key_and_options
|
19
|
-
force_missing_translation_data
|
20
|
-
rescue I18n::ArgumentError => e
|
21
|
-
options = {:scope => :bar}
|
22
|
-
assert_equal 'de', e.locale
|
23
|
-
assert_equal :foo, e.key
|
24
|
-
assert_equal options, e.options
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_missing_translation_data_message
|
28
|
-
force_missing_translation_data
|
29
|
-
rescue I18n::ArgumentError => e
|
30
|
-
assert_equal 'translation missing: de, bar, foo', e.message
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_invalid_pluralization_data_stores_entry_and_count
|
34
|
-
force_invalid_pluralization_data
|
35
|
-
rescue I18n::ArgumentError => e
|
36
|
-
assert_equal [:bar], e.entry
|
37
|
-
assert_equal 1, e.count
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_invalid_pluralization_data_message
|
41
|
-
force_invalid_pluralization_data
|
42
|
-
rescue I18n::ArgumentError => e
|
43
|
-
assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_missing_interpolation_argument_stores_key_and_string
|
47
|
-
assert_raises(I18n::MissingInterpolationArgument) { force_missing_interpolation_argument }
|
48
|
-
force_missing_interpolation_argument
|
49
|
-
rescue I18n::ArgumentError => e
|
50
|
-
# assert_equal :bar, e.key
|
51
|
-
assert_equal "{{bar}}", e.string
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_missing_interpolation_argument_message
|
55
|
-
force_missing_interpolation_argument
|
56
|
-
rescue I18n::ArgumentError => e
|
57
|
-
assert_equal 'missing interpolation argument in "{{bar}}" ({:baz=>"baz"} given)', e.message
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_reserved_interpolation_key_stores_key_and_string
|
61
|
-
force_reserved_interpolation_key
|
62
|
-
rescue I18n::ArgumentError => e
|
63
|
-
assert_equal :scope, e.key
|
64
|
-
assert_equal "{{scope}}", e.string
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_reserved_interpolation_key_message
|
68
|
-
force_reserved_interpolation_key
|
69
|
-
rescue I18n::ArgumentError => e
|
70
|
-
assert_equal 'reserved key :scope used in "{{scope}}"', e.message
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
def force_invalid_locale
|
75
|
-
I18n.backend.translate nil, :foo
|
76
|
-
end
|
77
|
-
|
78
|
-
def force_missing_translation_data
|
79
|
-
I18n.backend.store_translations 'de', :bar => nil
|
80
|
-
I18n.backend.translate 'de', :foo, :scope => :bar
|
81
|
-
end
|
82
|
-
|
83
|
-
def force_invalid_pluralization_data
|
84
|
-
I18n.backend.store_translations 'de', :foo => [:bar]
|
85
|
-
I18n.backend.translate 'de', :foo, :count => 1
|
86
|
-
end
|
87
|
-
|
88
|
-
def force_missing_interpolation_argument
|
89
|
-
I18n.backend.store_translations 'de', :foo => "{{bar}}"
|
90
|
-
I18n.backend.translate 'de', :foo, :baz => 'baz'
|
91
|
-
end
|
92
|
-
|
93
|
-
def force_reserved_interpolation_key
|
94
|
-
I18n.backend.store_translations 'de', :foo => "{{scope}}"
|
95
|
-
I18n.backend.translate 'de', :foo, :baz => 'baz'
|
96
|
-
end
|
97
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
4
|
-
|
5
|
-
class I18nLoadPathTest < Test::Unit::TestCase
|
6
|
-
# include Tests::Backend::Simple::Setup::Base
|
7
|
-
|
8
|
-
def setup
|
9
|
-
I18n.locale = :en
|
10
|
-
I18n.backend = I18n::Backend::Simple.new
|
11
|
-
store_translations(:en, :foo => {:bar => 'bar', :baz => 'baz'})
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_nested_load_paths_do_not_break_locale_loading
|
15
|
-
I18n.load_path = [[locales_dir + '/en.yml']]
|
16
|
-
assert_equal "baz", I18n.t(:'foo.bar')
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_adding_arrays_of_filenames_to_load_path_do_not_break_locale_loading
|
20
|
-
I18n.load_path << Dir[locales_dir + '/*.{rb,yml}']
|
21
|
-
assert_equal "baz", I18n.t(:'foo.bar')
|
22
|
-
end
|
23
|
-
end
|
@@ -1,172 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
4
|
-
|
5
|
-
class I18nTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
I18n.backend.store_translations :'en', {
|
8
|
-
:currency => {
|
9
|
-
:format => {
|
10
|
-
:separator => '.',
|
11
|
-
:delimiter => ',',
|
12
|
-
}
|
13
|
-
}
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_uses_simple_backend_set_by_default
|
18
|
-
assert I18n.backend.is_a?(I18n::Backend::Simple)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_can_set_backend
|
22
|
-
assert_nothing_raised { I18n.backend = self }
|
23
|
-
assert_equal self, I18n.backend
|
24
|
-
I18n.backend = I18n::Backend::Simple.new
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_uses_en_us_as_default_locale_by_default
|
28
|
-
assert_equal :en, I18n.default_locale
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_can_set_default_locale
|
32
|
-
assert_nothing_raised { I18n.default_locale = 'de' }
|
33
|
-
assert_equal :de, I18n.default_locale
|
34
|
-
I18n.default_locale = :en
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_uses_default_locale_as_locale_by_default
|
38
|
-
assert_equal I18n.default_locale, I18n.locale
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_can_set_locale_to_thread_current
|
42
|
-
assert_nothing_raised { I18n.locale = 'de' }
|
43
|
-
assert_equal :de, I18n.locale
|
44
|
-
assert_equal :de, Thread.current[:locale]
|
45
|
-
I18n.locale = :en
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_defaults_to_dot_as_separator
|
49
|
-
assert_equal '.', I18n.default_separator
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_can_set_default_separator
|
53
|
-
assert_nothing_raised { I18n.default_separator = "\001" }
|
54
|
-
I18n.default_separator = '.' # revert it
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_normalize_keys
|
58
|
-
assert_equal [:en, :foo, :bar], I18n.send(:normalize_translation_keys, :en, :bar, :foo)
|
59
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz.buz', :'foo.bar')
|
60
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, 'baz.buz', 'foo.bar')
|
61
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, %w(baz buz), %w(foo bar))
|
62
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, [:baz, :buz], [:foo, :bar])
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_normalize_keys_should_not_attempt_to_sym_on_empty_string
|
66
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz.buz', :'foo..bar')
|
67
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz.buz', :'foo......bar')
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_uses_passed_separator_to_normalize_keys
|
71
|
-
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz|buz', :'foo|bar', '|')
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_can_set_exception_handler
|
75
|
-
assert_nothing_raised { I18n.exception_handler = :custom_exception_handler }
|
76
|
-
I18n.exception_handler = :default_exception_handler # revert it
|
77
|
-
end
|
78
|
-
|
79
|
-
with_mocha do
|
80
|
-
def test_uses_custom_exception_handler
|
81
|
-
I18n.exception_handler = :custom_exception_handler
|
82
|
-
I18n.expects(:custom_exception_handler)
|
83
|
-
I18n.translate :bogus
|
84
|
-
I18n.exception_handler = :default_exception_handler # revert it
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_delegates_translate_to_backend
|
88
|
-
I18n.backend.expects(:translate).with 'de', :foo, {}
|
89
|
-
I18n.translate :foo, :locale => 'de'
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_delegates_localize_to_backend
|
93
|
-
I18n.backend.expects(:localize).with 'de', :whatever, :default
|
94
|
-
I18n.localize :whatever, :locale => 'de'
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_translate_given_no_locale_uses_i18n_locale
|
98
|
-
I18n.backend.expects(:translate).with :en, :foo, {}
|
99
|
-
I18n.translate :foo
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_translate_on_nested_symbol_keys_works
|
104
|
-
assert_equal ".", I18n.t(:'currency.format.separator')
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_translate_with_nested_string_keys_works
|
108
|
-
assert_equal ".", I18n.t('currency.format.separator')
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_translate_with_array_as_scope_works
|
112
|
-
assert_equal ".", I18n.t(:separator, :scope => %w(currency format))
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_translate_with_array_containing_dot_separated_strings_as_scope_works
|
116
|
-
assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_translate_with_key_array_and_dot_separated_scope_works
|
120
|
-
assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_translate_with_dot_separated_key_array_and_scope_works
|
124
|
-
assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
|
125
|
-
end
|
126
|
-
|
127
|
-
with_mocha do
|
128
|
-
def test_translate_with_options_using_scope_works
|
129
|
-
I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
|
130
|
-
I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
|
131
|
-
locale.t :precision
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
# def test_translate_given_no_args_raises_missing_translation_data
|
137
|
-
# assert_equal "translation missing: en, no key", I18n.t
|
138
|
-
# end
|
139
|
-
|
140
|
-
def test_translate_given_a_bogus_key_raises_missing_translation_data
|
141
|
-
assert_equal "translation missing: en, bogus", I18n.t(:bogus)
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_localize_nil_raises_argument_error
|
145
|
-
assert_raises(I18n::ArgumentError) { I18n.l nil }
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_localize_object_raises_argument_error
|
149
|
-
assert_raises(I18n::ArgumentError) { I18n.l Object.new }
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_proc_exception_handler
|
153
|
-
I18n.exception_handler = Proc.new { |exception, locale, key, options|
|
154
|
-
"No exception here! [Proc handler]"
|
155
|
-
}
|
156
|
-
assert_equal "No exception here! [Proc handler]", I18n.translate(:test_proc_handler)
|
157
|
-
ensure
|
158
|
-
I18n.exception_handler = :default_exception_handler
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_class_exception_handler
|
162
|
-
I18n.exception_handler = Class.new do
|
163
|
-
def call(exception, locale, key, options)
|
164
|
-
"No exception here! [Class handler]"
|
165
|
-
end
|
166
|
-
end.new
|
167
|
-
assert_equal "No exception here! [Class handler]", I18n.translate(:test_class_handler)
|
168
|
-
ensure
|
169
|
-
I18n.exception_handler = :default_exception_handler
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
4
|
-
|
5
|
-
include I18n::Locale
|
6
|
-
|
7
|
-
class I18nFallbacksDefaultsTest < Test::Unit::TestCase
|
8
|
-
def teardown
|
9
|
-
I18n.default_locale = :en
|
10
|
-
end
|
11
|
-
|
12
|
-
test "defaults reflect the I18n.default_locale if no default has been set manually" do
|
13
|
-
I18n.default_locale = :'en-US'
|
14
|
-
fallbacks = Fallbacks.new
|
15
|
-
assert_equal [:'en-US', :en], fallbacks.defaults
|
16
|
-
end
|
17
|
-
|
18
|
-
test "defaults reflect a manually passed default locale if any" do
|
19
|
-
fallbacks = Fallbacks.new(:'fi-FI')
|
20
|
-
assert_equal [:'fi-FI', :fi], fallbacks.defaults
|
21
|
-
I18n.default_locale = :'de-DE'
|
22
|
-
assert_equal [:'fi-FI', :fi], fallbacks.defaults
|
23
|
-
end
|
24
|
-
|
25
|
-
test "defaults allows to set multiple defaults" do
|
26
|
-
fallbacks = Fallbacks.new(:'fi-FI', :'se-FI')
|
27
|
-
assert_equal [:'fi-FI', :fi, :'se-FI', :se], fallbacks.defaults
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class I18nFallbacksComputationTest < Test::Unit::TestCase
|
32
|
-
def setup
|
33
|
-
@fallbacks = Fallbacks.new(:'en-US')
|
34
|
-
end
|
35
|
-
|
36
|
-
test "with no mappings defined it returns [:es, :en-US] for :es" do
|
37
|
-
assert_equal [:es, :"en-US", :en], @fallbacks[:es]
|
38
|
-
end
|
39
|
-
|
40
|
-
test "with no mappings defined it returns [:es-ES, :es, :en-US] for :es-ES" do
|
41
|
-
assert_equal [:"es-ES", :es, :"en-US", :en], @fallbacks[:"es-ES"]
|
42
|
-
end
|
43
|
-
|
44
|
-
test "with no mappings defined it returns [:es-MX, :es, :en-US] for :es-MX" do
|
45
|
-
assert_equal [:"es-MX", :es, :"en-US", :en], @fallbacks[:"es-MX"]
|
46
|
-
end
|
47
|
-
|
48
|
-
test "with no mappings defined it returns [:es-Latn-ES, :es-Latn, :es, :en-US] for :es-Latn-ES" do
|
49
|
-
assert_equal [:"es-Latn-ES", :"es-Latn", :es, :"en-US", :en], @fallbacks[:'es-Latn-ES']
|
50
|
-
end
|
51
|
-
|
52
|
-
test "with no mappings defined it returns [:en, :en-US] for :en" do
|
53
|
-
assert_equal [:en, :"en-US"], @fallbacks[:en]
|
54
|
-
end
|
55
|
-
|
56
|
-
test "with no mappings defined it returns [:en-US, :en] for :en-US (special case: locale == default)" do
|
57
|
-
assert_equal [:"en-US", :en], @fallbacks[:"en-US"]
|
58
|
-
end
|
59
|
-
|
60
|
-
# Most people who speak Catalan also live in Spain, so it is safe to assume
|
61
|
-
# that they also speak Spanish as spoken in Spain.
|
62
|
-
test "with a Catalan mapping defined it returns [:ca, :es-ES, :es, :en-US] for :ca" do
|
63
|
-
@fallbacks.map(:ca => :"es-ES")
|
64
|
-
assert_equal [:ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:ca]
|
65
|
-
end
|
66
|
-
|
67
|
-
test "with a Catalan mapping defined it returns [:ca-ES, :ca, :es-ES, :es, :en-US] for :ca-ES" do
|
68
|
-
@fallbacks.map(:ca => :"es-ES")
|
69
|
-
assert_equal [:"ca-ES", :ca, :"es-ES", :es, :"en-US", :en], @fallbacks[:"ca-ES"]
|
70
|
-
end
|
71
|
-
|
72
|
-
# People who speak Arabic as spoken in Palestine often times also speak
|
73
|
-
# Hebrew as spoken in Israel. However it is in no way safe to assume that
|
74
|
-
# everybody who speaks Arabic also speaks Hebrew.
|
75
|
-
|
76
|
-
test "with a Hebrew mapping defined it returns [:ar, :en-US] for :ar" do
|
77
|
-
@fallbacks.map(:"ar-PS" => :"he-IL")
|
78
|
-
assert_equal [:ar, :"en-US", :en], @fallbacks[:ar]
|
79
|
-
end
|
80
|
-
|
81
|
-
test "with a Hebrew mapping defined it returns [:ar-EG, :ar, :en-US] for :ar-EG" do
|
82
|
-
@fallbacks.map(:"ar-PS" => :"he-IL")
|
83
|
-
assert_equal [:"ar-EG", :ar, :"en-US", :en], @fallbacks[:"ar-EG"]
|
84
|
-
end
|
85
|
-
|
86
|
-
test "with a Hebrew mapping defined it returns [:ar-PS, :ar, :he-IL, :he, :en-US] for :ar-PS" do
|
87
|
-
@fallbacks.map(:"ar-PS" => :"he-IL")
|
88
|
-
assert_equal [:"ar-PS", :ar, :"he-IL", :he, :"en-US", :en], @fallbacks[:"ar-PS"]
|
89
|
-
end
|
90
|
-
|
91
|
-
# Sami people live in several scandinavian countries. In Finnland many people
|
92
|
-
# know Swedish and Finnish. Thus, it can be assumed that Sami living in
|
93
|
-
# Finnland also speak Swedish and Finnish.
|
94
|
-
|
95
|
-
test "with a Sami mapping defined it returns [:sms-FI, :sms, :se-FI, :se, :fi-FI, :fi, :en-US] for :sms-FI" do
|
96
|
-
@fallbacks.map(:sms => [:"se-FI", :"fi-FI"])
|
97
|
-
assert_equal [:"sms-FI", :sms, :"se-FI", :se, :"fi-FI", :fi, :"en-US", :en], @fallbacks[:"sms-FI"]
|
98
|
-
end
|
99
|
-
|
100
|
-
# Austrian people understand German as spoken in Germany
|
101
|
-
|
102
|
-
test "with a German mapping defined it returns [:de, :en-US] for de" do
|
103
|
-
@fallbacks.map(:"de-AT" => :"de-DE")
|
104
|
-
assert_equal [:de, :"en-US", :en], @fallbacks[:"de"]
|
105
|
-
end
|
106
|
-
|
107
|
-
test "with a German mapping defined it returns [:de-DE, :de, :en-US] for de-DE" do
|
108
|
-
@fallbacks.map(:"de-AT" => :"de-DE")
|
109
|
-
assert_equal [:"de-DE", :de, :"en-US", :en], @fallbacks[:"de-DE"]
|
110
|
-
end
|
111
|
-
|
112
|
-
test "with a German mapping defined it returns [:de-AT, :de, :de-DE, :en-US] for de-AT" do
|
113
|
-
@fallbacks.map(:"de-AT" => :"de-DE")
|
114
|
-
assert_equal [:"de-AT", :de, :"de-DE", :"en-US", :en], @fallbacks[:"de-AT"]
|
115
|
-
end
|
116
|
-
|
117
|
-
# Mapping :de => :en, :he => :en
|
118
|
-
|
119
|
-
test "with a mapping :de => :en, :he => :en defined it returns [:de, :en] for :de" do
|
120
|
-
assert_equal [:de, :"en-US", :en], @fallbacks[:de]
|
121
|
-
end
|
122
|
-
|
123
|
-
test "with a mapping :de => :en, :he => :en defined it [:he, :en] for :de" do
|
124
|
-
assert_equal [:he, :"en-US", :en], @fallbacks[:he]
|
125
|
-
end
|
126
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
4
|
-
|
5
|
-
class I18nLocaleTagRfc4646ParserTest < Test::Unit::TestCase
|
6
|
-
include I18n::Locale
|
7
|
-
|
8
|
-
test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
|
9
|
-
assert_equal ['de', nil, nil, nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de')
|
10
|
-
end
|
11
|
-
|
12
|
-
test "Rfc4646::Parser given a valid tag 'de' returns an array of subtags" do
|
13
|
-
assert_equal ['de', nil, 'DE', nil, nil, nil, nil], Tag::Rfc4646::Parser.match('de-DE')
|
14
|
-
end
|
15
|
-
|
16
|
-
test "Rfc4646::Parser given a valid lowercase tag 'de-latn-de-variant-x-phonebk' returns an array of subtags" do
|
17
|
-
assert_equal ['de', 'latn', 'de', 'variant', nil, 'x-phonebk', nil], Tag::Rfc4646::Parser.match('de-latn-de-variant-x-phonebk')
|
18
|
-
end
|
19
|
-
|
20
|
-
test "Rfc4646::Parser given a valid uppercase tag 'DE-LATN-DE-VARIANT-X-PHONEBK' returns an array of subtags" do
|
21
|
-
assert_equal ['DE', 'LATN', 'DE', 'VARIANT', nil, 'X-PHONEBK', nil], Tag::Rfc4646::Parser.match('DE-LATN-DE-VARIANT-X-PHONEBK')
|
22
|
-
end
|
23
|
-
|
24
|
-
test "Rfc4646::Parser given an invalid tag 'a-DE' it returns false" do
|
25
|
-
assert_equal false, Tag::Rfc4646::Parser.match('a-DE')
|
26
|
-
end
|
27
|
-
|
28
|
-
test "Rfc4646::Parser given an invalid tag 'de-419-DE' it returns false" do
|
29
|
-
assert_equal false, Tag::Rfc4646::Parser.match('de-419-DE')
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Tag for the locale 'de-Latn-DE-Variant-a-ext-x-phonebk-i-klingon'
|
34
|
-
|
35
|
-
class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
|
36
|
-
include I18n::Locale
|
37
|
-
|
38
|
-
def setup
|
39
|
-
subtags = %w(de Latn DE variant a-ext x-phonebk i-klingon)
|
40
|
-
@tag = Tag::Rfc4646.new *subtags
|
41
|
-
end
|
42
|
-
|
43
|
-
test "returns 'de' as the language subtag in lowercase" do
|
44
|
-
assert_equal 'de', @tag.language
|
45
|
-
end
|
46
|
-
|
47
|
-
test "returns 'Latn' as the script subtag in titlecase" do
|
48
|
-
assert_equal 'Latn', @tag.script
|
49
|
-
end
|
50
|
-
|
51
|
-
test "returns 'DE' as the region subtag in uppercase" do
|
52
|
-
assert_equal 'DE', @tag.region
|
53
|
-
end
|
54
|
-
|
55
|
-
test "returns 'variant' as the variant subtag in lowercase" do
|
56
|
-
assert_equal 'variant', @tag.variant
|
57
|
-
end
|
58
|
-
|
59
|
-
test "returns 'a-ext' as the extension subtag" do
|
60
|
-
assert_equal 'a-ext', @tag.extension
|
61
|
-
end
|
62
|
-
|
63
|
-
test "returns 'x-phonebk' as the privateuse subtag" do
|
64
|
-
assert_equal 'x-phonebk', @tag.privateuse
|
65
|
-
end
|
66
|
-
|
67
|
-
test "returns 'i-klingon' as the grandfathered subtag" do
|
68
|
-
assert_equal 'i-klingon', @tag.grandfathered
|
69
|
-
end
|
70
|
-
|
71
|
-
test "returns a formatted tag string from #to_s" do
|
72
|
-
assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon', @tag.to_s
|
73
|
-
end
|
74
|
-
|
75
|
-
test "returns an array containing the formatted subtags from #to_a" do
|
76
|
-
assert_equal %w(de Latn DE variant a-ext x-phonebk i-klingon), @tag.to_a
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# Tag inheritance
|
81
|
-
|
82
|
-
class I18nLocaleTagSubtagsTest < Test::Unit::TestCase
|
83
|
-
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
|
84
|
-
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
|
85
|
-
assert_equal 'de-Latn-DE-variant-a-ext-x-phonebk', tag.parent.to_s
|
86
|
-
end
|
87
|
-
|
88
|
-
test "#parent returns 'de-Latn-DE-variant-a-ext' as the parent of 'de-Latn-DE-variant-a-ext-x-phonebk'" do
|
89
|
-
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk)
|
90
|
-
assert_equal 'de-Latn-DE-variant-a-ext', tag.parent.to_s
|
91
|
-
end
|
92
|
-
|
93
|
-
test "#parent returns 'de-Latn-DE-variant' as the parent of 'de-Latn-DE-variant-a-ext'" do
|
94
|
-
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext)
|
95
|
-
assert_equal 'de-Latn-DE-variant', tag.parent.to_s
|
96
|
-
end
|
97
|
-
|
98
|
-
test "#parent returns 'de-Latn-DE' as the parent of 'de-Latn-DE-variant'" do
|
99
|
-
tag = Tag::Rfc4646.new *%w(de Latn DE variant)
|
100
|
-
assert_equal 'de-Latn-DE', tag.parent.to_s
|
101
|
-
end
|
102
|
-
|
103
|
-
test "#parent returns 'de-Latn' as the parent of 'de-Latn-DE'" do
|
104
|
-
tag = Tag::Rfc4646.new *%w(de Latn DE)
|
105
|
-
assert_equal 'de-Latn', tag.parent.to_s
|
106
|
-
end
|
107
|
-
|
108
|
-
test "#parent returns 'de' as the parent of 'de-Latn'" do
|
109
|
-
tag = Tag::Rfc4646.new *%w(de Latn)
|
110
|
-
assert_equal 'de', tag.parent.to_s
|
111
|
-
end
|
112
|
-
|
113
|
-
# TODO RFC4647 says: "If no language tag matches the request, the "default" value is returned."
|
114
|
-
# where should we set the default language?
|
115
|
-
# test "#parent returns '' as the parent of 'de'" do
|
116
|
-
# tag = Tag::Rfc4646.new *%w(de)
|
117
|
-
# assert_equal '', tag.parent.to_s
|
118
|
-
# end
|
119
|
-
|
120
|
-
test "#parent returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
|
121
|
-
parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
|
122
|
-
de-Latn-DE-variant-a-ext-x-phonebk
|
123
|
-
de-Latn-DE-variant-a-ext
|
124
|
-
de-Latn-DE-variant
|
125
|
-
de-Latn-DE
|
126
|
-
de-Latn
|
127
|
-
de)
|
128
|
-
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
|
129
|
-
assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
|
130
|
-
end
|
131
|
-
|
132
|
-
test "returns an array of 5 parents for 'de-Latn-DE-variant-a-ext-x-phonebk-i-klingon'" do
|
133
|
-
parents = %w(de-Latn-DE-variant-a-ext-x-phonebk-i-klingon
|
134
|
-
de-Latn-DE-variant-a-ext-x-phonebk
|
135
|
-
de-Latn-DE-variant-a-ext
|
136
|
-
de-Latn-DE-variant
|
137
|
-
de-Latn-DE
|
138
|
-
de-Latn
|
139
|
-
de)
|
140
|
-
tag = Tag::Rfc4646.new *%w(de Latn DE variant a-ext x-phonebk i-klingon)
|
141
|
-
assert_equal parents, tag.self_and_parents.map{|tag| tag.to_s}
|
142
|
-
end
|
143
|
-
end
|