pepe-i18n 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +57 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +42 -0
- data/Rakefile +21 -0
- data/VERSION +1 -0
- data/lib/i18n.rb +270 -0
- data/lib/i18n/backend/base.rb +251 -0
- data/lib/i18n/backend/cache.rb +71 -0
- data/lib/i18n/backend/chain.rb +64 -0
- data/lib/i18n/backend/fallbacks.rb +53 -0
- data/lib/i18n/backend/gettext.rb +65 -0
- data/lib/i18n/backend/pluralization.rb +56 -0
- data/lib/i18n/backend/simple.rb +23 -0
- data/lib/i18n/exceptions.rb +61 -0
- data/lib/i18n/gettext.rb +25 -0
- data/lib/i18n/helpers/gettext.rb +35 -0
- data/lib/i18n/locale/fallbacks.rb +100 -0
- data/lib/i18n/locale/tag.rb +27 -0
- data/lib/i18n/locale/tag/parents.rb +24 -0
- data/lib/i18n/locale/tag/rfc4646.rb +78 -0
- data/lib/i18n/locale/tag/simple.rb +44 -0
- data/lib/i18n/string.rb +95 -0
- data/test/all.rb +5 -0
- data/test/api/basics.rb +15 -0
- data/test/api/interpolation.rb +85 -0
- data/test/api/lambda.rb +52 -0
- data/test/api/link.rb +47 -0
- data/test/api/localization/date.rb +65 -0
- data/test/api/localization/date_time.rb +63 -0
- data/test/api/localization/lambda.rb +26 -0
- data/test/api/localization/time.rb +63 -0
- data/test/api/pluralization.rb +37 -0
- data/test/api/translation.rb +51 -0
- data/test/backend/cache/cache_test.rb +57 -0
- data/test/backend/chain/api_test.rb +80 -0
- data/test/backend/chain/chain_test.rb +64 -0
- data/test/backend/fallbacks/api_test.rb +79 -0
- data/test/backend/fallbacks/fallbacks_test.rb +29 -0
- data/test/backend/pluralization/api_test.rb +81 -0
- data/test/backend/pluralization/pluralization_test.rb +39 -0
- data/test/backend/simple/all.rb +5 -0
- data/test/backend/simple/api_test.rb +90 -0
- data/test/backend/simple/lookup_test.rb +24 -0
- data/test/backend/simple/setup.rb +147 -0
- data/test/backend/simple/translations_test.rb +89 -0
- data/test/fixtures/locales/de.po +61 -0
- data/test/fixtures/locales/en.rb +3 -0
- data/test/fixtures/locales/en.yml +3 -0
- data/test/fixtures/locales/plurals.rb +112 -0
- data/test/gettext/api_test.rb +78 -0
- data/test/gettext/backend_test.rb +35 -0
- data/test/i18n_exceptions_test.rb +97 -0
- data/test/i18n_load_path_test.rb +23 -0
- data/test/i18n_test.rb +163 -0
- data/test/locale/fallbacks_test.rb +128 -0
- data/test/locale/tag/rfc4646_test.rb +147 -0
- data/test/locale/tag/simple_test.rb +35 -0
- data/test/string_test.rb +94 -0
- data/test/test_helper.rb +71 -0
- data/test/with_options.rb +34 -0
- metadata +151 -0
@@ -0,0 +1,78 @@
|
|
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#{I18n::Gettext::PLURAL_SEPARATOR}{{count}} apples" => { :one => 'Ein Apfel', :other => '{{count}} Äpfel' },
|
16
|
+
:special => { 'An apple' => { :one => 'Ein spezieller Apfel', :other => '{{count}} spezielle Äpfel' } },
|
17
|
+
:foo => { :bar => { :baz => 'baz-de' } }
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_helper_uses_msg_as_default
|
22
|
+
assert_equal 'Hi Gettext!', _('Hi Gettext!')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_helper_uses_msg_as_key
|
26
|
+
I18n.locale = :de
|
27
|
+
assert_equal 'Hallo Gettext!', _('Hi Gettext!')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_helper_uses_msg_containing_dots_as_default
|
31
|
+
assert_equal 'Sentence 1. Sentence 2.', _('Sentence 1. Sentence 2.')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_helper_uses_msg_containing_dots_as_key
|
35
|
+
I18n.locale = :de
|
36
|
+
assert_equal 'Satz 1. Satz 2.', _('Sentence 1. Sentence 2.')
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_sgettext_defaults_to_the_last_token_of_a_scoped_msgid
|
40
|
+
assert_equal 'baz', sgettext('foo|bar|baz')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_sgettext_looks_up_a_scoped_translation
|
44
|
+
I18n.locale = :de
|
45
|
+
assert_equal 'baz-de', sgettext('foo|bar|baz')
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_pgettext_defaults_to_msgid
|
49
|
+
assert_equal 'baz', pgettext('foo|bar', 'baz', '|')
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_pgettext_looks_up_a_scoped_translation
|
53
|
+
I18n.locale = :de
|
54
|
+
assert_equal 'baz-de', pgettext('foo|bar', 'baz', '|')
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_ngettext_looks_up_msg_id_as_default_singular
|
58
|
+
assert_equal 'An apple', ngettext('An apple', '{{count}} apples', 1)
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_ngettext_looks_up_msg_id_plural_as_default_plural
|
62
|
+
assert_equal '2 apples', ngettext('An apple', '{{count}} apples', 2)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_ngettext_looks_up_msg_id_as_singular
|
66
|
+
I18n.locale = :de
|
67
|
+
assert_equal 'Ein Apfel', ngettext('An apple', '{{count}} apples', 1)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_ngettext_looks_up_msg_id_as_singular
|
71
|
+
I18n.locale = :de
|
72
|
+
assert_equal '2 Äpfel', ngettext('An apple', '{{count}} apples', 2)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_nsgettext_looks_up_msg_id_as_default_singular
|
76
|
+
assert_equal 'A special apple', nsgettext('special|A special apple', '{{count}} special apples', 1, '|')
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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 I18nGettextBackendTest < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
I18n.locale = :en
|
12
|
+
I18n.load_path = [locales_dir + '/de.po']
|
13
|
+
I18n.backend.meta_class.send(:include, I18n::Backend::Gettext)
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
I18n.load_path = nil
|
18
|
+
I18n.backend = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_backend_loads_po_file
|
22
|
+
I18n.backend.send(:init_translations)
|
23
|
+
assert I18n.backend.send(:translations)[:de][:"Axis\001Axis"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_looks_up_translation
|
27
|
+
I18n.locale = :de
|
28
|
+
assert_equal 'Auto', _('car')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_pluralizes_entry
|
32
|
+
I18n.locale = :de
|
33
|
+
assert_equal 'Achsen', ngettext('Axis', 'Axis', 2)
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,97 @@
|
|
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
|
@@ -0,0 +1,23 @@
|
|
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
|
+
backend_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
|
data/test/i18n_test.rb
ADDED
@@ -0,0 +1,163 @@
|
|
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_uses_passed_separator_to_normalize_keys
|
66
|
+
assert_equal [:en, :foo, :bar, :baz, :buz], I18n.send(:normalize_translation_keys, :en, :'baz|buz', :'foo|bar', '|')
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_can_set_exception_handler
|
70
|
+
assert_nothing_raised { I18n.exception_handler = :custom_exception_handler }
|
71
|
+
I18n.exception_handler = :default_exception_handler # revert it
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_uses_custom_exception_handler
|
75
|
+
I18n.exception_handler = :custom_exception_handler
|
76
|
+
I18n.expects(:custom_exception_handler)
|
77
|
+
I18n.translate :bogus
|
78
|
+
I18n.exception_handler = :default_exception_handler # revert it
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_delegates_translate_to_backend
|
82
|
+
I18n.backend.expects(:translate).with 'de', :foo, {}
|
83
|
+
I18n.translate :foo, :locale => 'de'
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_delegates_localize_to_backend
|
87
|
+
I18n.backend.expects(:localize).with 'de', :whatever, :default
|
88
|
+
I18n.localize :whatever, :locale => 'de'
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_translate_given_no_locale_uses_i18n_locale
|
92
|
+
I18n.backend.expects(:translate).with :en, :foo, {}
|
93
|
+
I18n.translate :foo
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_translate_on_nested_symbol_keys_works
|
97
|
+
assert_equal ".", I18n.t(:'currency.format.separator')
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_translate_with_nested_string_keys_works
|
101
|
+
assert_equal ".", I18n.t('currency.format.separator')
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_translate_with_array_as_scope_works
|
105
|
+
assert_equal ".", I18n.t(:separator, :scope => %w(currency format))
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_translate_with_array_containing_dot_separated_strings_as_scope_works
|
109
|
+
assert_equal ".", I18n.t(:separator, :scope => ['currency.format'])
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_translate_with_key_array_and_dot_separated_scope_works
|
113
|
+
assert_equal [".", ","], I18n.t(%w(separator delimiter), :scope => 'currency.format')
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_translate_with_dot_separated_key_array_and_scope_works
|
117
|
+
assert_equal [".", ","], I18n.t(%w(format.separator format.delimiter), :scope => 'currency')
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_translate_with_options_using_scope_works
|
121
|
+
I18n.backend.expects(:translate).with('de', :precision, :scope => :"currency.format")
|
122
|
+
I18n.with_options :locale => 'de', :scope => :'currency.format' do |locale|
|
123
|
+
locale.t :precision
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# def test_translate_given_no_args_raises_missing_translation_data
|
128
|
+
# assert_equal "translation missing: en, no key", I18n.t
|
129
|
+
# end
|
130
|
+
|
131
|
+
def test_translate_given_a_bogus_key_raises_missing_translation_data
|
132
|
+
assert_equal "translation missing: en, bogus", I18n.t(:bogus)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_localize_nil_raises_argument_error
|
136
|
+
assert_raises(I18n::ArgumentError) { I18n.l nil }
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_localize_object_raises_argument_error
|
140
|
+
assert_raises(I18n::ArgumentError) { I18n.l Object.new }
|
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
|
+
|
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
|
+
I18n.fallbacks = Fallbacks.new
|
17
|
+
assert_equal [:'en-US', :en], I18n.fallbacks.defaults
|
18
|
+
end
|
19
|
+
|
20
|
+
test "defaults reflect a manually passed default locale if any" do
|
21
|
+
I18n.fallbacks = Fallbacks.new(:'fi-FI')
|
22
|
+
assert_equal [:'fi-FI', :fi], I18n.fallbacks.defaults
|
23
|
+
I18n.default_locale = :'de-DE'
|
24
|
+
assert_equal [:'fi-FI', :fi], I18n.fallbacks.defaults
|
25
|
+
end
|
26
|
+
|
27
|
+
test "defaults allows to set multiple defaults" do
|
28
|
+
I18n.fallbacks = Fallbacks.new(:'fi-FI', :'se-FI')
|
29
|
+
assert_equal [:'fi-FI', :fi, :'se-FI', :se], I18n.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
|