rails-i18nterface 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/app/assets/javascripts/rails_i18nterface/application.js +1 -1
  3. data/app/assets/javascripts/rails_i18nterface/base.js +6 -2
  4. data/app/assets/stylesheets/rails_i18nterface/application.css +1 -1
  5. data/app/controllers/rails_i18nterface/translate_controller.rb +23 -30
  6. data/app/helpers/rails_i18nterface/translate_helper.rb +12 -13
  7. data/app/models/rails_i18nterface/translation.rb +23 -0
  8. data/app/views/rails_i18nterface/translate/index.html.erb +1 -1
  9. data/config/routes.rb +3 -3
  10. data/db/migrate/20130422115639_rename_translation_to_namespace.rb +8 -0
  11. data/lib/rails-i18nterface/keys.rb +15 -13
  12. data/lib/rails-i18nterface/log.rb +2 -2
  13. data/lib/rails-i18nterface/sourcefiles.rb +11 -6
  14. data/lib/rails-i18nterface/storage.rb +3 -3
  15. data/lib/rails-i18nterface/utils.rb +5 -9
  16. data/lib/rails-i18nterface/version.rb +1 -1
  17. data/lib/rails-i18nterface/yamlfile.rb +5 -5
  18. data/lib/rails-i18nterface.rb +7 -7
  19. data/spec/controllers/translate_controller_spec.rb +29 -29
  20. data/spec/internal/app/models/article.rb +1 -1
  21. data/spec/internal/config/routes.rb +2 -2
  22. data/spec/internal/db/combustion_test.sqlite +0 -0
  23. data/spec/internal/db/schema.rb +2 -0
  24. data/spec/internal/log/test.log +1380 -546
  25. data/spec/lib/keys_spec.rb +63 -63
  26. data/spec/lib/log_spec.rb +12 -11
  27. data/spec/lib/sourcefiles_spec.rb +11 -11
  28. data/spec/lib/storage_spec.rb +7 -7
  29. data/spec/lib/utils_spec.rb +1 -1
  30. data/spec/lib/yamlfile_spec.rb +5 -5
  31. data/spec/models/translation_spec.rb +9 -0
  32. data/spec/spec_helper.rb +19 -4
  33. metadata +84 -67
  34. data/app/models/translation.rb +0 -4
@@ -7,71 +7,71 @@ describe RailsI18nterface::Keys do
7
7
  @keys = RailsI18nterface::Keys.new
8
8
  end
9
9
 
10
- describe "to_a" do
11
- it "extracts keys from I18n lookups in .rb, .html.erb, and .rhtml files" do
10
+ describe 'to_a' do
11
+ it 'extracts keys from I18n lookups in .rb, .html.erb, and .rhtml files' do
12
12
  @keys.to_a.map(&:to_s).sort.should == [
13
- "activerecord.attributes.article.active",
14
- "activerecord.attributes.article.body",
15
- "activerecord.attributes.article.created_at",
16
- "activerecord.attributes.article.title",
17
- "activerecord.attributes.article.updated_at",
18
- "activerecord.attributes.topics.created_at",
19
- "activerecord.attributes.topics.title",
20
- "activerecord.attributes.topics.updated_at",
21
- "activerecord.models.article",
22
- "activerecord.models.topics",
23
- "article.key1",
24
- "article.key2",
25
- "article.key3",
26
- "article.key4",
27
- "article.key5",
28
- "category_erb.key1",
29
- "category_html_erb.key1",
30
- "category_rhtml.key1",
31
- "js.alert"
13
+ 'activerecord.attributes.article.active',
14
+ 'activerecord.attributes.article.body',
15
+ 'activerecord.attributes.article.created_at',
16
+ 'activerecord.attributes.article.title',
17
+ 'activerecord.attributes.article.updated_at',
18
+ 'activerecord.attributes.topics.created_at',
19
+ 'activerecord.attributes.topics.title',
20
+ 'activerecord.attributes.topics.updated_at',
21
+ 'activerecord.models.article',
22
+ 'activerecord.models.topics',
23
+ 'article.key1',
24
+ 'article.key2',
25
+ 'article.key3',
26
+ 'article.key4',
27
+ 'article.key5',
28
+ 'category_erb.key1',
29
+ 'category_html_erb.key1',
30
+ 'category_rhtml.key1',
31
+ 'js.alert'
32
32
  ]
33
33
  end
34
34
  end
35
35
 
36
- describe "to_hash" do
37
- it "return a hash with I18n keys and file lists" do
38
- @keys.to_hash[:'article.key3'].should == ["app/models/article.rb"]
36
+ describe 'to_hash' do
37
+ it 'return a hash with I18n keys and file lists' do
38
+ @keys.to_hash[:'article.key3'].should == ['app/models/article.rb']
39
39
  end
40
40
  end
41
41
 
42
- describe "i18n_keys" do
42
+ describe 'i18n_keys' do
43
43
  before(:each) do
44
44
  I18n.backend.send(:init_translations) unless I18n.backend.initialized?
45
45
  end
46
46
 
47
- it "should return all keys in the I18n backend translations hash" do
47
+ it 'should return all keys in the I18n backend translations hash' do
48
48
  I18n.backend.should_receive(:translations).and_return(translations)
49
49
  @keys.i18n_keys(:en).should == ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
50
50
  end
51
51
 
52
- describe "untranslated_keys" do
52
+ describe 'untranslated_keys' do
53
53
  before(:each) do
54
54
  I18n.backend.stub!(:translations).and_return(translations)
55
55
  end
56
56
 
57
- it "should return a hash with keys with missing translations in each locale" do
57
+ it 'should return a hash with keys with missing translations in each locale' do
58
58
  @keys.untranslated_keys.should == {
59
59
  :sv => ['articles.new.page_title', 'categories.flash.created', 'empty'],
60
- :no => ["articles.new.page_title", "categories.flash.created", "empty", "home.about"]
60
+ :no => ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
61
61
  }
62
62
  end
63
63
  end
64
64
 
65
- describe "missing_keys" do
65
+ describe 'missing_keys' do
66
66
  before(:each) do
67
- @file_path = File.join(i18n_files_dir, "config", "locales", "en.yml")
67
+ @file_path = File.join(i18n_files_dir, 'config', 'locales', 'en.yml')
68
68
  RailsI18nterface::Yamlfile.new(@file_path).write({
69
69
  :en => {
70
70
  :home => {
71
71
  :page_title => false,
72
72
  :intro => {
73
- :one => "intro one",
74
- :other => "intro other"
73
+ :one => 'intro one',
74
+ :other => 'intro other'
75
75
  }
76
76
  }
77
77
  }
@@ -82,22 +82,22 @@ describe RailsI18nterface::Keys do
82
82
  FileUtils.rm(@file_path)
83
83
  end
84
84
 
85
- it "should return a hash with keys that are not in the locale file" do
85
+ it 'should return a hash with keys that are not in the locale file' do
86
86
  @keys.stub!(:files).and_return({
87
- :'home.page_title' => "app/views/home/index.rhtml",
87
+ :'home.page_title' => 'app/views/home/index.rhtml',
88
88
  :'home.intro' => 'app/views/home/index.rhtml',
89
- :'home.signup' => "app/views/home/_signup.rhtml",
90
- :'about.index.page_title' => "app/views/about/index.rhtml"
89
+ :'home.signup' => 'app/views/home/_signup.rhtml',
90
+ :'about.index.page_title' => 'app/views/about/index.rhtml'
91
91
  })
92
92
  @keys.missing_keys.should == {
93
- :'home.signup' => "app/views/home/_signup.rhtml",
94
- :'about.index.page_title' => "app/views/about/index.rhtml"
93
+ :'home.signup' => 'app/views/home/_signup.rhtml',
94
+ :'about.index.page_title' => 'app/views/about/index.rhtml'
95
95
  }
96
96
  end
97
97
  end
98
98
 
99
- describe "contains_key?" do
100
- it "works" do
99
+ describe 'contains_key?' do
100
+ it 'works' do
101
101
  hash = {
102
102
  :foo => {
103
103
  :bar => {
@@ -105,34 +105,34 @@ describe RailsI18nterface::Keys do
105
105
  }
106
106
  }
107
107
  }
108
- RailsI18nterface::Keys.contains_key?(hash, "").should be_false
109
- RailsI18nterface::Keys.contains_key?(hash, "foo").should be_true
110
- RailsI18nterface::Keys.contains_key?(hash, "foo.bar").should be_true
111
- RailsI18nterface::Keys.contains_key?(hash, "foo.bar.baz").should be_true
112
- RailsI18nterface::Keys.contains_key?(hash, :"foo.bar.baz").should be_true
113
- RailsI18nterface::Keys.contains_key?(hash, "foo.bar.baz.bla").should be_false
108
+ RailsI18nterface::Keys.contains_key?(hash, '').should be_false
109
+ RailsI18nterface::Keys.contains_key?(hash, 'foo').should be_true
110
+ RailsI18nterface::Keys.contains_key?(hash, 'foo.bar').should be_true
111
+ RailsI18nterface::Keys.contains_key?(hash, 'foo.bar.baz').should be_true
112
+ RailsI18nterface::Keys.contains_key?(hash, :'foo.bar.baz').should be_true
113
+ RailsI18nterface::Keys.contains_key?(hash, 'foo.bar.baz.bla').should be_false
114
114
  end
115
115
  end
116
116
 
117
- describe "translated_locales" do
117
+ describe 'translated_locales' do
118
118
  before(:each) do
119
119
  I18n.stub!(:default_locale).and_return(:en)
120
120
  I18n.stub!(:available_locales).and_return([:sv, :no, :en, :root])
121
121
  end
122
122
 
123
- it "returns all avaiable except :root and the default" do
123
+ it 'returns all avaiable except :root and the default' do
124
124
  RailsI18nterface::Keys.translated_locales.should == [:sv, :no]
125
125
  end
126
126
  end
127
127
 
128
- describe "to_deep_hash" do
129
- it "convert shallow hash with dot separated keys to deep hash" do
128
+ describe 'to_deep_hash' do
129
+ it 'convert shallow hash with dot separated keys to deep hash' do
130
130
  RailsI18nterface::Keys.to_deep_hash(shallow_hash).should == deep_hash
131
131
  end
132
132
  end
133
133
 
134
- describe "to_shallow_hash" do
135
- it "converts a deep hash to a shallow one" do
134
+ describe 'to_shallow_hash' do
135
+ it 'converts a deep hash to a shallow one' do
136
136
  RailsI18nterface::Keys.to_shallow_hash(deep_hash).should == shallow_hash
137
137
  end
138
138
  end
@@ -147,16 +147,16 @@ describe RailsI18nterface::Keys do
147
147
  {
148
148
  :en => {
149
149
  :home => {
150
- :about => "This site is about making money"
150
+ :about => 'This site is about making money'
151
151
  },
152
152
  :articles => {
153
153
  :new => {
154
- :page_title => "New Article"
154
+ :page_title => 'New Article'
155
155
  }
156
156
  },
157
157
  :categories => {
158
158
  :flash => {
159
- :created => "Category created"
159
+ :created => 'Category created'
160
160
  }
161
161
  },
162
162
  :empty => nil
@@ -172,9 +172,9 @@ describe RailsI18nterface::Keys do
172
172
 
173
173
  def shallow_hash
174
174
  {
175
- 'pressrelease.label.one' => "Pressmeddelande",
176
- 'pressrelease.label.other' => "Pressmeddelanden",
177
- 'article' => "Artikel",
175
+ 'pressrelease.label.one' => 'Pressmeddelande',
176
+ 'pressrelease.label.other' => 'Pressmeddelanden',
177
+ 'article' => 'Artikel',
178
178
  'category' => ''
179
179
  }
180
180
  end
@@ -183,16 +183,16 @@ describe RailsI18nterface::Keys do
183
183
  {
184
184
  :pressrelease => {
185
185
  :label => {
186
- :one => "Pressmeddelande",
187
- :other => "Pressmeddelanden"
186
+ :one => 'Pressmeddelande',
187
+ :other => 'Pressmeddelanden'
188
188
  }
189
189
  },
190
- :article => "Artikel",
190
+ :article => 'Artikel',
191
191
  :category => ''
192
192
  }
193
193
  end
194
194
 
195
195
  def i18n_files_dir
196
- File.expand_path(File.join("..", "..", "..", "spec", "internal"), __FILE__)
196
+ File.expand_path(File.join('..', '..', '..', 'spec', 'internal'), __FILE__)
197
197
  end
198
198
  end
data/spec/lib/log_spec.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RailsI18nterface::Log do
4
- describe "write_to_file" do
4
+ describe 'write_to_file' do
5
5
  before(:each) do
6
6
  I18n.locale = :sv
7
7
  I18n.backend.store_translations(:sv, from_texts)
8
- keys = RailsI18nterface::Keys.new
8
+ #keys = RailsI18nterface::Keys.new
9
9
  @log = RailsI18nterface::Log.new(:sv, :en, RailsI18nterface::Keys.to_shallow_hash(from_texts).keys)
10
10
  @log.stub!(:file_path).and_return(file_path)
11
11
  FileUtils.rm_f file_path
@@ -15,31 +15,32 @@ describe RailsI18nterface::Log do
15
15
  FileUtils.rm_f file_path
16
16
  end
17
17
 
18
- it "writes new log file with from texts" do
18
+ it 'writes new log file with from texts' do
19
19
  File.exists?(file_path).should be_false
20
20
  @log.write_to_file
21
21
  File.exists?(file_path).should be_true
22
- RailsI18nterface::Yamlfile.new(file_path).read.should == RailsI18nterface::Yamlfile.new(nil).deep_stringify_keys(from_texts)
22
+ expected = RailsI18nterface::Yamlfile.new(nil).deep_stringify_keys(from_texts)
23
+ RailsI18nterface::Yamlfile.new(file_path).read.should == expected
23
24
  end
24
25
 
25
- it "merges from texts with current texts in log file and re-writes the log file" do
26
+ it 'merges from texts with current texts in log file and re-writes the log file' do
26
27
  @log.write_to_file
27
- I18n.backend.store_translations(:sv, {:category => "Kategori ny"})
28
+ I18n.backend.store_translations(:sv, { category: 'Kategori ny' })
28
29
  @log.keys = ['category']
29
30
  @log.write_to_file
30
- RailsI18nterface::Yamlfile.new(file_path).read['category'].should == "Kategori ny"
31
+ RailsI18nterface::Yamlfile.new(file_path).read['category'].should == 'Kategori ny'
31
32
  end
32
33
 
33
34
  def file_path
34
- File.join(File.dirname(__FILE__), "files", "from_sv_to_en.yml")
35
+ File.join(File.dirname(__FILE__), 'files', 'from_sv_to_en.yml')
35
36
  end
36
37
 
37
38
  def from_texts
38
39
  {
39
- :article => {
40
- :title => "En artikel"
40
+ article: {
41
+ title: 'En artikel'
41
42
  },
42
- :category => "Kategori"
43
+ category: 'Kategori'
43
44
  }
44
45
  end
45
46
  end
@@ -2,18 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  describe RailsI18nterface::Sourcefiles do
4
4
 
5
- it "grabs field from schema.rb" do
5
+ it 'grabs field from schema.rb' do
6
6
  expected = {
7
- "activerecord.models.article"=>["db/schema.rb"],
8
- "activerecord.attributes.article.title"=>["db/schema.rb"],
9
- "activerecord.attributes.article.body"=>["db/schema.rb"],
10
- "activerecord.attributes.article.created_at"=>["db/schema.rb"],
11
- "activerecord.attributes.article.updated_at"=>["db/schema.rb"],
12
- "activerecord.attributes.article.active"=>["db/schema.rb"],
13
- "activerecord.models.topics"=>["db/schema.rb"],
14
- "activerecord.attributes.topics.title"=>["db/schema.rb"],
15
- "activerecord.attributes.topics.created_at"=>["db/schema.rb"],
16
- "activerecord.attributes.topics.updated_at"=>["db/schema.rb"]
7
+ 'activerecord.models.article'=>['db/schema.rb'],
8
+ 'activerecord.attributes.article.title'=>['db/schema.rb'],
9
+ 'activerecord.attributes.article.body'=>['db/schema.rb'],
10
+ 'activerecord.attributes.article.created_at'=>['db/schema.rb'],
11
+ 'activerecord.attributes.article.updated_at'=>['db/schema.rb'],
12
+ 'activerecord.attributes.article.active'=>['db/schema.rb'],
13
+ 'activerecord.models.topics'=>['db/schema.rb'],
14
+ 'activerecord.attributes.topics.title'=>['db/schema.rb'],
15
+ 'activerecord.attributes.topics.created_at'=>['db/schema.rb'],
16
+ 'activerecord.attributes.topics.updated_at'=>['db/schema.rb']
17
17
  }
18
18
 
19
19
  hash = RailsI18nterface::Sourcefiles.extract_activerecords
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RailsI18nterface::Storage do
4
- describe "write_to_file" do
4
+ describe 'write_to_file' do
5
5
  before(:each) do
6
6
  @storage = RailsI18nterface::Storage.new(:en)
7
7
  end
8
8
 
9
- it "writes all I18n messages for a locale to YAML file" do
9
+ it 'writes all I18n messages for a locale to YAML file' do
10
10
  I18n.backend.should_receive(:translations).and_return(translations)
11
11
  @storage.stub!(:file_path).and_return(file_path)
12
12
  file = mock(:file)
@@ -16,16 +16,16 @@ describe RailsI18nterface::Storage do
16
16
  end
17
17
 
18
18
  def file_path
19
- File.join(File.dirname(__FILE__), "files", "en.yml")
19
+ File.join(File.dirname(__FILE__), 'files', 'en.yml')
20
20
  end
21
21
 
22
22
  def translations
23
23
  {
24
- :en => {
25
- :article => {
26
- :title => "One Article"
24
+ en: {
25
+ article: {
26
+ title: 'One Article'
27
27
  },
28
- :category => "Category"
28
+ category: 'Category'
29
29
  }
30
30
  }
31
31
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe RailsI18nterface::Utils do
4
4
  include RailsI18nterface::Utils
5
5
 
6
- it "Removes blanks from a hash" do
6
+ it 'Removes blanks from a hash' do
7
7
  hash = { a: 'a', b: { ba: '', bb: 'bb'}, c: '', d: { }, e: { ea: 'ee', eb: { } } }
8
8
  expected = { a: 'a', b: { bb: 'bb'}, e: { ea: 'ee' } }
9
9
  remove_blanks(hash).should == expected
@@ -6,9 +6,9 @@ describe RailsI18nterface::Yamlfile do
6
6
  @translations = { en: { a: { aa: 'aa' }, b: 'b' } }
7
7
  end
8
8
 
9
- describe "write" do
9
+ describe 'write' do
10
10
  before(:each) do
11
- @file_path = File.join(File.dirname(__FILE__), "files", "en.yml")
11
+ @file_path = File.join(File.dirname(__FILE__), 'files', 'en.yml')
12
12
  @file = RailsI18nterface::Yamlfile.new(@file_path)
13
13
  end
14
14
 
@@ -16,15 +16,15 @@ describe RailsI18nterface::Yamlfile do
16
16
  FileUtils.rm(@file_path)
17
17
  end
18
18
 
19
- it "writes all I18n messages for a locale to YAML file" do
19
+ it 'writes all I18n messages for a locale to YAML file' do
20
20
  @file.write(@translations)
21
21
  @file.read.should == RailsI18nterface::Yamlfile.new(nil).deep_stringify_keys(@translations)
22
22
  end
23
23
 
24
24
  end
25
25
 
26
- describe "deep_stringify_keys" do
27
- it "should convert all keys in a hash to strings" do
26
+ describe 'deep_stringify_keys' do
27
+ it 'should convert all keys in a hash to strings' do
28
28
  expected = { 'en' => { 'a' => { 'aa' => 'aa' }, 'b' => 'b' } }
29
29
  RailsI18nterface::Yamlfile.new(nil).deep_stringify_keys(@translations).should == expected
30
30
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsI18nterface::Translation do
4
+
5
+ it 'can update entries' do
6
+ puts RailsI18nterface::Translation.all
7
+ end
8
+
9
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,18 @@
1
- ENV["RAILS_ENV"] ||= 'test'
2
- $:<<File.expand_path("../../lib",__FILE__)
1
+ if ENV['COV']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter '/spec/'
5
+ add_filter '/config/'
6
+ add_filter '/db/'
7
+ add_group 'Models', '/app/models/'
8
+ add_group 'Controllers', '/app/controllers/'
9
+ add_group 'Helpers', '/app/helpers/'
10
+ add_group 'Lib', '/lib/'
11
+ end
12
+ end
13
+
14
+ ENV['RAILS_ENV'] ||= 'test'
15
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
16
 
4
17
  require 'rubygems'
5
18
  require 'bundler'
@@ -17,7 +30,8 @@ require 'rspec/autorun'
17
30
  require 'capybara/rails'
18
31
  require 'rails-i18nterface'
19
32
 
20
- new_root = File.expand_path(File.join("..", "internal"), __FILE__)
33
+
34
+ new_root = File.expand_path(File.join('..', 'internal'), __FILE__)
21
35
 
22
36
  RSpec.configure do |config|
23
37
  config.mock_with :rspec
@@ -34,4 +48,5 @@ end
34
48
 
35
49
  # improve the performance of the specs suite by not logging anything
36
50
  # see http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/
37
- Rails.logger.level = 4
51
+ Rails.logger.level = 4
52
+