i18n_backend_database_rails3 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. data/Gemfile +4 -0
  2. data/LICENSE +21 -0
  3. data/README.textile +125 -0
  4. data/Rakefile +1 -0
  5. data/data/locales.yml +4 -0
  6. data/generators/i18n_backend_database/i18n_backend_database_generator.rb +8 -0
  7. data/generators/i18n_backend_database/templates/migrate/create_i18n_tables.rb +19 -0
  8. data/i18n_backend_database.gemspec +24 -0
  9. data/init.rb +1 -0
  10. data/lib/controllers/locales_controller.rb +86 -0
  11. data/lib/controllers/translations_controller.rb +141 -0
  12. data/lib/ext/i18n.rb +68 -0
  13. data/lib/google_language.rb +30 -0
  14. data/lib/i18n_backend_database.rb +9 -0
  15. data/lib/i18n_backend_database/database.rb +263 -0
  16. data/lib/i18n_backend_database/version.rb +7 -0
  17. data/lib/i18n_util.rb +148 -0
  18. data/lib/models/locale.rb +67 -0
  19. data/lib/models/translation.rb +46 -0
  20. data/lib/models/translation_option.rb +26 -0
  21. data/lib/public/images/custom1_bar.gif +0 -0
  22. data/lib/public/images/custom1_box.gif +0 -0
  23. data/lib/public/images/percentImage.png +0 -0
  24. data/lib/public/images/percentImage_back.png +0 -0
  25. data/lib/public/images/percentImage_back1.png +0 -0
  26. data/lib/public/images/percentImage_back2.png +0 -0
  27. data/lib/public/images/percentImage_back3.png +0 -0
  28. data/lib/public/images/percentImage_back4.png +0 -0
  29. data/lib/public/javascripts/jsProgressBarHandler.js +509 -0
  30. data/lib/routing.rb +15 -0
  31. data/lib/views/layouts/translations.html.haml +16 -0
  32. data/lib/views/locales/edit.html.haml +16 -0
  33. data/lib/views/locales/index.html.haml +14 -0
  34. data/lib/views/locales/new.html.haml +14 -0
  35. data/lib/views/locales/show.html.haml +10 -0
  36. data/lib/views/translations/asset_translations.html.haml +23 -0
  37. data/lib/views/translations/edit.html.haml +24 -0
  38. data/lib/views/translations/index.html.haml +21 -0
  39. data/lib/views/translations/new.html.haml +14 -0
  40. data/lib/views/translations/show.html.haml +21 -0
  41. data/lib/views/translations/translations.html.haml +20 -0
  42. data/lib/views/translations/update.rjs +7 -0
  43. data/routes.rb +3 -0
  44. data/spec/assets/public/es/favicons/favicon1.gif +0 -0
  45. data/spec/assets/public/es/images/icons/icon1.gif +0 -0
  46. data/spec/assets/public/es/images/image1.gif +0 -0
  47. data/spec/assets/public/favicons/favicon1.gif +0 -0
  48. data/spec/assets/public/favicons/favicon2.gif +0 -0
  49. data/spec/assets/public/images/icons/icon1.gif +0 -0
  50. data/spec/assets/public/images/icons/icon2.gif +0 -0
  51. data/spec/assets/public/images/image1.gif +0 -0
  52. data/spec/assets/public/images/image2.gif +0 -0
  53. data/spec/assets/public/images/promo/sfc08_140x400_3.gif +0 -0
  54. data/spec/assets/views/test_view1.html.erb +1 -0
  55. data/spec/assets/views/test_view2.html.erb +30 -0
  56. data/spec/caching_spec.rb +87 -0
  57. data/spec/controllers/locales_controller_spec.rb +173 -0
  58. data/spec/controllers/locales_routing_spec.rb +59 -0
  59. data/spec/controllers/translations_controller_spec.rb +189 -0
  60. data/spec/controllers/translations_routing_spec.rb +59 -0
  61. data/spec/database_spec.rb +199 -0
  62. data/spec/i18n_ext_spec.rb +40 -0
  63. data/spec/localize_spec.rb +66 -0
  64. data/spec/localize_text_spec.rb +76 -0
  65. data/spec/models/locale_spec.rb +111 -0
  66. data/spec/models/translation_spec.rb +44 -0
  67. data/spec/spec_helper.rb +16 -0
  68. data/spec/translate_asset_spec.rb +57 -0
  69. data/spec/translate_spec.rb +546 -0
  70. data/tasks/i18n.rake +60 -0
  71. metadata +143 -0
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe I18n do
4
+
5
+ describe "with default locale en" do
6
+ before(:each) do
7
+ I18n.default_locale = "en"
8
+ end
9
+
10
+ describe "and locale en" do
11
+ before(:each) do
12
+ I18n.locale = "en"
13
+ end
14
+
15
+ it "should return empty local segment" do
16
+ I18n.locale_segment.should == ''
17
+ end
18
+
19
+ it "should return empty local segment using alias" do
20
+ I18n.ls.should == ''
21
+ end
22
+ end
23
+
24
+ describe "and locale es" do
25
+ before(:each) do
26
+ I18n.locale = "es"
27
+ end
28
+
29
+ it "should return es local segment" do
30
+ I18n.locale_segment.should == '/es'
31
+ end
32
+
33
+ it "should return es local segment using alias" do
34
+ I18n.ls.should == '/es'
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe I18n::Backend::Database do
4
+ before(:each) do
5
+ @backend = I18n::Backend::Database.new
6
+ end
7
+
8
+ after(:each) do
9
+ @backend.cache_store.clear
10
+ end
11
+
12
+ describe "with default locale en" do
13
+ before(:each) do
14
+ I18n.default_locale = "en"
15
+ if File.exists?('vendor/rails/activesupport/lib/active_support/locale/en.yml')
16
+ I18nUtil.load_from_yml 'vendor/rails/activesupport/lib/active_support/locale/en.yml'
17
+ else
18
+ activesupport_gem = Gem.cache.find_name('activesupport').sort_by { |g| g.version.version }.last
19
+ I18nUtil.load_from_yml "#{activesupport_gem.full_gem_path}/lib/active_support/locale/en.yml"
20
+ end
21
+ end
22
+
23
+ describe "and locale en" do
24
+ before(:each) do
25
+ I18n.locale = "en"
26
+ end
27
+
28
+ it "should localize dates in different formats" do
29
+ dates = {
30
+ Date.new(2009,1,1) => {:default => "2009-01-01", :short => "Jan 01", :long => "January 01, 2009"},
31
+ Date.new(2009,1,31) => {:default => "2009-01-31", :short => "Jan 31", :long => "January 31, 2009"},
32
+ Date.new(2009,2,2) => {:default => "2009-02-02", :short => "Feb 02", :long => "February 02, 2009"},
33
+ Date.new(2009,2,28) => {:default => "2009-02-28", :short => "Feb 28", :long => "February 28, 2009"},
34
+ Date.new(2008,2,29) => {:default => "2008-02-29", :short => "Feb 29", :long => "February 29, 2008"},
35
+ Date.new(2009,3,11) => {:default => "2009-03-11", :short => "Mar 11", :long => "March 11, 2009"},
36
+ Date.new(2010,4,30) => {:default => "2010-04-30", :short => "Apr 30", :long => "April 30, 2010"},
37
+ Date.new(2020,12,31) => {:default => "2020-12-31", :short => "Dec 31", :long => "December 31, 2020"}
38
+ }
39
+
40
+ dates.each do |date, formats|
41
+ formats.each do |format, expected_value|
42
+ @backend.localize("en", date, format).should == expected_value
43
+ end
44
+ end
45
+ end
46
+
47
+ it "should localize times in different formats" do
48
+ time = DateTime.new(y=2008,m=3,d=22,h=16,min=30,s=12)
49
+
50
+ @backend.localize("en", time, :default).should == "Sat, 22 Mar 2008 16:30:12 +0000"
51
+ @backend.localize("en", time, :short).should == "22 Mar 16:30"
52
+ @backend.localize("en", time, :long).should == "March 22, 2008 16:30"
53
+ @backend.localize("en", time, '%B %d, %Y %H:%M %p').should == "March 22, 2008 16:30 pm"
54
+ end
55
+
56
+ end
57
+
58
+ describe "and locale es" do
59
+ before(:each) do
60
+ I18n.locale = "es"
61
+ @spanish_locale = Locale.create!(:code => 'es')
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe I18n::Backend::Database do
4
+ before(:each) do
5
+ @backend = I18n::Backend::Database.new
6
+ end
7
+
8
+ after(:each) do
9
+ @backend.cache_store.clear
10
+ end
11
+
12
+ describe "with default locale en" do
13
+ before(:each) do
14
+ I18n.default_locale = "en"
15
+ @english_locale = Locale.create!(:code => "en")
16
+ end
17
+
18
+ describe "and locale en" do
19
+ before(:each) do
20
+ I18n.locale = "en"
21
+ end
22
+
23
+ it "should localize tagged text" do
24
+ @backend.localize_text("en", "shane ^^is now friends with^^ dylan").should == "shane is now friends with dylan"
25
+ end
26
+
27
+ it "should localize text tagged more than once" do
28
+ @backend.localize_text("en", "dylan ^^is now friends with^^ shane ^^and is happy, ^^dylan ^^claps his hands!^^").should == "dylan is now friends with shane and is happy, dylan claps his hands!"
29
+ end
30
+
31
+ it "should localize tagged text using class method" do
32
+ I18n.localize_text("shane ^^is now friends with^^ dylan").should == "shane is now friends with dylan"
33
+ end
34
+
35
+ it "should localize tagged text using class method alias" do
36
+ I18n.lt("shane ^^is now friends with^^ dylan").should == "shane is now friends with dylan"
37
+ end
38
+
39
+ it "should add localize text tags" do
40
+ I18n.tag_localized_text("is now friends with").should == "^^is now friends with^^"
41
+ end
42
+
43
+ it "should add localize text tags using alias" do
44
+ I18n.tlt("is now friends with").should == "^^is now friends with^^"
45
+ end
46
+
47
+ it "should just return text with no localize text tags" do
48
+ @backend.localize_text("en", "shane is now friends with dylan").should == "shane is now friends with dylan"
49
+ end
50
+
51
+ it "should localize tagged text using custom localize text tag" do
52
+ @backend.localize_text_tag = "##"
53
+ @backend.localize_text("en", "shane ##is now friends with## dylan").should == "shane is now friends with dylan"
54
+ end
55
+
56
+ it "should localize tagged text using another custom localize text tag" do
57
+ @backend.localize_text_tag = "LOCALIZED_TEXT_TAG"
58
+ @backend.localize_text("en", "shane LOCALIZED_TEXT_TAGis now friends withLOCALIZED_TEXT_TAG dylan").should == "shane is now friends with dylan"
59
+ end
60
+
61
+ end
62
+
63
+ describe "and locale es" do
64
+ before(:each) do
65
+ I18n.locale = "es"
66
+ @spanish_locale = Locale.create!(:code => 'es')
67
+ end
68
+
69
+ it "should localize tagged text" do
70
+ @spanish_locale.translations.create!(:key => 'is now friends with', :value => 'ahora es con amigos')
71
+ @backend.localize_text("es", "shane ^^is now friends with^^ dylan").should == "shane ahora es con amigos dylan"
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,111 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Locale do
4
+ before(:each) do
5
+ @valid_attributes = {
6
+ :code => "en",
7
+ :name => "English"
8
+ }
9
+ end
10
+
11
+ it "should create a new instance given valid attributes" do
12
+ Locale.create!(@valid_attributes)
13
+ end
14
+
15
+ it "should return code as to_param" do
16
+ Locale.new(@valid_attributes).to_param.should == 'en'
17
+ end
18
+
19
+ it "should be invalid with no code" do
20
+ Locale.create!(:code => "en")
21
+ locale = Locale.new
22
+ locale.should_not be_valid
23
+ end
24
+ end
25
+
26
+
27
+ describe "English and Spanish Locales with I18n default locale set to English" do
28
+ before(:each) do
29
+ I18n.default_locale = "en"
30
+ @english_locale = Locale.create!(:code => "en")
31
+ @spanish_locale = Locale.create!(:code => "es")
32
+ end
33
+
34
+ it "should create a translated translation using english locale" do
35
+ translation = @english_locale.create_translation('Hello World', 'Hello World')
36
+ translation.key.should == Translation.hk('Hello World')
37
+ translation.value.should == 'Hello World'
38
+ end
39
+
40
+ it "should create an untranslated translation using spanish locale" do
41
+ translation = @spanish_locale.create_translation('Hello World', 'Hello World')
42
+ translation.key.should == Translation.hk('Hello World')
43
+ translation.value.should be_nil
44
+ end
45
+
46
+ it "should return default locale of English" do
47
+ Locale.default_locale.should == @english_locale
48
+ end
49
+
50
+ it "should return list of non-default locales" do
51
+ @geek_locale = Locale.create!(:code => "gk")
52
+ Locale.non_defaults.should include(@spanish_locale)
53
+ Locale.non_defaults.should include(@geek_locale)
54
+ Locale.non_defaults.should_not include(@english_locale)
55
+ end
56
+
57
+ it "should know that the english_locale is the default" do
58
+ @english_locale.should be_default_locale
59
+ end
60
+
61
+ it "should know if it has a translation record" do
62
+ translation = @english_locale.create_translation('key', 'Hello World')
63
+ @english_locale.should have_translation('key')
64
+ end
65
+
66
+ it "should have 0 translations" do
67
+ @spanish_locale.should have(0).translations
68
+ end
69
+
70
+ it "should have 0 untranslated" do
71
+ @spanish_locale.translations.untranslated.should have(0).records
72
+ end
73
+
74
+ it "should have 0 translated" do
75
+ @spanish_locale.translations.translated.should have(0).records
76
+ end
77
+
78
+ it "should have 100% translated" do
79
+ @spanish_locale.percentage_translated.should == 100
80
+ end
81
+
82
+ end
83
+
84
+ describe "Locale with translations" do
85
+ before(:each) do
86
+ I18n.default_locale = "en"
87
+ @english_locale = Locale.create!(:code => "en")
88
+ @spanish_locale = Locale.create!(:code => "es")
89
+
90
+ @spanish_locale.translations.create!(:key => 'key1', :value => 'translated1')
91
+ @spanish_locale.translations.create!(:key => 'key2', :value => 'translated2')
92
+ @spanish_locale.translations.create!(:key => 'key3', :value => nil) # 1 untranslated record
93
+ end
94
+
95
+ it "should have 3 translations" do
96
+ @spanish_locale.should have(3).translations
97
+ end
98
+
99
+ it "should have 1 untranslated" do
100
+ @spanish_locale.translations.untranslated.should have(1).records
101
+ end
102
+
103
+ it "should have 2 translated" do
104
+ @spanish_locale.translations.translated.should have(2).records
105
+ end
106
+
107
+ it "should have 67% translated" do
108
+ @spanish_locale.percentage_translated.should == 67
109
+ end
110
+
111
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Translation do
4
+ before(:each) do
5
+ @valid_attributes = {
6
+ :key => "Hello World",
7
+ :value => "Hello World"
8
+ }
9
+ end
10
+
11
+ it "should create a new instance given valid attributes" do
12
+ Translation.create!(@valid_attributes)
13
+ end
14
+ end
15
+
16
+ describe "English and Spanish Locales with I18n default locale set to English" do
17
+ before(:each) do
18
+ I18n.default_locale = "en"
19
+ @english_locale = Locale.create!(:code => "en")
20
+ @spanish_locale = Locale.create!(:code => "es")
21
+ end
22
+
23
+ describe "with no English translation" do
24
+ it "should have return 'No default locale value' for a new Spanish translation with same key" do
25
+ @spanish_translation = @spanish_locale.translations.create(:key => 'Hello World')
26
+ @spanish_translation.default_locale_value.should == 'No default locale value'
27
+ end
28
+ end
29
+
30
+ describe "with one English translation" do
31
+ before(:each) do
32
+ @english_translation = @english_locale.translations.create(:key => 'Hello World', :value => 'Hello World')
33
+ end
34
+
35
+ it "should have a default locale value" do
36
+ @english_translation.default_locale_value.should == 'Hello World'
37
+ end
38
+
39
+ it "should have a default locale value of the English for a new Spanish translation with same key" do
40
+ @spanish_translation = @spanish_locale.translations.create(:key => 'Hello World')
41
+ @spanish_translation.default_locale_value.should == 'Hello World'
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,16 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.join(File.dirname(__FILE__), "/../../../../config/environment")
3
+ require 'spec/rails'
4
+ require 'i18n_backend_database'
5
+
6
+ Spec::Runner.configure do |config|
7
+ config.use_transactional_fixtures = true
8
+ config.use_instantiated_fixtures = false
9
+
10
+ config.after(:each) do
11
+ Locale.reset_default_locale
12
+ I18n.locale = "en"
13
+ I18n.default_locale = "en"
14
+ I18n.backend.cache_store.clear
15
+ end
16
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe I18n do
4
+
5
+ describe "with default locale en" do
6
+ before(:each) do
7
+ I18n.default_locale = "en"
8
+ ActionView::Helpers::AssetTagHelper.send(:remove_const, :ASSETS_DIR)
9
+ ActionView::Helpers::AssetTagHelper::ASSETS_DIR = "#{RAILS_ROOT}/vendor/plugins/i18n_backend_database/spec/assets/public"
10
+ I18n.send(:remove_const, :APP_DIRECTORY)
11
+ I18n::APP_DIRECTORY = "./vendor/plugins/i18n_backend_database/spec/assets"
12
+ end
13
+
14
+ it "should find my test views" do
15
+ I18n.asset_translations.should == ["promo/sfc08_140x400_3.gif", "image1.gif", "image2.gif", "icons/icon1.gif", "icons/icon2.gif",
16
+ "/favicons/favicon1.gif", "/favicons/favicon2.gif"]
17
+ end
18
+
19
+ it "should return no untranslated assets" do
20
+ I18n.untranslated_assets(:en).should be_empty
21
+ end
22
+
23
+ it "should return untranslated assets" do
24
+ I18n.untranslated_assets(:es).should == ["promo/sfc08_140x400_3.gif", "image2.gif", "icons/icon2.gif", "/favicons/favicon2.gif"]
25
+ end
26
+
27
+ describe "and locale en" do
28
+ before(:each) do
29
+ I18n.locale = "en"
30
+ end
31
+
32
+ it "should return default asset path" do
33
+ I18n.ta("image.gif").should == 'image.gif'
34
+ end
35
+
36
+ it "should return translated asset path for locale passed" do
37
+ I18n.ta("image1.gif", :locale => :es).should == '/es/images/image1.gif'
38
+ end
39
+ end
40
+
41
+ describe "and locale es" do
42
+ before(:each) do
43
+ I18n.locale = "es"
44
+ end
45
+
46
+ it "should return default asset path if no translated asset exists" do
47
+ I18n.ta("image2.gif").should == 'image2.gif'
48
+ end
49
+
50
+ it "should return translated asset path if translatied asset exists" do
51
+ I18n.ta("image1.gif").should == '/es/images/image1.gif'
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,546 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class MemoryStoreProxy < ActiveSupport::Cache::MemoryStore
4
+ attr_accessor :write_count
5
+
6
+ def initialize
7
+ @write_count = 0
8
+ super
9
+ end
10
+
11
+ def write(key, value, options = nil)
12
+ super(key, value, options)
13
+ @write_count += 1
14
+ end
15
+ end
16
+
17
+ describe I18n::Backend::Database do
18
+ before(:each) do
19
+ @backend = I18n::Backend::Database.new
20
+ end
21
+
22
+ after(:each) do
23
+ @backend.cache_store.clear
24
+ end
25
+
26
+ describe "returning hashes for non-leaves" do
27
+ before do
28
+ #Set up a translation hierarchy
29
+ @locale = Locale.create!(:code => "en")
30
+ I18n.default_locale = "en"
31
+ end
32
+
33
+ it "should return a hash when asked for a non-leaf node" do
34
+ format_hash = {:separator => ".", :precision => 3, :delimiter => ","}
35
+ @locale.translations.create!(:key => "number.format.separator", :value => format_hash[:separator])
36
+ @locale.translations.create!(:key => "number.format.precision", :value => format_hash[:precision])
37
+ @locale.translations.create!(:key => "number.format.delimiter", :value => format_hash[:delimiter])
38
+ @backend.translate("en", "number.format").should == format_hash
39
+ end
40
+
41
+ it "should return a nested hash" do
42
+ nested_hash = {:a => "b", :c => {:d => "e", :f => "g"}}
43
+ @locale.translations.create!(:key => "nested.a", :value => "b")
44
+ @locale.translations.create!(:key => "nested.c.d", :value => "e")
45
+ @locale.translations.create!(:key => "nested.c.f", :value => "g")
46
+ @backend.translate("en", "nested").should == nested_hash
47
+ end
48
+
49
+ it "should not be fooled by SQL injection" do
50
+ #for bad_string in ["number.format%", "number.format\%", "number.format\\"] do
51
+ for bad_string in ["number.format\\"] do
52
+ @backend.translate("en", bad_string).should == bad_string
53
+ end
54
+ end
55
+
56
+ it "should not be fooled by keys ending in a delimiter" do
57
+ @locale.translations.create!(:key => "number.format.", :value => 'this should be a normal leaf')
58
+ @backend.translate('en', 'number.format.').should == 'this should be a normal leaf'
59
+ end
60
+
61
+ end
62
+
63
+ describe "with default locale en" do
64
+ before(:each) do
65
+ I18n.default_locale = "en"
66
+ @english_locale = Locale.create!(:code => "en")
67
+ end
68
+
69
+ describe "and locale en" do
70
+ before(:each) do
71
+ I18n.locale = "en"
72
+ end
73
+
74
+ it "should create a record with the key as the value when the key is a string" do
75
+ @backend.translate("en", "String").should == "String"
76
+ @english_locale.should have(1).translation
77
+ @english_locale.translations.first.key.should == Translation.hk("String")
78
+ @english_locale.translations.first.raw_key.should == "String"
79
+ @english_locale.translations.first.value.should == "String"
80
+ end
81
+
82
+ it "should not write to the cache if the key already exists in the cache" do
83
+ @backend.cache_store = MemoryStoreProxy.new
84
+ @english_locale.translations.create!(:key => 'String', :value => 'Value')
85
+
86
+ @backend.translate("en", "String").should == "Value"
87
+ @backend.cache_store.write_count.should == 1
88
+
89
+ @backend.translate("en", "String").should == "Value"
90
+ @backend.cache_store.write_count.should == 1
91
+ end
92
+
93
+ it "should create a record with the key as the value when the key is a string and cache that record" do
94
+ @backend.translate("en", "status").should == "status"
95
+ @english_locale.should have(1).translation
96
+
97
+ # once cached
98
+ @backend.translate("en", "status").should == "status"
99
+ @english_locale.should have(1).translation
100
+ end
101
+
102
+ it "should find a record with the key as the value when the key is a string" do
103
+ @english_locale.translations.create!(:key => 'String', :value => 'Value')
104
+ @backend.translate("en", "String").should == "Value"
105
+ @english_locale.should have(1).translation
106
+ end
107
+
108
+ it "should support having a record with a nil value" do
109
+ @english_locale.translations.create!(:key => 'date.order')
110
+ @backend.translate("en", :'date.order').should be_nil
111
+ @english_locale.should have(1).translation
112
+ end
113
+
114
+ it "should create a record with a nil value when key is a symbol" do
115
+ @backend.translate("en", :'date.order').should be_nil
116
+ @english_locale.should have(1).translation
117
+ @english_locale.translations.first.key.should == Translation.hk('date.order')
118
+ @english_locale.translations.first.raw_key.should == "date.order"
119
+ @english_locale.translations.first.value.should be_nil
120
+
121
+ # once cached
122
+ @backend.translate("en", :'date.order').should be_nil
123
+ @english_locale.reload.should have(1).translation
124
+ end
125
+
126
+ it "should support storing values as YAML symbols" do
127
+ @english_locale.translations.create!(:key => 'date.order', :value => "--- :year\n", :pluralization_index => 0)
128
+ @english_locale.translations.create!(:key => 'date.order', :value => "--- :month\n", :pluralization_index => 1)
129
+ @english_locale.translations.create!(:key => 'date.order', :value => "--- :day\n", :pluralization_index => 2)
130
+
131
+ @backend.translate("en", :'date.order').should == [:year, :month, :day]
132
+ @english_locale.should have(3).translations
133
+ end
134
+
135
+ it "should find a cached record from a cache key if it exists in the cache" do
136
+ hash_key = Translation.hk("blah")
137
+ @backend.cache_store.write("en:#{hash_key}", 'woot')
138
+ @backend.translate("en", "blah").should == "woot"
139
+ end
140
+
141
+ it "should find a cached record with a nil value from a cache key if it exists in the cache" do
142
+ hash_key = Translation.hk(".date.order")
143
+ @backend.cache_store.write("en:#{hash_key}", nil)
144
+ @backend.translate("en", :'date.order').should be_nil
145
+ end
146
+
147
+ it "should write a cache record to the cache for a newly created translation record" do
148
+ hash_key = Translation.hk("blah")
149
+ @backend.translate("en", "blah")
150
+ @backend.cache_store.read("en:#{hash_key}").should == "blah"
151
+ end
152
+
153
+ it "should write a cache record to the cache for translation record with nil value" do
154
+ @english_locale.translations.create!(:key => '.date.order')
155
+ @backend.translate("en", :'date.order').should be_nil
156
+
157
+ hash_key = Translation.hk(".date.order")
158
+ @backend.cache_store.read("en:#{hash_key}").should be_nil
159
+ end
160
+
161
+ it "should handle active record helper defaults, where default is the object name" do
162
+ options = {:count=>1, :scope=>[:activerecord, :models], :default=>"post"}
163
+ @english_locale.translations.create!(:key => 'activerecord.errors.models.blank', :value => 'post')
164
+ @backend.translate("en", :"models.blank", options).should == 'post'
165
+ end
166
+
167
+ it "should handle translating defaults used by active record attributes" do
168
+ options = {:scope=>[:activerecord, :attributes], :count=>1, :default=>["Content"]}
169
+ @backend.translate("en", :"post.content", options).should == 'Content'
170
+
171
+ # and when cached
172
+ options = {:scope=>[:activerecord, :attributes], :count=>1, :default=>["Content"]}
173
+ @backend.translate("en", :"post.content", options).should == 'Content'
174
+ @english_locale.should have(1).translation
175
+ end
176
+
177
+ it "should handle translating defaults used by active record attributes when the default is blank" do
178
+ options = { :count=>1, :default=> " "}
179
+ @backend.translate("en", "key", options).should == " "
180
+
181
+ # and when cached
182
+ options = { :count=>1, :default=> " "}
183
+ @backend.translate("en", "key", options).should == " "
184
+ @english_locale.should have(1).translation
185
+ end
186
+
187
+ it "should be able to handle interpolated values" do
188
+ options = {:some_value => 'INTERPOLATED'}
189
+ @english_locale.translations.create!(:key => 'Fred', :value => 'Fred has been {{some_value}}!!')
190
+ @backend.translate("en", 'Fred', options).should == 'Fred has been INTERPOLATED!!'
191
+ end
192
+
193
+ it "should be able to handle interpolated values with 'Fred {{some_value}}' also as the key" do
194
+ options = {:some_value => 'INTERPOLATED'}
195
+ @english_locale.translations.create!(:key => 'Fred {{some_value}}', :value => 'Fred {{some_value}}!!')
196
+ @backend.translate("en", 'Fred {{some_value}}', options).should == 'Fred INTERPOLATED!!'
197
+ end
198
+
199
+ it "should be able to handle interpolated count values" do
200
+ options = {:count=>1, :model => ["Cheese"], :scope=>[:activerecord, :errors], :default=>["Locale"]}
201
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => '{{count}} errors prohibited this {{model}} from being saved')
202
+ @backend.translate("en", :"messages.blank", options).should == '1 errors prohibited this Cheese from being saved'
203
+ end
204
+
205
+ it "should be able to handle the case of scope being passed in as something other than an array" do
206
+ options = {:count=>1, :model => ["Cheese"], :scope=> :activerecord, :default=>["Locale"]}
207
+ @english_locale.translations.create!(:key => 'activerecord.messages.blank', :value => 'dude')
208
+ @backend.translate("en", :"messages.blank", options).should == 'dude'
209
+ end
210
+
211
+ it "should be able to handle pluralization" do
212
+ @english_locale.translations.create!(:key => 'activerecord.errors.template.header', :value => '1 error prohibited this {{model}} from being saved', :pluralization_index => 1)
213
+ @english_locale.translations.create!(:key => 'activerecord.errors.template.header', :value => '{{count}} errors prohibited this {{model}} from being saved', :pluralization_index => 0)
214
+
215
+ options = {:count=>1, :model=>"translation", :scope=>[:activerecord, :errors, :template]}
216
+ @backend.translate("en", :"header", options).should == "1 error prohibited this translation from being saved"
217
+ @english_locale.should have(2).translations
218
+
219
+ options = {:count=>2, :model=>"translation", :scope=>[:activerecord, :errors, :template]}
220
+ @backend.translate("en", :"header", options).should == "2 errors prohibited this translation from being saved"
221
+ @english_locale.should have(2).translations
222
+ end
223
+
224
+ it "should find lowest level translation" do
225
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
226
+
227
+ options = {:attribute=>"Locale", :value=>nil,
228
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", :"messages.blank"], :model=>"Translation"}
229
+
230
+ @backend.translate("en", :"models.translation.attributes.locale.blank", options).should == "is blank moron!"
231
+ end
232
+
233
+ it "should find higher level translation" do
234
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
235
+ @english_locale.translations.create!(:key => 'activerecord.errors.models.translation.blank', :value => 'translation blank')
236
+
237
+ options = {:attribute=>"Locale", :value=>nil,
238
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", :"messages.blank"], :model=>"Translation"}
239
+
240
+ @backend.translate("en", :"models.translation.attributes.locale.blank", options).should == "translation blank"
241
+ end
242
+
243
+ it "should find highest level translation" do
244
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
245
+ @english_locale.translations.create!(:key => 'activerecord.errors.models.translation.blank', :value => 'translation blank')
246
+ @english_locale.translations.create!(:key => 'activerecord.errors.models.translation.attributes.locale.blank', :value => 'translation locale blank')
247
+
248
+ options = {:attribute=>"Locale", :value=>nil,
249
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", :"messages.blank"], :model=>"Translation"}
250
+
251
+ @backend.translate("en", :"models.translation.attributes.locale.blank", options).should == "translation locale blank"
252
+ end
253
+
254
+ it "should create the translation for custom message" do
255
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
256
+
257
+ options = {:attribute=>"Locale", :value=>nil,
258
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", "This is a custom message!", :"messages.blank"], :model=>"Translation"}
259
+
260
+ @backend.translate("en", :"models.translation.attributes.locale.blank", options).should == "This is a custom message!"
261
+ @english_locale.should have(2).translations
262
+ @english_locale.translations.find_by_key(Translation.hk("This is a custom message!")).value.should == 'This is a custom message!'
263
+ end
264
+
265
+ it "should find the translation for custom message" do
266
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
267
+ @english_locale.translations.create!(:key => 'This is a custom message!', :value => 'This is a custom message!')
268
+
269
+ options = {:attribute=>"Locale", :value=>nil,
270
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", "This is a custom message!", :"messages.blank"], :model=>"Translation"}
271
+
272
+ @backend.translate("en", :"models.translation.attributes.locale.blank", options).should == "This is a custom message!"
273
+ end
274
+
275
+ it "should NOT find the translation for custom message" do
276
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
277
+ @english_locale.translations.create!(:key => 'This is a custom message!', :value => 'This is a custom message!')
278
+
279
+ options = {:attribute=>"Locale", :value=>nil,
280
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", :"messages.blank"], :model=>"Translation"}
281
+
282
+ @backend.translate("en", :"models.translation.attributes.locale.blank", options).should == "is blank moron!"
283
+ end
284
+
285
+ it "should return an array" do
286
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'January', :pluralization_index => 1)
287
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'February', :pluralization_index => 2)
288
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'March', :pluralization_index => 3)
289
+ @backend.translate("en", :"date.month_names").should == [nil, 'January', 'February', 'March']
290
+
291
+ # once cached
292
+ @backend.translate("en", :"date.month_names").should == [nil, 'January', 'February', 'March']
293
+ @english_locale.reload.should have(3).translation
294
+ end
295
+
296
+ it "should return an unfrozen array" do
297
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'January', :pluralization_index => 1)
298
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'February', :pluralization_index => 2)
299
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'March', :pluralization_index => 3)
300
+ @backend.translate("en", :"date.month_names").should_not be_frozen
301
+
302
+ # once cached
303
+ @backend.translate("en", :"date.month_names").should_not be_frozen
304
+ end
305
+
306
+ it "should return an array of days" do
307
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Sunday', :pluralization_index => 0)
308
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Monday', :pluralization_index => 1)
309
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Tuesday', :pluralization_index => 2)
310
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Wednesday', :pluralization_index => 3)
311
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Thursday', :pluralization_index => 4)
312
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Friday', :pluralization_index => 5)
313
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Saturday', :pluralization_index => 6)
314
+
315
+ # once cached
316
+ @backend.translate("en", :"date.day_names").should == ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
317
+ @english_locale.reload.should have(7).translation
318
+ end
319
+
320
+ end
321
+
322
+ describe "and locale es" do
323
+ before(:each) do
324
+ I18n.locale = "es"
325
+ @spanish_locale = Locale.create!(:code => 'es')
326
+ end
327
+
328
+ it "should create a record with a nil value when the key is a string" do
329
+ @backend.translate("es", "String").should == "String"
330
+ @spanish_locale.should have(1).translation
331
+ @spanish_locale.translations.first.key.should == Translation.hk("String")
332
+ @spanish_locale.translations.first.value.should be_nil
333
+ end
334
+
335
+ it "should not write to the cache if the key already exists in the cache" do
336
+ @backend.cache_store = MemoryStoreProxy.new
337
+ @english_locale.translations.create!(:key => 'Message Center', :value => 'Message Center')
338
+ @spanish_locale.translations.create!(:key => 'Message Center', :value => nil)
339
+
340
+ @backend.translate("es", "Message Center").should == "Message Center"
341
+ @backend.cache_store.write_count.should == 1
342
+
343
+ @backend.translate("es", "Message Center").should == "Message Center"
344
+ @backend.cache_store.write_count.should == 1
345
+ end
346
+
347
+ it "should handle basic workflow" do
348
+ @english_locale.translations.create!(:key => 'Message Center', :value => 'Message Center')
349
+ @spanish_locale.translations.create!(:key => 'Message Center', :value => nil)
350
+
351
+ @backend.translate("en", "Message Center").should == "Message Center"
352
+
353
+ @english_locale.should have(1).translation
354
+ @english_locale.translations.first.key.should == Translation.hk("Message Center")
355
+ @english_locale.translations.first.raw_key.should == "Message Center"
356
+ @english_locale.translations.first.value.should == "Message Center"
357
+
358
+ @backend.translate("es", "Message Center").should == "Message Center"
359
+
360
+ @spanish_locale.should have(1).translation
361
+ @spanish_locale.translations.first.key.should == Translation.hk("Message Center")
362
+ @spanish_locale.translations.first.value.should be_nil
363
+
364
+ @backend.translate("es", "Message Center").should == "Message Center"
365
+ @spanish_locale.should have(1).translation
366
+ end
367
+
368
+ it "should return default locale (en) value and create the spanish record" do
369
+ @english_locale.translations.create!(:key => 'String', :value => 'English String')
370
+ @backend.translate("es", "String").should == "English String"
371
+ @spanish_locale.should have(1).translation
372
+ end
373
+
374
+ it "should return just the passed in value when no translated record and no default translation" do
375
+ @backend.translate("es", "String").should == "String"
376
+ @spanish_locale.should have(1).translation
377
+ end
378
+
379
+ it "should support having a default locale record with a nil value" do
380
+ @english_locale.translations.create!(:key => 'date.order')
381
+ @backend.translate("es", :'date.order').should be_nil
382
+
383
+ @spanish_locale.should have(1).translation
384
+ @spanish_locale.translations.first.key.should == Translation.hk('date.order')
385
+ @spanish_locale.translations.first.value.should be_nil
386
+ end
387
+
388
+ it "should be able to handle interpolated values" do
389
+ options = {:some_value => 'INTERPOLATED'}
390
+ @english_locale.translations.create!(:key => 'Fred', :value => 'Fred has been {{some_value}}!!')
391
+ @spanish_locale.translations.create!(:key => 'Fred', :value => 'Fred ha sido {{some_value}}!!')
392
+ @backend.translate("es", 'Fred', options).should == 'Fred ha sido INTERPOLATED!!'
393
+ end
394
+
395
+ it "should be able to handle interpolated count values" do
396
+ options = {:count=>1, :model => ["Cheese"], :scope=>[:activerecord, :errors], :default=>["Locale"]}
397
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => '{{count}} error prohibited this {{model}} from being saved')
398
+ @backend.translate("es", :"messages.blank", options).should == '1 error prohibited this Cheese from being saved'
399
+ end
400
+
401
+ it "should be able to handle pluralization" do
402
+ @english_locale.translations.create!(:key => 'activerecord.errors.template.header', :value => '1 error prohibited this {{model}} from being saved', :pluralization_index => 1)
403
+ @english_locale.translations.create!(:key => 'activerecord.errors.template.header', :value => '{{count}} errors prohibited this {{model}} from being saved', :pluralization_index => 0)
404
+ options = {:count=>1, :model=>"translation", :scope=>[:activerecord, :errors, :template]}
405
+ @backend.translate("es", :"header", options).should == "1 error prohibited this translation from being saved"
406
+ @spanish_locale.should have(2).translations
407
+
408
+ options = {:count=>2, :model=>"translation", :scope=>[:activerecord, :errors, :template]}
409
+ @backend.translate("es", :"header", options).should == "2 errors prohibited this translation from being saved"
410
+ @spanish_locale.reload.should have(2).translations
411
+ end
412
+
413
+ it "should find lowest level translation" do
414
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
415
+
416
+ options = {:attribute=>"Locale", :value=>nil,
417
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", :"messages.blank"], :model=>"Translation"}
418
+
419
+ @backend.translate("es", :"models.translation.attributes.locale.blank", options).should == "is blank moron!"
420
+
421
+ @spanish_locale.should have(1).translation
422
+ @spanish_locale.translations.first.key.should == Translation.hk("activerecord.errors.messages.blank")
423
+ @spanish_locale.translations.first.value.should be_nil
424
+ end
425
+
426
+ it "should find higher level translation" do
427
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
428
+ @english_locale.translations.create!(:key => 'activerecord.errors.models.translation.blank', :value => 'translation blank')
429
+
430
+ options = {:attribute=>"Locale", :value=>nil,
431
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", :"messages.blank"], :model=>"Translation"}
432
+
433
+ @backend.translate("es", :"models.translation.attributes.locale.blank", options).should == "translation blank"
434
+ @spanish_locale.should have(1).translation
435
+ @spanish_locale.translations.first.key.should == Translation.hk("activerecord.errors.models.translation.blank")
436
+ @spanish_locale.translations.first.value.should be_nil
437
+ @backend.cache_store.read("es:activerecord.errors.models.translation.blank", "translation blank")
438
+ end
439
+
440
+ it "should find highest level translation" do
441
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
442
+ @english_locale.translations.create!(:key => 'activerecord.errors.models.translation.blank', :value => 'translation blank')
443
+ @english_locale.translations.create!(:key => 'activerecord.errors.models.translation.attributes.locale.blank', :value => 'translation locale blank')
444
+
445
+ options = {:attribute=>"Locale", :value=>nil,
446
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", :"messages.blank"], :model=>"Translation"}
447
+
448
+ @backend.translate("es", :"models.translation.attributes.locale.blank", options).should == "translation locale blank"
449
+ @spanish_locale.should have(1).translation
450
+ @spanish_locale.translations.first.key.should == Translation.hk("activerecord.errors.models.translation.attributes.locale.blank")
451
+ @spanish_locale.translations.first.value.should be_nil
452
+ end
453
+
454
+ it "should find the translation for custom message" do
455
+ @english_locale.translations.create!(:key => 'activerecord.errors.messages.blank', :value => 'is blank moron!')
456
+ @english_locale.translations.create!(:key => 'This is a custom message!', :value => 'This is a custom message!')
457
+
458
+ options = {:attribute=>"Locale", :value=>nil,
459
+ :scope=>[:activerecord, :errors], :default=>[:"models.translation.blank", "This is a custom message!", :"messages.blank"], :model=>"Translation"}
460
+
461
+ @backend.translate("es", :"models.translation.attributes.locale.blank", options).should == "This is a custom message!"
462
+ @spanish_locale.should have(1).translation
463
+ @spanish_locale.translations.first.key.should == Translation.hk("This is a custom message!")
464
+ @spanish_locale.translations.first.value.should be_nil
465
+ end
466
+
467
+ it "should return an array from spanish locale" do
468
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'January', :pluralization_index => 1)
469
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'February', :pluralization_index => 2)
470
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'March', :pluralization_index => 3)
471
+ @spanish_locale.translations.create!(:key => 'date.month_names', :value => 'Enero', :pluralization_index => 1)
472
+ @spanish_locale.translations.create!(:key => 'date.month_names', :value => 'Febrero', :pluralization_index => 2)
473
+ @spanish_locale.translations.create!(:key => 'date.month_names', :value => 'Marzo', :pluralization_index => 3)
474
+
475
+ @backend.translate("es", :"date.month_names").should == [nil, 'Enero', 'Febrero', 'Marzo']
476
+
477
+ # once cached
478
+ @backend.translate("es", :"date.month_names").should == [nil, 'Enero', 'Febrero', 'Marzo']
479
+ @english_locale.reload.should have(3).translation
480
+ @spanish_locale.reload.should have(3).translation
481
+ end
482
+
483
+ it "should return an array from default locale" do
484
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'January', :pluralization_index => 1)
485
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'February', :pluralization_index => 2)
486
+ @english_locale.translations.create!(:key => 'date.month_names', :value => 'March', :pluralization_index => 3)
487
+ @backend.translate("es", :"date.month_names").should == [nil, 'January', 'February', 'March']
488
+
489
+ # once cached
490
+ @backend.translate("es", :"date.month_names").should == [nil, 'January', 'February', 'March']
491
+ @english_locale.reload.should have(3).translation
492
+ @spanish_locale.reload.should have(3).translation
493
+ end
494
+
495
+ it "should return an array of days" do
496
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Sunday', :pluralization_index => 0)
497
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Monday', :pluralization_index => 1)
498
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Tuesday', :pluralization_index => 2)
499
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Wednesday', :pluralization_index => 3)
500
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Thursday', :pluralization_index => 4)
501
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Friday', :pluralization_index => 5)
502
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Saturday', :pluralization_index => 6)
503
+ @backend.translate("es", :"date.day_names").should == ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
504
+
505
+ # once cached
506
+ @backend.translate("es", :"date.day_names").should == ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
507
+ @english_locale.reload.should have(7).translation
508
+ @spanish_locale.reload.should have(7).translation
509
+ end
510
+
511
+ it "should return an array of days" do
512
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Sunday', :pluralization_index => 0)
513
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Monday', :pluralization_index => 1)
514
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Tuesday', :pluralization_index => 2)
515
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Wednesday', :pluralization_index => 3)
516
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Thursday', :pluralization_index => 4)
517
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Friday', :pluralization_index => 5)
518
+ @english_locale.translations.create!(:key => 'date.day_names', :value => 'Saturday', :pluralization_index => 6)
519
+ @spanish_locale.translations.create!(:key => 'date.day_names', :value => nil, :pluralization_index => 0)
520
+ @spanish_locale.translations.create!(:key => 'date.day_names', :value => nil, :pluralization_index => 1)
521
+ @spanish_locale.translations.create!(:key => 'date.day_names', :value => nil, :pluralization_index => 2)
522
+ @spanish_locale.translations.create!(:key => 'date.day_names', :value => nil, :pluralization_index => 3)
523
+ @spanish_locale.translations.create!(:key => 'date.day_names', :value => nil, :pluralization_index => 4)
524
+ @spanish_locale.translations.create!(:key => 'date.day_names', :value => nil, :pluralization_index => 5)
525
+ @spanish_locale.translations.create!(:key => 'date.day_names', :value => nil, :pluralization_index => 6)
526
+ @backend.translate("es", :"date.day_names").should == ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
527
+
528
+ # once cached
529
+ @backend.translate("es", :"date.day_names").should == ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
530
+ @english_locale.reload.should have(7).translation
531
+ @spanish_locale.reload.should have(7).translation
532
+ end
533
+
534
+ it "should support storing values as YAML symbols" do
535
+ @english_locale.translations.create!(:key => 'date.order', :value => "--- :year\n", :pluralization_index => 0)
536
+ @english_locale.translations.create!(:key => 'date.order', :value => "--- :month\n", :pluralization_index => 1)
537
+ @english_locale.translations.create!(:key => 'date.order', :value => "--- :day\n", :pluralization_index => 2)
538
+
539
+ @backend.translate("es", :'date.order').should == [:year, :month, :day]
540
+ @english_locale.should have(3).translations
541
+ @spanish_locale.should have(3).translations
542
+ end
543
+
544
+ end
545
+ end
546
+ end