1 require File.join( File.dirname(__FILE__), '..', 'test_helper' )
2 require 'globalize/locale/fallbacks'
4 include Globalize::Locale
5 I18n.default_locale = :'en-US' # This has to be set explicitly, no longer default for I18n
7 class FallbacksTest < ActiveSupport::TestCase
9 I18n.fallbacks = Fallbacks.new
13 I18n.default_locale = :'en-US'
16 test "#[] caches computed results" do
18 assert_equal( { :en => [:en, :"en-US", :root] }, I18n.fallbacks )
21 test "#defaults always reflect the I18n.default_locale if no default has been set manually" do
22 I18n.default_locale = :'en-US'
23 assert_equal( [:'en-US', :en, :root], I18n.fallbacks.defaults )
26 test "#defaults always reflect a manually passed default locale if any" do
27 I18n.fallbacks = Fallbacks.new(:'fi-FI')
28 assert_equal( [:'fi-FI', :fi, :root], I18n.fallbacks.defaults )
29 I18n.default_locale = :'de-DE'
30 assert_equal( [:'fi-FI', :fi, :root], I18n.fallbacks.defaults )
33 test "#defaults allows to set multiple defaults" do
34 I18n.fallbacks = Fallbacks.new(:'fi-FI', :'se-FI')
35 assert_equal( [:'fi-FI', :fi, :'se-FI', :se, :root], I18n.fallbacks.defaults )
39 class NoMappingFallbacksTest < ActiveSupport::TestCase
41 @fallbacks = Fallbacks.new(:'en-US')
44 test "returns [:es, :en-US, :root] for :es" do
45 assert_equal [:es, :"en-US", :en, :root], @fallbacks[:es]
48 test "returns [:es-ES, :es, :en-US, :root] for :es-ES" do
49 assert_equal [:"es-ES", :es, :"en-US", :en, :root], @fallbacks[:"es-ES"]
52 test "returns [:es-MX, :es, :en-US, :root] for :es-MX" do
53 assert_equal [:"es-MX", :es, :"en-US", :en, :root], @fallbacks[:"es-MX"]
56 test "returns [:es-Latn-ES, :es-Latn, :es, :en-US, :root] for :es-Latn-ES" do
57 assert_equal [:"es-Latn-ES", :"es-Latn", :es, :"en-US", :en, :root], @fallbacks[:'es-Latn-ES']
60 test "returns [:en, :en-US, :root] for :en" do
61 assert_equal [:en, :"en-US", :root], @fallbacks[:en]
64 test "returns [:en-US, :en, :root] for :en-US (special case: locale == default)" do
65 assert_equal [:"en-US", :en, :root], @fallbacks[:"en-US"]
69 class CaMappingFallbacksTest < ActiveSupport::TestCase
70 # Most people who speak Catalan also live in Spain, so test is safe to assume
71 # that they also speak Spanish as spoken in Spain.
73 @fallbacks = Fallbacks.new(:'en-US')
74 @fallbacks.map :ca => :"es-ES"
77 test "returns [:ca, :es-ES, :es, :en-US, :root] for :ca" do
78 assert_equal [:ca, :"es-ES", :es, :"en-US", :en, :root], @fallbacks[:ca]
81 test "returns [:ca-ES, :ca, :es-ES, :es, :en-US, :root] for :ca-ES" do
82 assert_equal [:"ca-ES", :ca, :"es-ES", :es, :"en-US", :en, :root], @fallbacks[:"ca-ES"]
86 class ArMappingFallbacksTest < ActiveSupport::TestCase
87 # People who speak Arabic as spoken in Palestine often times also speak
88 # Hebrew as spoken in Israel. However test is in no way safe to assume that
89 # everybody who speaks Arabic also speaks Hebrew.
91 @fallbacks = Fallbacks.new(:'en-US')
92 @fallbacks.map :"ar-PS" => :"he-IL"
95 test "returns [:ar, :en-US, :root] for :ar" do
96 assert_equal [:ar, :"en-US", :en, :root], @fallbacks[:ar]
99 test "returns [:ar-EG, :ar, :en-US, :root] for :ar-EG" do
100 assert_equal [:"ar-EG", :ar, :"en-US", :en, :root], @fallbacks[:"ar-EG"]
103 test "returns [:ar-PS, :ar, :he-IL, :he, :en-US, :root] for :ar-PS" do
104 assert_equal [:"ar-PS", :ar, :"he-IL", :he, :"en-US", :en, :root], @fallbacks[:"ar-PS"]
108 class SmsMappingFallbacksTest < ActiveSupport::TestCase
109 # Sami people live in several scandinavian countries. In Finnland many people
110 # know Swedish and Finnish. Thus, test can be assumed that Sami living in
111 # Finnland also speak Swedish and Finnish.
113 @fallbacks = Fallbacks.new(:'en-US')
114 @fallbacks.map :sms => [:"se-FI", :"fi-FI"]
117 test "returns [:sms-FI, :sms, :se-FI, :se, :fi-FI, :fi, :en-US, :root] for :sms-FI" do
118 assert_equal [:"sms-FI", :sms, :"se-FI", :se, :"fi-FI", :fi, :"en-US", :en, :root], @fallbacks[:"sms-FI"]
122 class DeAtMappingFallbacksTest < ActiveSupport::TestCase
124 @fallbacks = Fallbacks.new(:'en-US')
125 @fallbacks.map :"de-AT" => :"de-DE"
128 test "returns [:de, :en-US, :root] for de" do
129 assert_equal [:de, :"en-US", :en, :root], @fallbacks[:"de"]
132 test "returns [:de-DE, :de, :en-US, :root] for de-DE" do
133 assert_equal [:"de-DE", :de, :"en-US", :en, :root], @fallbacks[:"de-DE"]
136 test "returns [:de-AT, :de, :de-DE, :en-US, :root] for de-AT" do
137 assert_equal [:"de-AT", :de, :"de-DE", :"en-US", :en, :root], @fallbacks[:"de-AT"]
141 class DeMappingFallbacksTest < ActiveSupport::TestCase
143 @fallbacks = Fallbacks.new(:'en-US')
144 @fallbacks.map :de => :en, :he => :en
147 test "returns [:de, :en, :root] for :de" do
148 assert_equal [:de, :en, :"en-US", :root], @fallbacks[:de]
151 test "returns [:he, :en, :root] for :de" do
152 assert_equal [:he, :en, :"en-US", :root], @fallbacks[:he]