i18n 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of i18n might be problematic. Click here for more details.
- data/README.textile +44 -9
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/i18n.rb +60 -15
- data/lib/i18n/backend.rb +14 -0
- data/lib/i18n/backend/active_record.rb +69 -0
- data/lib/i18n/backend/active_record/store_procs.rb +37 -0
- data/lib/i18n/backend/active_record/translation.rb +82 -0
- data/lib/i18n/backend/active_record_missing.rb +55 -0
- data/lib/i18n/backend/base.rb +235 -0
- data/lib/i18n/backend/cache.rb +71 -0
- data/lib/i18n/backend/chain.rb +74 -0
- data/lib/i18n/backend/fallbacks.rb +51 -0
- data/lib/i18n/backend/gettext.rb +75 -0
- data/lib/i18n/backend/helpers.rb +53 -0
- data/lib/i18n/backend/metadata.rb +73 -0
- data/lib/i18n/backend/pluralization.rb +57 -0
- data/lib/i18n/backend/simple.rb +15 -227
- data/lib/i18n/core_ext/object/meta_class.rb +5 -0
- data/lib/i18n/{string.rb → core_ext/string/interpolate.rb} +2 -0
- data/lib/i18n/exceptions.rb +2 -0
- data/lib/i18n/gettext.rb +25 -0
- data/lib/i18n/helpers.rb +5 -0
- data/lib/i18n/helpers/gettext.rb +64 -0
- data/lib/i18n/locale.rb +6 -0
- data/lib/i18n/locale/fallbacks.rb +98 -0
- data/lib/i18n/locale/tag.rb +28 -0
- data/lib/i18n/locale/tag/parents.rb +24 -0
- data/lib/i18n/locale/tag/rfc4646.rb +76 -0
- data/lib/i18n/locale/tag/simple.rb +41 -0
- data/test/all.rb +7 -2
- data/test/api/basics.rb +3 -1
- data/test/api/interpolation.rb +35 -4
- data/test/api/lambda.rb +5 -3
- data/test/api/link.rb +4 -2
- data/test/api/localization/date.rb +2 -0
- data/test/api/localization/date_time.rb +3 -1
- data/test/api/localization/lambda.rb +4 -2
- data/test/api/localization/time.rb +3 -1
- data/test/api/pluralization.rb +12 -15
- data/test/api/translation.rb +5 -3
- data/test/backend/active_record/active_record_test.rb +40 -0
- data/test/backend/active_record/all.rb +3 -0
- data/test/backend/active_record/api_test.rb +54 -0
- data/test/backend/active_record/setup.rb +166 -0
- data/test/backend/active_record_missing/active_record_missing_test.rb +63 -0
- data/test/backend/all/api_test.rb +88 -0
- data/test/backend/cache/cache_test.rb +69 -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 +84 -0
- data/test/backend/fallbacks/fallbacks_test.rb +57 -0
- data/test/backend/metadata/metadata_test.rb +65 -0
- data/test/backend/pluralization/api_test.rb +86 -0
- data/test/backend/pluralization/pluralization_test.rb +43 -0
- data/test/backend/simple/all.rb +2 -0
- data/test/backend/simple/api_test.rb +27 -20
- data/test/backend/simple/helpers_test.rb +26 -0
- data/test/backend/simple/lookup_test.rb +2 -1
- data/test/backend/simple/{setup/localization.rb → setup.rb} +29 -11
- data/test/backend/simple/translations_test.rb +1 -6
- data/test/{string_test.rb → core_ext/string/interpolate_test.rb} +4 -2
- data/test/fixtures/locales/de.po +67 -0
- data/test/fixtures/locales/en.rb +2 -0
- data/test/fixtures/locales/plurals.rb +113 -0
- data/test/gettext/api_test.rb +204 -0
- data/test/gettext/backend_test.rb +84 -0
- data/test/i18n_exceptions_test.rb +3 -1
- data/test/i18n_load_path_test.rb +8 -1
- data/test/i18n_test.rb +30 -7
- data/test/locale/fallbacks_test.rb +128 -0
- data/test/locale/tag/rfc4646_test.rb +145 -0
- data/test/locale/tag/simple_test.rb +35 -0
- data/test/test_helper.rb +11 -5
- data/test/with_options.rb +2 -0
- metadata +75 -11
- data/test/backend/simple/setup/base.rb +0 -21
data/test/api/lambda.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Tests
|
2
4
|
module Backend
|
3
5
|
module Api
|
@@ -16,8 +18,8 @@ module Tests
|
|
16
18
|
def test_translate_proc_with_pluralize
|
17
19
|
setup_proc_translations
|
18
20
|
params = { :zero => 'zero', :one => 'one', :other => 'other' }
|
19
|
-
assert_equal 'zero',
|
20
|
-
assert_equal 'one',
|
21
|
+
assert_equal 'zero', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 0))
|
22
|
+
assert_equal 'one', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 1))
|
21
23
|
assert_equal 'other', I18n.backend.translate('en', :lambda_for_pluralize, params.merge(:count => 2))
|
22
24
|
end
|
23
25
|
|
@@ -47,4 +49,4 @@ module Tests
|
|
47
49
|
end
|
48
50
|
end
|
49
51
|
end
|
50
|
-
end
|
52
|
+
end
|
data/test/api/link.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Tests
|
2
4
|
module Backend
|
3
5
|
module Api
|
@@ -28,7 +30,7 @@ module Tests
|
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
31
|
-
|
33
|
+
|
32
34
|
def setup_linked_translations
|
33
35
|
I18n.backend.store_translations 'en', {
|
34
36
|
:foo => 'foo',
|
@@ -42,4 +44,4 @@ module Tests
|
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
45
|
-
end
|
47
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Tests
|
2
4
|
module Backend
|
3
5
|
module Api
|
@@ -12,7 +14,7 @@ module Tests
|
|
12
14
|
assert_match /марта/, I18n.backend.localize('ru', time, "%d %B %Y")
|
13
15
|
assert_match /Март/, I18n.backend.localize('ru', time, "%B %Y")
|
14
16
|
end
|
15
|
-
|
17
|
+
|
16
18
|
def test_localize_uses_lambda_abbr_day_names
|
17
19
|
assert_match /марта/, I18n.backend.localize('ru', time, "%d %b %Y")
|
18
20
|
assert_match /март/, I18n.backend.localize('ru', time, "%b %Y")
|
@@ -21,4 +23,4 @@ module Tests
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
24
|
-
end
|
26
|
+
end
|
data/test/api/pluralization.rb
CHANGED
@@ -1,40 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Tests
|
2
4
|
module Backend
|
3
5
|
module Api
|
4
6
|
module Pluralization
|
5
|
-
def test_pluralize_given_nil_returns_the_given_entry
|
6
|
-
entry = {:one => 'bar', :other => 'bars'}
|
7
|
-
assert_equal entry, I18n.backend.send(:pluralize, nil, entry, nil)
|
8
|
-
end
|
9
|
-
|
10
7
|
def test_pluralize_given_0_returns_zero_string_if_zero_key_given
|
11
|
-
assert_equal 'zero', I18n.
|
8
|
+
assert_equal 'zero', I18n.t(:default => { :zero => 'zero' }, :count => 0)
|
12
9
|
end
|
13
10
|
|
14
11
|
def test_pluralize_given_0_returns_plural_string_if_no_zero_key_given
|
15
|
-
assert_equal 'bars', I18n.
|
12
|
+
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 0)
|
16
13
|
end
|
17
14
|
|
18
15
|
def test_pluralize_given_1_returns_singular_string
|
19
|
-
assert_equal 'bar', I18n.
|
16
|
+
assert_equal 'bar', I18n.t(:default => { :one => 'bar' }, :count => 1)
|
20
17
|
end
|
21
18
|
|
22
19
|
def test_pluralize_given_2_returns_plural_string
|
23
|
-
assert_equal 'bars', I18n.
|
20
|
+
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 2)
|
24
21
|
end
|
25
22
|
|
26
23
|
def test_pluralize_given_3_returns_plural_string
|
27
|
-
assert_equal 'bars', I18n.
|
24
|
+
assert_equal 'bars', I18n.t(:default => { :other => 'bars' }, :count => 3)
|
28
25
|
end
|
29
26
|
|
30
|
-
def
|
31
|
-
|
27
|
+
def test_pluralize_given_nil_returns_the_given_entry
|
28
|
+
assert_equal({ :zero => 'zero' }, I18n.t(:default => { :zero => 'zero' }, :count => nil))
|
32
29
|
end
|
33
30
|
|
34
|
-
def
|
35
|
-
|
31
|
+
def test_interpolate_given_incomplete_pluralization_data_raises_invalid_pluralization_data
|
32
|
+
assert_raises(I18n::InvalidPluralizationData){ I18n.t(:default => { :one => 'bar' }, :count => 2) }
|
36
33
|
end
|
37
34
|
end
|
38
35
|
end
|
39
36
|
end
|
40
|
-
end
|
37
|
+
end
|
data/test/api/translation.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Tests
|
2
4
|
module Backend
|
3
5
|
module Api
|
@@ -5,7 +7,7 @@ module Tests
|
|
5
7
|
def translate(key, options = {})
|
6
8
|
I18n.backend.translate('en', key, options)
|
7
9
|
end
|
8
|
-
|
10
|
+
|
9
11
|
def test_given_no_keys_it_returns_the_default
|
10
12
|
assert_equal 'default', translate(nil, :default => 'default')
|
11
13
|
end
|
@@ -33,7 +35,7 @@ module Tests
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def test_translate_with_a_missing_key_and_no_default_raises_missing_translation_data
|
36
|
-
assert_raises(I18n::MissingTranslationData) do
|
38
|
+
assert_raises(I18n::MissingTranslationData) do
|
37
39
|
translate(:missing)
|
38
40
|
end
|
39
41
|
end
|
@@ -46,4 +48,4 @@ module Tests
|
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
49
|
-
end
|
51
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
3
|
+
require 'i18n/backend/active_record'
|
4
|
+
|
5
|
+
class I18nActiveRecordBackendTest < Test::Unit::TestCase
|
6
|
+
include Tests::Backend::ActiveRecord::Setup::Base
|
7
|
+
|
8
|
+
def test_store_translations_does_not_allow_ambigous_keys_1
|
9
|
+
I18n::Backend::ActiveRecord::Translation.delete_all
|
10
|
+
I18n.backend.store_translations(:en, :foo => 'foo')
|
11
|
+
I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
|
12
|
+
I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
|
13
|
+
|
14
|
+
translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo', '.').all
|
15
|
+
assert_equal %w(bar baz), translations.map(&:value)
|
16
|
+
|
17
|
+
assert_equal({ :bar => 'bar', :baz => 'baz' }, I18n.t(:foo))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_store_translations_does_not_allow_ambigous_keys_2
|
21
|
+
I18n::Backend::ActiveRecord::Translation.delete_all
|
22
|
+
I18n.backend.store_translations(:en, :foo => { :bar => 'bar' })
|
23
|
+
I18n.backend.store_translations(:en, :foo => { :baz => 'baz' })
|
24
|
+
I18n.backend.store_translations(:en, :foo => 'foo')
|
25
|
+
|
26
|
+
translations = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo', '.').all
|
27
|
+
assert_equal %w(foo), translations.map(&:value)
|
28
|
+
|
29
|
+
assert_equal 'foo', I18n.t(:foo)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_missing_translations_table_does_not_cause_available_locales_to_error
|
33
|
+
I18n::Backend::ActiveRecord::Translation.expects(:available_locales).raises(::ActiveRecord::StatementInvalid)
|
34
|
+
assert_equal [], I18n.backend.available_locales
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_expand_keys
|
38
|
+
assert_equal %w(foo foo.bar foo.bar.baz), I18n.backend.send(:expand_keys, :'foo.bar.baz')
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
3
|
+
require 'i18n/backend/active_record'
|
4
|
+
|
5
|
+
class I18nActiveRecordBackendApiBasicsTest < Test::Unit::TestCase
|
6
|
+
include Tests::Backend::ActiveRecord::Setup::Base
|
7
|
+
include Tests::Backend::Api::Basics
|
8
|
+
end
|
9
|
+
|
10
|
+
class I18nActiveRecordBackendApiTranslateTest < Test::Unit::TestCase
|
11
|
+
include Tests::Backend::ActiveRecord::Setup::Base
|
12
|
+
include Tests::Backend::Api::Translation
|
13
|
+
end
|
14
|
+
|
15
|
+
class I18nActiveRecordBackendApiInterpolateTest < Test::Unit::TestCase
|
16
|
+
include Tests::Backend::ActiveRecord::Setup::Base
|
17
|
+
include Tests::Backend::Api::Interpolation
|
18
|
+
end
|
19
|
+
|
20
|
+
class I18nActiveRecordBackendApiLambdaTest < Test::Unit::TestCase
|
21
|
+
include Tests::Backend::ActiveRecord::Setup::Base
|
22
|
+
include Tests::Backend::Api::Lambda
|
23
|
+
end
|
24
|
+
|
25
|
+
class I18nActiveRecordBackendApiTranslateLinkedTest < Test::Unit::TestCase
|
26
|
+
include Tests::Backend::ActiveRecord::Setup::Base
|
27
|
+
include Tests::Backend::Api::Link
|
28
|
+
end
|
29
|
+
|
30
|
+
class I18nActiveRecordBackendApiPluralizationTest < Test::Unit::TestCase
|
31
|
+
include Tests::Backend::ActiveRecord::Setup::Base
|
32
|
+
include Tests::Backend::Api::Pluralization
|
33
|
+
end
|
34
|
+
|
35
|
+
class I18nActiveRecordBackendApiLocalizeDateTest < Test::Unit::TestCase
|
36
|
+
include Tests::Backend::ActiveRecord::Setup::Localization
|
37
|
+
include Tests::Backend::Api::Localization::Date
|
38
|
+
end
|
39
|
+
|
40
|
+
class I18nActiveRecordBackendApiLocalizeDateTimeTest < Test::Unit::TestCase
|
41
|
+
include Tests::Backend::ActiveRecord::Setup::Localization
|
42
|
+
include Tests::Backend::Api::Localization::DateTime
|
43
|
+
end
|
44
|
+
|
45
|
+
class I18nActiveRecordBackendApiLocalizeTimeTest < Test::Unit::TestCase
|
46
|
+
include Tests::Backend::ActiveRecord::Setup::Localization
|
47
|
+
include Tests::Backend::Api::Localization::Time
|
48
|
+
end
|
49
|
+
|
50
|
+
class I18nActiveRecordBackendApiLocalizeLambdaTest < Test::Unit::TestCase
|
51
|
+
include Tests::Backend::ActiveRecord::Setup::Localization
|
52
|
+
include Tests::Backend::Api::Localization::Lambda
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'active_record'
|
3
|
+
require 'i18n/backend/active_record/store_procs'
|
4
|
+
|
5
|
+
if I18n::Backend::Simple.method_defined?(:interpolate_with_deprecated_syntax)
|
6
|
+
I18n::Backend::Simple.send(:remove_method, :interpolate) rescue NameError
|
7
|
+
end
|
8
|
+
|
9
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
10
|
+
ActiveRecord::Migration.verbose = false
|
11
|
+
ActiveRecord::Schema.define(:version => 1) do
|
12
|
+
create_table :translations do |t|
|
13
|
+
t.string :locale
|
14
|
+
t.string :key
|
15
|
+
t.string :value
|
16
|
+
t.string :interpolations
|
17
|
+
t.boolean :is_proc, :default => false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Tests
|
22
|
+
module Backend
|
23
|
+
module ActiveRecord
|
24
|
+
module Setup
|
25
|
+
module Base
|
26
|
+
def setup
|
27
|
+
super
|
28
|
+
I18n.locale = nil
|
29
|
+
I18n.default_locale = :en
|
30
|
+
I18n.backend = I18n::Backend::ActiveRecord.new
|
31
|
+
I18n::Backend::ActiveRecord::Translation.send(:include, I18n::Backend::ActiveRecord::StoreProcs)
|
32
|
+
backend_store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
|
33
|
+
end
|
34
|
+
|
35
|
+
def teardown
|
36
|
+
super
|
37
|
+
I18n::Backend::ActiveRecord::Translation.destroy_all
|
38
|
+
I18n.backend = nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Localization
|
43
|
+
include Base
|
44
|
+
|
45
|
+
def setup
|
46
|
+
super
|
47
|
+
setup_datetime_translations
|
48
|
+
setup_datetime_lambda_translations
|
49
|
+
@old_timezone, ENV['TZ'] = ENV['TZ'], 'UTC'
|
50
|
+
end
|
51
|
+
|
52
|
+
def teardown
|
53
|
+
super
|
54
|
+
@old_timezone ? ENV['TZ'] = @old_timezone : ENV.delete('TZ')
|
55
|
+
end
|
56
|
+
|
57
|
+
def setup_datetime_translations
|
58
|
+
backend_store_translations :de, {
|
59
|
+
:date => {
|
60
|
+
:formats => {
|
61
|
+
:default => "%d.%m.%Y",
|
62
|
+
:short => "%d. %b",
|
63
|
+
:long => "%d. %B %Y",
|
64
|
+
:long_ordinalized => lambda { |date, options|
|
65
|
+
tz = " (#{options[:timezone]})" if options[:timezone]
|
66
|
+
"#{date.day}ter %B %Y#{tz}"
|
67
|
+
}
|
68
|
+
},
|
69
|
+
:day_names => %w(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag),
|
70
|
+
:abbr_day_names => %w(So Mo Di Mi Do Fr Sa),
|
71
|
+
:month_names => %w(Januar Februar März April Mai Juni Juli August September Oktober November Dezember).unshift(nil),
|
72
|
+
:abbr_month_names => %w(Jan Feb Mar Apr Mai Jun Jul Aug Sep Okt Nov Dez).unshift(nil),
|
73
|
+
:order => [:day, :month, :year]
|
74
|
+
},
|
75
|
+
:time => {
|
76
|
+
:formats => {
|
77
|
+
:default => "%a, %d. %b %Y %H:%M:%S %z",
|
78
|
+
:short => "%d. %b %H:%M",
|
79
|
+
:long => "%d. %B %Y %H:%M",
|
80
|
+
:long_ordinalized => lambda { |date, options|
|
81
|
+
tz = " (#{options[:timezone]})" if options[:timezone]
|
82
|
+
"#{date.day}ter %B %Y, %H:%M Uhr#{tz}"
|
83
|
+
}
|
84
|
+
},
|
85
|
+
:am => 'am',
|
86
|
+
:pm => 'pm'
|
87
|
+
},
|
88
|
+
:datetime => {
|
89
|
+
:distance_in_words => {
|
90
|
+
:half_a_minute => 'half a minute',
|
91
|
+
:less_than_x_seconds => {
|
92
|
+
:one => 'less than 1 second',
|
93
|
+
:other => 'less than {{count}} seconds'
|
94
|
+
},
|
95
|
+
:x_seconds => {
|
96
|
+
:one => '1 second',
|
97
|
+
:other => '{{count}} seconds'
|
98
|
+
},
|
99
|
+
:less_than_x_minutes => {
|
100
|
+
:one => 'less than a minute',
|
101
|
+
:other => 'less than {{count}} minutes'
|
102
|
+
},
|
103
|
+
:x_minutes => {
|
104
|
+
:one => '1 minute',
|
105
|
+
:other => '{{count}} minutes'
|
106
|
+
},
|
107
|
+
:about_x_hours => {
|
108
|
+
:one => 'about 1 hour',
|
109
|
+
:other => 'about {{count}} hours'
|
110
|
+
},
|
111
|
+
:x_days => {
|
112
|
+
:one => '1 day',
|
113
|
+
:other => '{{count}} days'
|
114
|
+
},
|
115
|
+
:about_x_months => {
|
116
|
+
:one => 'about 1 month',
|
117
|
+
:other => 'about {{count}} months'
|
118
|
+
},
|
119
|
+
:x_months => {
|
120
|
+
:one => '1 month',
|
121
|
+
:other => '{{count}} months'
|
122
|
+
},
|
123
|
+
:about_x_years => {
|
124
|
+
:one => 'about 1 year',
|
125
|
+
:other => 'about {{count}} year'
|
126
|
+
},
|
127
|
+
:over_x_years => {
|
128
|
+
:one => 'over 1 year',
|
129
|
+
:other => 'over {{count}} years'
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
def setup_datetime_lambda_translations
|
137
|
+
backend_store_translations 'ru', {
|
138
|
+
:date => {
|
139
|
+
:'day_names' => lambda { |key, options|
|
140
|
+
(options[:format] =~ /^%A/) ?
|
141
|
+
%w(Воскресенье Понедельник Вторник Среда Четверг Пятница Суббота) :
|
142
|
+
%w(воскресенье понедельник вторник среда четверг пятница суббота)
|
143
|
+
},
|
144
|
+
:'abbr_day_names' => %w(Вс Пн Вт Ср Чт Пт Сб),
|
145
|
+
:'month_names' => lambda { |key, options|
|
146
|
+
(options[:format] =~ /(%d|%e)(\s*)?(%B)/) ?
|
147
|
+
%w(января февраля марта апреля мая июня июля августа сентября октября ноября декабря).unshift(nil) :
|
148
|
+
%w(Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь).unshift(nil)
|
149
|
+
},
|
150
|
+
:'abbr_month_names' => lambda { |key, options|
|
151
|
+
(options[:format] =~ /(%d|%e)(\s*)(%b)/) ?
|
152
|
+
%w(янв. февр. марта апр. мая июня июля авг. сент. окт. нояб. дек.).unshift(nil) :
|
153
|
+
%w(янв. февр. март апр. май июнь июль авг. сент. окт. нояб. дек.).unshift(nil)
|
154
|
+
},
|
155
|
+
},
|
156
|
+
:time => {
|
157
|
+
:am => "утра",
|
158
|
+
:pm => "вечера"
|
159
|
+
}
|
160
|
+
}
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
3
|
+
require 'i18n/backend/chain'
|
4
|
+
require 'i18n/backend/active_record'
|
5
|
+
require 'i18n/backend/active_record_missing'
|
6
|
+
|
7
|
+
class I18nActiveRecordMissingTest < Test::Unit::TestCase
|
8
|
+
include Tests::Backend::ActiveRecord::Setup::Base
|
9
|
+
|
10
|
+
def setup
|
11
|
+
I18n.backend.store_translations(:en, :i18n => { :plural_keys => [:zero, :one, :other] })
|
12
|
+
|
13
|
+
I18n.backend = I18n::Backend::Chain.new(I18n.backend)
|
14
|
+
I18n.backend.meta_class.send(:include, I18n::Backend::ActiveRecordMissing)
|
15
|
+
|
16
|
+
I18n::Backend::ActiveRecord::Translation.delete_all
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_can_persist_interpolations
|
20
|
+
translation = I18n::Backend::ActiveRecord::Translation.new \
|
21
|
+
:key => 'foo',
|
22
|
+
:value => 'bar',
|
23
|
+
:locale => :en
|
24
|
+
|
25
|
+
translation.interpolations = %w{ count name }
|
26
|
+
translation.save
|
27
|
+
|
28
|
+
assert translation.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_lookup_persists_key
|
32
|
+
I18n.t('foo.bar.baz')
|
33
|
+
|
34
|
+
assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_lookup_does_not_persist_key_twice
|
38
|
+
2.times { I18n.t('foo.bar.baz') }
|
39
|
+
|
40
|
+
assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_persists_interpolation_keys_when_looked_up_directly
|
44
|
+
I18n.t('foo.bar.baz', :cow => "lucy" ) # creates stub translation.
|
45
|
+
|
46
|
+
translation_stub = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo.bar.baz').first
|
47
|
+
assert translation_stub.interpolates?(:cow)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_creates_one_stub_per_pluralization
|
51
|
+
I18n.t('foo', :count => 999)
|
52
|
+
|
53
|
+
translations = I18n::Backend::ActiveRecord::Translation.locale(:en).find_all_by_key %w{ foo.zero foo.one foo.other }
|
54
|
+
assert_equal 3, translations.length
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_creates_no_stub_for_base_key_in_pluralization
|
58
|
+
I18n.t('foo', :count => 999)
|
59
|
+
|
60
|
+
translations = I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key %w{ foo.zero foo.one foo.other }
|
61
|
+
assert !I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key("foo")
|
62
|
+
end
|
63
|
+
end
|