sayso-i18n 0.5.0.001

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/CHANGELOG.textile +152 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +103 -0
  4. data/ci/Gemfile.no-rails +5 -0
  5. data/ci/Gemfile.no-rails.lock +14 -0
  6. data/ci/Gemfile.rails-2.3.x +9 -0
  7. data/ci/Gemfile.rails-2.3.x.lock +23 -0
  8. data/ci/Gemfile.rails-3.x +9 -0
  9. data/ci/Gemfile.rails-3.x.lock +23 -0
  10. data/lib/i18n.rb +324 -0
  11. data/lib/i18n/backend.rb +19 -0
  12. data/lib/i18n/backend/base.rb +174 -0
  13. data/lib/i18n/backend/cache.rb +102 -0
  14. data/lib/i18n/backend/cascade.rb +53 -0
  15. data/lib/i18n/backend/chain.rb +80 -0
  16. data/lib/i18n/backend/fallbacks.rb +70 -0
  17. data/lib/i18n/backend/flatten.rb +113 -0
  18. data/lib/i18n/backend/flatten_yml.rb +70 -0
  19. data/lib/i18n/backend/gettext.rb +71 -0
  20. data/lib/i18n/backend/interpolation_compiler.rb +121 -0
  21. data/lib/i18n/backend/key_value.rb +100 -0
  22. data/lib/i18n/backend/memoize.rb +46 -0
  23. data/lib/i18n/backend/metadata.rb +65 -0
  24. data/lib/i18n/backend/pluralization.rb +55 -0
  25. data/lib/i18n/backend/simple.rb +87 -0
  26. data/lib/i18n/backend/transliterator.rb +98 -0
  27. data/lib/i18n/config.rb +86 -0
  28. data/lib/i18n/core_ext/hash.rb +29 -0
  29. data/lib/i18n/core_ext/kernel/surpress_warnings.rb +9 -0
  30. data/lib/i18n/core_ext/string/interpolate.rb +105 -0
  31. data/lib/i18n/exceptions.rb +88 -0
  32. data/lib/i18n/gettext.rb +25 -0
  33. data/lib/i18n/gettext/helpers.rb +64 -0
  34. data/lib/i18n/gettext/po_parser.rb +329 -0
  35. data/lib/i18n/interpolate/ruby.rb +31 -0
  36. data/lib/i18n/locale.rb +6 -0
  37. data/lib/i18n/locale/fallbacks.rb +96 -0
  38. data/lib/i18n/locale/tag.rb +28 -0
  39. data/lib/i18n/locale/tag/parents.rb +22 -0
  40. data/lib/i18n/locale/tag/rfc4646.rb +74 -0
  41. data/lib/i18n/locale/tag/simple.rb +39 -0
  42. data/lib/i18n/tests.rb +12 -0
  43. data/lib/i18n/tests/basics.rb +54 -0
  44. data/lib/i18n/tests/defaults.rb +40 -0
  45. data/lib/i18n/tests/interpolation.rb +133 -0
  46. data/lib/i18n/tests/link.rb +56 -0
  47. data/lib/i18n/tests/localization.rb +19 -0
  48. data/lib/i18n/tests/localization/date.rb +84 -0
  49. data/lib/i18n/tests/localization/date_time.rb +77 -0
  50. data/lib/i18n/tests/localization/procs.rb +116 -0
  51. data/lib/i18n/tests/localization/time.rb +76 -0
  52. data/lib/i18n/tests/lookup.rb +74 -0
  53. data/lib/i18n/tests/pluralization.rb +35 -0
  54. data/lib/i18n/tests/procs.rb +55 -0
  55. data/lib/i18n/version.rb +3 -0
  56. data/test/all.rb +8 -0
  57. data/test/api/all_features_test.rb +58 -0
  58. data/test/api/cascade_test.rb +28 -0
  59. data/test/api/chain_test.rb +24 -0
  60. data/test/api/fallbacks_test.rb +30 -0
  61. data/test/api/flatten_yml_test.rb +32 -0
  62. data/test/api/key_value_test.rb +28 -0
  63. data/test/api/memoize_test.rb +60 -0
  64. data/test/api/pluralization_test.rb +30 -0
  65. data/test/api/simple_test.rb +28 -0
  66. data/test/backend/cache_test.rb +83 -0
  67. data/test/backend/cascade_test.rb +85 -0
  68. data/test/backend/chain_test.rb +72 -0
  69. data/test/backend/exceptions_test.rb +23 -0
  70. data/test/backend/fallbacks_test.rb +120 -0
  71. data/test/backend/flatten_yml_test.rb +49 -0
  72. data/test/backend/interpolation_compiler_test.rb +102 -0
  73. data/test/backend/key_value_test.rb +46 -0
  74. data/test/backend/memoize_test.rb +47 -0
  75. data/test/backend/metadata_test.rb +67 -0
  76. data/test/backend/pluralization_test.rb +44 -0
  77. data/test/backend/simple_test.rb +83 -0
  78. data/test/backend/transliterator_test.rb +81 -0
  79. data/test/core_ext/hash_test.rb +30 -0
  80. data/test/core_ext/string/interpolate_test.rb +99 -0
  81. data/test/gettext/api_test.rb +206 -0
  82. data/test/gettext/backend_test.rb +93 -0
  83. data/test/i18n/exceptions_test.rb +116 -0
  84. data/test/i18n/interpolate_test.rb +61 -0
  85. data/test/i18n/load_path_test.rb +26 -0
  86. data/test/i18n_test.rb +236 -0
  87. data/test/locale/fallbacks_test.rb +124 -0
  88. data/test/locale/tag/rfc4646_test.rb +142 -0
  89. data/test/locale/tag/simple_test.rb +32 -0
  90. data/test/run_all.rb +21 -0
  91. data/test/test_data/locales/de.po +72 -0
  92. data/test/test_data/locales/en.rb +3 -0
  93. data/test/test_data/locales/en.yml +3 -0
  94. data/test/test_data/locales/invalid/empty.yml +1 -0
  95. data/test/test_data/locales/plurals.rb +113 -0
  96. data/test/test_helper.rb +56 -0
  97. metadata +194 -0
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Link
6
+ test "linked lookup: if a key resolves to a symbol it looks up the symbol" do
7
+ I18n.backend.store_translations 'en', {
8
+ :link => :linked,
9
+ :linked => 'linked'
10
+ }
11
+ assert_equal 'linked', I18n.backend.translate('en', :link)
12
+ end
13
+
14
+ test "linked lookup: if a key resolves to a dot-separated symbol it looks up the symbol" do
15
+ I18n.backend.store_translations 'en', {
16
+ :link => :"foo.linked",
17
+ :foo => { :linked => 'linked' }
18
+ }
19
+ assert_equal('linked', I18n.backend.translate('en', :link))
20
+ end
21
+
22
+ test "linked lookup: if a dot-separated key resolves to a symbol it looks up the symbol" do
23
+ I18n.backend.store_translations 'en', {
24
+ :foo => { :link => :linked },
25
+ :linked => 'linked'
26
+ }
27
+ assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
28
+ end
29
+
30
+ test "linked lookup: if a dot-separated key resolves to a dot-separated symbol it looks up the symbol" do
31
+ I18n.backend.store_translations 'en', {
32
+ :foo => { :link => :"bar.linked" },
33
+ :bar => { :linked => 'linked' }
34
+ }
35
+ assert_equal('linked', I18n.backend.translate('en', :'foo.link'))
36
+ end
37
+
38
+ test "linked lookup: links always refer to the absolute key" do
39
+ I18n.backend.store_translations 'en', {
40
+ :foo => { :link => :linked, :linked => 'linked in foo' },
41
+ :linked => 'linked absolutely'
42
+ }
43
+ assert_equal 'linked absolutely', I18n.backend.translate('en', :link, :scope => :foo)
44
+ end
45
+
46
+ test "linked lookup: a link can resolve to a namespace in the middle of a dot-separated key" do
47
+ I18n.backend.store_translations 'en', {
48
+ :activemodel => { :errors => { :messages => { :blank => "can't be blank" } } },
49
+ :activerecord => { :errors => { :messages => :"activemodel.errors.messages" } }
50
+ }
51
+ assert_equal "can't be blank", I18n.t(:"activerecord.errors.messages.blank")
52
+ assert_equal "can't be blank", I18n.t(:"activerecord.errors.messages.blank")
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,19 @@
1
+ module I18n
2
+ module Tests
3
+ module Localization
4
+ autoload :Date, 'i18n/tests/localization/date'
5
+ autoload :DateTime, 'i18n/tests/localization/date_time'
6
+ autoload :Time, 'i18n/tests/localization/time'
7
+ autoload :Procs, 'i18n/tests/localization/procs'
8
+
9
+ def self.included(base)
10
+ base.class_eval do
11
+ include I18n::Tests::Localization::Date
12
+ include I18n::Tests::Localization::DateTime
13
+ include I18n::Tests::Localization::Procs
14
+ include I18n::Tests::Localization::Time
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Localization
6
+ module Date
7
+ def setup
8
+ super
9
+ setup_date_translations
10
+ @date = ::Date.new(2008, 3, 1)
11
+ end
12
+
13
+ test "localize Date: given the short format it uses it" do
14
+ # TODO should be Mrz, shouldn't it?
15
+ assert_equal '01. Mar', I18n.l(@date, :format => :short, :locale => :de)
16
+ end
17
+
18
+ test "localize Date: given the long format it uses it" do
19
+ assert_equal '01. März 2008', I18n.l(@date, :format => :long, :locale => :de)
20
+ end
21
+
22
+ test "localize Date: given the default format it uses it" do
23
+ assert_equal '01.03.2008', I18n.l(@date, :format => :default, :locale => :de)
24
+ end
25
+
26
+ test "localize Date: given a day name format it returns the correct day name" do
27
+ assert_equal 'Samstag', I18n.l(@date, :format => '%A', :locale => :de)
28
+ end
29
+
30
+ test "localize Date: given an abbreviated day name format it returns the correct abbreviated day name" do
31
+ assert_equal 'Sa', I18n.l(@date, :format => '%a', :locale => :de)
32
+ end
33
+
34
+ test "localize Date: given a month name format it returns the correct month name" do
35
+ assert_equal 'März', I18n.l(@date, :format => '%B', :locale => :de)
36
+ end
37
+
38
+ test "localize Date: given an abbreviated month name format it returns the correct abbreviated month name" do
39
+ # TODO should be Mrz, shouldn't it?
40
+ assert_equal 'Mar', I18n.l(@date, :format => '%b', :locale => :de)
41
+ end
42
+
43
+ test "localize Date: given an unknown format it does not fail" do
44
+ assert_nothing_raised { I18n.l(@date, :format => '%x') }
45
+ end
46
+
47
+ test "localize Date: given nil it raises I18n::ArgumentError" do
48
+ assert_raise(I18n::ArgumentError) { I18n.l(nil) }
49
+ end
50
+
51
+ test "localize Date: given a plain Object it raises I18n::ArgumentError" do
52
+ assert_raise(I18n::ArgumentError) { I18n.l(Object.new) }
53
+ end
54
+
55
+ test "localize Date: given a format is missing it raises I18n::MissingTranslationData" do
56
+ assert_raise(I18n::MissingTranslationData) { I18n.l(@date, :format => :missing) }
57
+ end
58
+
59
+ test "localize Date: it does not alter the format string" do
60
+ assert_equal '01. Februar 2009', I18n.l(::Date.parse('2009-02-01'), :format => :long, :locale => :de)
61
+ assert_equal '01. Oktober 2009', I18n.l(::Date.parse('2009-10-01'), :format => :long, :locale => :de)
62
+ end
63
+
64
+ protected
65
+
66
+ def setup_date_translations
67
+ I18n.backend.store_translations :de, {
68
+ :date => {
69
+ :formats => {
70
+ :default => "%d.%m.%Y",
71
+ :short => "%d. %b",
72
+ :long => "%d. %B %Y",
73
+ },
74
+ :day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
75
+ :abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
76
+ :month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
77
+ :abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil)
78
+ }
79
+ }
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Localization
6
+ module DateTime
7
+ def setup
8
+ super
9
+ setup_datetime_translations
10
+ @datetime = ::DateTime.new(2008, 3, 1, 6)
11
+ @other_datetime = ::DateTime.new(2008, 3, 1, 18)
12
+ end
13
+
14
+ test "localize DateTime: given the short format it uses it" do
15
+ # TODO should be Mrz, shouldn't it?
16
+ assert_equal '01. Mar 06:00', I18n.l(@datetime, :format => :short, :locale => :de)
17
+ end
18
+
19
+ test "localize DateTime: given the long format it uses it" do
20
+ assert_equal '01. März 2008 06:00', I18n.l(@datetime, :format => :long, :locale => :de)
21
+ end
22
+
23
+ test "localize DateTime: given the default format it uses it" do
24
+ # TODO should be Mrz, shouldn't it?
25
+ assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@datetime, :format => :default, :locale => :de)
26
+ end
27
+
28
+ test "localize DateTime: given a day name format it returns the correct day name" do
29
+ assert_equal 'Samstag', I18n.l(@datetime, :format => '%A', :locale => :de)
30
+ end
31
+
32
+ test "localize DateTime: given an abbreviated day name format it returns the correct abbreviated day name" do
33
+ assert_equal 'Sa', I18n.l(@datetime, :format => '%a', :locale => :de)
34
+ end
35
+
36
+ test "localize DateTime: given a month name format it returns the correct month name" do
37
+ assert_equal 'März', I18n.l(@datetime, :format => '%B', :locale => :de)
38
+ end
39
+
40
+ test "localize DateTime: given an abbreviated month name format it returns the correct abbreviated month name" do
41
+ # TODO should be Mrz, shouldn't it?
42
+ assert_equal 'Mar', I18n.l(@datetime, :format => '%b', :locale => :de)
43
+ end
44
+
45
+ test "localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
46
+ assert_equal 'am', I18n.l(@datetime, :format => '%p', :locale => :de)
47
+ assert_equal 'pm', I18n.l(@other_datetime, :format => '%p', :locale => :de)
48
+ end
49
+
50
+ test "localize DateTime: given an unknown format it does not fail" do
51
+ assert_nothing_raised { I18n.l(@datetime, :format => '%x') }
52
+ end
53
+
54
+ test "localize DateTime: given a format is missing it raises I18n::MissingTranslationData" do
55
+ assert_raise(I18n::MissingTranslationData) { I18n.l(@datetime, :format => :missing) }
56
+ end
57
+
58
+ protected
59
+
60
+ def setup_datetime_translations
61
+ # time translations might have been set up in Tests::Api::Localization::Time
62
+ I18n.backend.store_translations :de, {
63
+ :time => {
64
+ :formats => {
65
+ :default => "%a, %d. %b %Y %H:%M:%S %z",
66
+ :short => "%d. %b %H:%M",
67
+ :long => "%d. %B %Y %H:%M"
68
+ },
69
+ :am => 'am',
70
+ :pm => 'pm'
71
+ }
72
+ }
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,116 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Localization
6
+ module Procs
7
+ test "localize: using day names from lambdas" do
8
+ setup_time_proc_translations
9
+ time = ::Time.utc(2008, 3, 1, 6, 0)
10
+ assert_match(/Суббота/, I18n.l(time, :format => "%A, %d %B", :locale => :ru))
11
+ assert_match(/суббота/, I18n.l(time, :format => "%d %B (%A)", :locale => :ru))
12
+ end
13
+
14
+ test "localize: using month names from lambdas" do
15
+ setup_time_proc_translations
16
+ time = ::Time.utc(2008, 3, 1, 6, 0)
17
+ assert_match(/марта/, I18n.l(time, :format => "%d %B %Y", :locale => :ru))
18
+ assert_match(/Март /, I18n.l(time, :format => "%B %Y", :locale => :ru))
19
+ end
20
+
21
+ test "localize: using abbreviated day names from lambdas" do
22
+ setup_time_proc_translations
23
+ time = ::Time.utc(2008, 3, 1, 6, 0)
24
+ assert_match(/марта/, I18n.l(time, :format => "%d %b %Y", :locale => :ru))
25
+ assert_match(/март /, I18n.l(time, :format => "%b %Y", :locale => :ru))
26
+ end
27
+
28
+ test "localize Date: given a format that resolves to a Proc it calls the Proc with the object" do
29
+ setup_time_proc_translations
30
+ date = ::Date.new(2008, 3, 1, 6)
31
+ assert_equal '[Sat, 01 Mar 2008, {}]', I18n.l(date, :format => :proc, :locale => :ru)
32
+ end
33
+
34
+ test "localize Date: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
35
+ setup_time_proc_translations
36
+ date = ::Date.new(2008, 3, 1, 6)
37
+ assert_equal '[Sat, 01 Mar 2008, {:foo=>"foo"}]', I18n.l(date, :format => :proc, :foo => 'foo', :locale => :ru)
38
+ end
39
+
40
+ test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object" do
41
+ setup_time_proc_translations
42
+ datetime = ::DateTime.new(2008, 3, 1, 6)
43
+ assert_equal '[Sat, 01 Mar 2008 06:00:00 +00:00, {}]', I18n.l(datetime, :format => :proc, :locale => :ru)
44
+ end
45
+
46
+ test "localize DateTime: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
47
+ setup_time_proc_translations
48
+ datetime = ::DateTime.new(2008, 3, 1, 6)
49
+ assert_equal '[Sat, 01 Mar 2008 06:00:00 +00:00, {:foo=>"foo"}]', I18n.l(datetime, :format => :proc, :foo => 'foo', :locale => :ru)
50
+ end
51
+
52
+ test "localize Time: given a format that resolves to a Proc it calls the Proc with the object" do
53
+ setup_time_proc_translations
54
+ time = ::Time.utc(2008, 3, 1, 6, 0)
55
+ assert_equal inspect_args([time, {}]), I18n.l(time, :format => :proc, :locale => :ru)
56
+ end
57
+
58
+ test "localize Time: given a format that resolves to a Proc it calls the Proc with the object and extra options" do
59
+ setup_time_proc_translations
60
+ time = ::Time.utc(2008, 3, 1, 6, 0)
61
+ options = { :foo => 'foo' }
62
+ assert_equal inspect_args([time, options]), I18n.l(time, options.merge(:format => :proc, :locale => :ru))
63
+ end
64
+
65
+ protected
66
+
67
+ def inspect_args(args)
68
+ args = args.map do |arg|
69
+ case arg
70
+ when ::Time, ::DateTime
71
+ arg.strftime('%a, %d %b %Y %H:%M:%S %Z').sub('+0000', '+00:00')
72
+ when ::Date
73
+ arg.strftime('%a, %d %b %Y')
74
+ when Hash
75
+ arg.delete(:fallback)
76
+ arg.inspect
77
+ else
78
+ arg.inspect
79
+ end
80
+ end
81
+ "[#{args.join(', ')}]"
82
+ end
83
+
84
+ def setup_time_proc_translations
85
+ I18n.backend.store_translations :ru, {
86
+ :time => {
87
+ :formats => {
88
+ :proc => lambda { |*args| inspect_args(args) }
89
+ }
90
+ },
91
+ :date => {
92
+ :formats => {
93
+ :proc => lambda { |*args| inspect_args(args) }
94
+ },
95
+ :'day_names' => lambda { |key, options|
96
+ (options[:format] =~ /^%A/) ?
97
+ %w(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота) :
98
+ %w(воскресенье понедельник вторник среда четверг пятница суббота)
99
+ },
100
+ :'month_names' => lambda { |key, options|
101
+ (options[:format] =~ /(%d|%e)(\s*)?(%B)/) ?
102
+ %w(января февраля марта апреля мая июня июля августа сентября октября ноября декабря).unshift(nil) :
103
+ %w(Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь).unshift(nil)
104
+ },
105
+ :'abbr_month_names' => lambda { |key, options|
106
+ (options[:format] =~ /(%d|%e)(\s*)(%b)/) ?
107
+ %w(янв. февр. марта апр. мая июня июля авг. сент. окт. нояб. дек.).unshift(nil) :
108
+ %w(янв. февр. март апр. май июнь июль авг. сент. окт. нояб. дек.).unshift(nil)
109
+ },
110
+ }
111
+ }
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Localization
6
+ module Time
7
+ def setup
8
+ super
9
+ setup_time_translations
10
+ @time = ::Time.utc(2008, 3, 1, 6, 0)
11
+ @other_time = ::Time.utc(2008, 3, 1, 18, 0)
12
+ end
13
+
14
+ test "localize Time: given the short format it uses it" do
15
+ # TODO should be Mrz, shouldn't it?
16
+ assert_equal '01. Mar 06:00', I18n.l(@time, :format => :short, :locale => :de)
17
+ end
18
+
19
+ test "localize Time: given the long format it uses it" do
20
+ assert_equal '01. März 2008 06:00', I18n.l(@time, :format => :long, :locale => :de)
21
+ end
22
+
23
+ # TODO Seems to break on Windows because ENV['TZ'] is ignored. What's a better way to do this?
24
+ # def test_localize_given_the_default_format_it_uses_it
25
+ # assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@time, :format => :default, :locale => :de)
26
+ # end
27
+
28
+ test "localize Time: given a day name format it returns the correct day name" do
29
+ assert_equal 'Samstag', I18n.l(@time, :format => '%A', :locale => :de)
30
+ end
31
+
32
+ test "localize Time: given an abbreviated day name format it returns the correct abbreviated day name" do
33
+ assert_equal 'Sa', I18n.l(@time, :format => '%a', :locale => :de)
34
+ end
35
+
36
+ test "localize Time: given a month name format it returns the correct month name" do
37
+ assert_equal 'März', I18n.l(@time, :format => '%B', :locale => :de)
38
+ end
39
+
40
+ test "localize Time: given an abbreviated month name format it returns the correct abbreviated month name" do
41
+ # TODO should be Mrz, shouldn't it?
42
+ assert_equal 'Mar', I18n.l(@time, :format => '%b', :locale => :de)
43
+ end
44
+
45
+ test "localize Time: given a meridian indicator format it returns the correct meridian indicator" do
46
+ assert_equal 'am', I18n.l(@time, :format => '%p', :locale => :de)
47
+ assert_equal 'pm', I18n.l(@other_time, :format => '%p', :locale => :de)
48
+ end
49
+
50
+ test "localize Time: given an unknown format it does not fail" do
51
+ assert_nothing_raised { I18n.l(@time, :format => '%x') }
52
+ end
53
+
54
+ test "localize Time: given a format is missing it raises I18n::MissingTranslationData" do
55
+ assert_raise(I18n::MissingTranslationData) { I18n.l(@time, :format => :missing) }
56
+ end
57
+
58
+ protected
59
+
60
+ def setup_time_translations
61
+ I18n.backend.store_translations :de, {
62
+ :time => {
63
+ :formats => {
64
+ :default => "%a, %d. %b %Y %H:%M:%S %z",
65
+ :short => "%d. %b %H:%M",
66
+ :long => "%d. %B %Y %H:%M",
67
+ },
68
+ :am => 'am',
69
+ :pm => 'pm'
70
+ }
71
+ }
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+
3
+ module I18n
4
+ module Tests
5
+ module Lookup
6
+ def setup
7
+ super
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" })
10
+ end
11
+
12
+ test "lookup: it returns a string" do
13
+ assert_equal("a", I18n.t(:string))
14
+ end
15
+
16
+ test "lookup: it returns hash" do
17
+ assert_equal({ :a => "b" }, I18n.t(:hash))
18
+ end
19
+
20
+ test "lookup: it returns a array" do
21
+ assert_equal(%w(a b c), I18n.t(:array))
22
+ end
23
+
24
+ test "lookup: it returns a native true" do
25
+ assert I18n.t(:truthy) === true
26
+ end
27
+
28
+ test "lookup: it returns a native false" do
29
+ assert I18n.t(:falsy) === false
30
+ end
31
+
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)
34
+ end
35
+
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) }
38
+ end
39
+
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) }
42
+ end
43
+
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])
46
+ end
47
+
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 => '|')
52
+ end
53
+
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) }
59
+ end
60
+
61
+ test "lookup: a resulting String is not frozen" do
62
+ assert !I18n.t(:string).frozen?
63
+ end
64
+
65
+ test "lookup: a resulting Array is not frozen" do
66
+ assert !I18n.t(:array).frozen?
67
+ end
68
+
69
+ test "lookup: a resulting Hash is not frozen" do
70
+ assert !I18n.t(:hash).frozen?
71
+ end
72
+ end
73
+ end
74
+ end