8 I18n.backend.store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' }, :falsy => false, :truthy => true,
9 :string => "a", :array => %w(a b c), :hash => { "a" => "b" })
12 test "lookup: it returns a string" do
13 assert_equal("a", I18n.t(:string))
16 test "lookup: it returns hash" do
17 assert_equal({ :a => "b" }, I18n.t(:hash))
20 test "lookup: it returns a array" do
21 assert_equal(%w(a b c), I18n.t(:array))
24 test "lookup: it returns a native true" do
25 assert I18n.t(:truthy) === true
28 test "lookup: it returns a native false" do
29 assert I18n.t(:falsy) === false
32 test "lookup: given a missing key, no default and no raise option it returns an error message" do
33 assert_equal "translation missing: en.missing", I18n.t(:missing)
36 test "lookup: given a missing key, no default and the raise option it raises MissingTranslationData" do
37 assert_raise(I18n::MissingTranslationData) { I18n.t(:missing, :raise => true) }
40 test "lookup: does not raise an exception if no translation data is present for the given locale" do
41 assert_nothing_raised { I18n.t(:foo, :locale => :xx) }
44 test "lookup: given an array of keys it translates all of them" do
45 assert_equal %w(bar baz), I18n.t([:bar, :baz], :scope => [:foo])
48 test "lookup: using a custom scope separator" do
49 # data must have been stored using the custom separator when using the ActiveRecord backend
50 I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
51 assert_equal 'bar', I18n.t('foo|bar', :separator => '|')
54 # In fact it probably *should* fail but Rails currently relies on using the default locale instead.
55 # So we'll stick to this for now until we get it fixed in Rails.
56 test "lookup: given nil as a locale it does not raise but use the default locale" do
57 # assert_raise(I18n::InvalidLocale) { I18n.t(:bar, :locale => nil) }
58 assert_nothing_raised { I18n.t(:bar, :locale => nil) }
61 test "lookup: a resulting String is not frozen" do
62 assert !I18n.t(:string).frozen?
65 test "lookup: a resulting Array is not frozen" do
66 assert !I18n.t(:array).frozen?
69 test "lookup: a resulting Hash is not frozen" do
70 assert !I18n.t(:hash).frozen?