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.
- checksums.yaml +7 -0
- data/app/assets/javascripts/rails_i18nterface/application.js +1 -1
- data/app/assets/javascripts/rails_i18nterface/base.js +6 -2
- data/app/assets/stylesheets/rails_i18nterface/application.css +1 -1
- data/app/controllers/rails_i18nterface/translate_controller.rb +23 -30
- data/app/helpers/rails_i18nterface/translate_helper.rb +12 -13
- data/app/models/rails_i18nterface/translation.rb +23 -0
- data/app/views/rails_i18nterface/translate/index.html.erb +1 -1
- data/config/routes.rb +3 -3
- data/db/migrate/20130422115639_rename_translation_to_namespace.rb +8 -0
- data/lib/rails-i18nterface/keys.rb +15 -13
- data/lib/rails-i18nterface/log.rb +2 -2
- data/lib/rails-i18nterface/sourcefiles.rb +11 -6
- data/lib/rails-i18nterface/storage.rb +3 -3
- data/lib/rails-i18nterface/utils.rb +5 -9
- data/lib/rails-i18nterface/version.rb +1 -1
- data/lib/rails-i18nterface/yamlfile.rb +5 -5
- data/lib/rails-i18nterface.rb +7 -7
- data/spec/controllers/translate_controller_spec.rb +29 -29
- data/spec/internal/app/models/article.rb +1 -1
- data/spec/internal/config/routes.rb +2 -2
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +2 -0
- data/spec/internal/log/test.log +1380 -546
- data/spec/lib/keys_spec.rb +63 -63
- data/spec/lib/log_spec.rb +12 -11
- data/spec/lib/sourcefiles_spec.rb +11 -11
- data/spec/lib/storage_spec.rb +7 -7
- data/spec/lib/utils_spec.rb +1 -1
- data/spec/lib/yamlfile_spec.rb +5 -5
- data/spec/models/translation_spec.rb +9 -0
- data/spec/spec_helper.rb +19 -4
- metadata +84 -67
- data/app/models/translation.rb +0 -4
data/spec/lib/keys_spec.rb
CHANGED
@@ -7,71 +7,71 @@ describe RailsI18nterface::Keys do
|
|
7
7
|
@keys = RailsI18nterface::Keys.new
|
8
8
|
end
|
9
9
|
|
10
|
-
describe
|
11
|
-
it
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
37
|
-
it
|
38
|
-
@keys.to_hash[:'article.key3'].should == [
|
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
|
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
|
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
|
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
|
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 => [
|
60
|
+
:no => ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
|
61
61
|
}
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
describe
|
65
|
+
describe 'missing_keys' do
|
66
66
|
before(:each) do
|
67
|
-
@file_path = File.join(i18n_files_dir,
|
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 =>
|
74
|
-
: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
|
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' =>
|
87
|
+
:'home.page_title' => 'app/views/home/index.rhtml',
|
88
88
|
:'home.intro' => 'app/views/home/index.rhtml',
|
89
|
-
:'home.signup' =>
|
90
|
-
:'about.index.page_title' =>
|
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' =>
|
94
|
-
:'about.index.page_title' =>
|
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
|
100
|
-
it
|
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,
|
109
|
-
RailsI18nterface::Keys.contains_key?(hash,
|
110
|
-
RailsI18nterface::Keys.contains_key?(hash,
|
111
|
-
RailsI18nterface::Keys.contains_key?(hash,
|
112
|
-
RailsI18nterface::Keys.contains_key?(hash, :
|
113
|
-
RailsI18nterface::Keys.contains_key?(hash,
|
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
|
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
|
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
|
129
|
-
it
|
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
|
135
|
-
it
|
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 =>
|
150
|
+
:about => 'This site is about making money'
|
151
151
|
},
|
152
152
|
:articles => {
|
153
153
|
:new => {
|
154
|
-
:page_title =>
|
154
|
+
:page_title => 'New Article'
|
155
155
|
}
|
156
156
|
},
|
157
157
|
:categories => {
|
158
158
|
:flash => {
|
159
|
-
: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' =>
|
176
|
-
'pressrelease.label.other' =>
|
177
|
-
'article' =>
|
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 =>
|
187
|
-
:other =>
|
186
|
+
:one => 'Pressmeddelande',
|
187
|
+
:other => 'Pressmeddelanden'
|
188
188
|
}
|
189
189
|
},
|
190
|
-
:article =>
|
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(
|
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
|
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
|
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
|
-
|
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
|
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, {:
|
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 ==
|
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__),
|
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
|
-
:
|
40
|
-
:
|
40
|
+
article: {
|
41
|
+
title: 'En artikel'
|
41
42
|
},
|
42
|
-
:
|
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
|
5
|
+
it 'grabs field from schema.rb' do
|
6
6
|
expected = {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
data/spec/lib/storage_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RailsI18nterface::Storage do
|
4
|
-
describe
|
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
|
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__),
|
19
|
+
File.join(File.dirname(__FILE__), 'files', 'en.yml')
|
20
20
|
end
|
21
21
|
|
22
22
|
def translations
|
23
23
|
{
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
24
|
+
en: {
|
25
|
+
article: {
|
26
|
+
title: 'One Article'
|
27
27
|
},
|
28
|
-
:
|
28
|
+
category: 'Category'
|
29
29
|
}
|
30
30
|
}
|
31
31
|
end
|
data/spec/lib/utils_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe RailsI18nterface::Utils do
|
4
4
|
include RailsI18nterface::Utils
|
5
5
|
|
6
|
-
it
|
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
|
data/spec/lib/yamlfile_spec.rb
CHANGED
@@ -6,9 +6,9 @@ describe RailsI18nterface::Yamlfile do
|
|
6
6
|
@translations = { en: { a: { aa: 'aa' }, b: 'b' } }
|
7
7
|
end
|
8
8
|
|
9
|
-
describe
|
9
|
+
describe 'write' do
|
10
10
|
before(:each) do
|
11
|
-
@file_path = File.join(File.dirname(__FILE__),
|
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
|
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
|
27
|
-
it
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
-
ENV[
|
2
|
-
|
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
|
-
|
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
|
+
|