File: link.rb

package info (click to toggle)
libi18n-ruby 0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 576 kB
  • ctags: 619
  • sloc: ruby: 4,655; makefile: 5
file content (56 lines) | stat: -rw-r--r-- 2,282 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# encoding: utf-8

module Tests
  module Api
    module Link
      define_method "test linked lookup: if a key resolves to a symbol it looks up the symbol" do
        I18n.backend.store_translations 'en', {
          :link  => :linked,
          :linked => 'linked'
        }
        assert_equal 'linked', I18n.backend.translate('en', :link)
      end

      define_method "test linked lookup: if a key resolves to a dot-separated symbol it looks up the symbol" do
        I18n.backend.store_translations 'en', {
          :link => :"foo.linked",
          :foo  => { :linked => 'linked' }
        }
        assert_equal('linked', I18n.backend.translate('en', :link))
      end

      define_method "test linked lookup: if a dot-separated key resolves to a symbol it looks up the symbol" do
        I18n.backend.store_translations 'en', {
          :foo    => { :link => :linked },
          :linked => 'linked'
        }
        assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
      end
      
      define_method "test linked lookup: if a dot-separated key resolves to a dot-separated symbol it looks up the symbol" do
        I18n.backend.store_translations 'en', {
          :foo => { :link   => :"bar.linked" },
          :bar => { :linked => 'linked' }
        }
        assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
      end

      define_method "test linked lookup: links always refer to the absolute key" do
        I18n.backend.store_translations 'en', {
          :foo => { :link => :linked, :linked => 'linked in foo' },
          :linked => 'linked absolutely'
        }
        assert_equal 'linked absolutely', I18n.backend.translate('en', :link, :scope => :foo)
      end

      define_method "test linked lookup: a link can resolve to a namespace in the middle of a dot-separated key" do
        I18n.backend.store_translations 'en', {
          :activemodel  => { :errors => { :messages => { :blank => "can't be blank" } } },
          :activerecord => { :errors => { :messages => :"activemodel.errors.messages" } }
        }
        assert_equal "can't be blank", I18n.t(:"activerecord.errors.messages.blank")
        assert_equal "can't be blank", I18n.t(:"activerecord.errors.messages.blank")
      end
    end
  end
end