rails-i18nterface 0.2.0 → 0.2.1
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.
- data/README.md +2 -1
- data/app/assets/stylesheets/rails_i18nterface/application.css +8 -4
- data/app/controllers/rails_i18nterface/translate_controller.rb +10 -97
- data/app/helpers/rails_i18nterface/translate_helper.rb +4 -0
- data/app/views/rails_i18nterface/translate/_pagination.html.erb +58 -6
- data/app/views/rails_i18nterface/translate/index.html.erb +13 -12
- data/lib/rails-i18nterface.rb +0 -1
- data/lib/rails-i18nterface/cache.rb +14 -20
- data/lib/rails-i18nterface/keys.rb +69 -4
- data/lib/rails-i18nterface/sourcefiles.rb +19 -9
- data/lib/rails-i18nterface/utils.rb +14 -0
- data/lib/rails-i18nterface/version.rb +1 -1
- data/spec/controllers/translate_controller_spec.rb +30 -34
- data/spec/internal/app/controllers/application_controller.rb +2 -0
- data/spec/internal/app/models/article.rb +3 -0
- data/spec/internal/log/test.log +752 -219
- data/spec/internal/tmp/translation_strings +1 -0
- data/spec/lib/cache_spec.rb +12 -16
- data/spec/lib/keys_spec.rb +28 -28
- data/spec/lib/sourcefiles_spec.rb +33 -2
- data/spec/spec_helper.rb +5 -0
- metadata +6 -7
- data/lib/rails-i18nterface/storage.rb +0 -32
- data/spec/lib/storage_spec.rb +0 -35
@@ -0,0 +1 @@
|
|
1
|
+
C:-ActiveSupport::HashWithIndifferentAccess{I"article.key1:EF[I"app/models/article.rb;TI"article.key2;F[I"app/models/article.rb;TI"article.key3;F[I"app/models/article.rb;TI"article.key4;F[I"app/models/article.rb;TI"article.key5;F[I"app/models/article.rb;TI"category_html_erb.key1;F[I"+app/views/categories/category.html.erb;TI"category_erb.key1;F[I"&app/views/categories/category.erb;TI"category_rhtml.key1;F[I"(app/views/categories/category.rhtml;TI"
|
data/spec/lib/cache_spec.rb
CHANGED
@@ -7,16 +7,10 @@ describe RailsI18nterface::Cache do
|
|
7
7
|
|
8
8
|
before :each do
|
9
9
|
@cachefile = File.expand_path(File.join('..', 'files', 'cache_test'), __FILE__)
|
10
|
-
@file = File.join(File.dirname(@cachefile), 'test.yml')
|
11
|
-
@sample = { 'a' => 'a', 'b' => 'b' }
|
12
|
-
File.open(@file, 'w') do |f|
|
13
|
-
f.write YAML.dump(@sample)
|
14
|
-
end
|
15
10
|
end
|
16
11
|
|
17
12
|
after :each do
|
18
13
|
FileUtils.rm @cachefile if File.exists? @cachefile
|
19
|
-
FileUtils.rm @file if File.exists? @file
|
20
14
|
end
|
21
15
|
|
22
16
|
it 'stores cache of an object' do
|
@@ -28,24 +22,26 @@ describe RailsI18nterface::Cache do
|
|
28
22
|
it 'reads cache from marshalled file' do
|
29
23
|
a = { a: 'a' }
|
30
24
|
cache_save a, @cachefile
|
31
|
-
b = cache_load @cachefile
|
25
|
+
b = cache_load @cachefile
|
32
26
|
b.should == a
|
33
27
|
end
|
34
28
|
|
35
29
|
it 'creates the cache if not present' do
|
36
|
-
b = cache_load @cachefile
|
37
|
-
|
30
|
+
b = cache_load @cachefile do
|
31
|
+
20
|
38
32
|
end
|
39
|
-
|
33
|
+
File.exists?(@cachefile).should be_true
|
34
|
+
b.should == 20
|
40
35
|
end
|
41
36
|
|
42
|
-
it '
|
43
|
-
|
44
|
-
|
45
|
-
b = cache_load @cachefile, @file do
|
46
|
-
YAML.load_file @file
|
37
|
+
it 'creates the cache if not present, using an argument' do
|
38
|
+
b = cache_load @cachefile, 'something' do |options|
|
39
|
+
options
|
47
40
|
end
|
48
|
-
|
41
|
+
File.exists?(@cachefile).should be_true
|
42
|
+
b.should == 'something'
|
49
43
|
end
|
50
44
|
|
45
|
+
|
46
|
+
|
51
47
|
end
|
data/spec/lib/keys_spec.rb
CHANGED
@@ -11,36 +11,36 @@ describe RailsI18nterface::Keys do
|
|
11
11
|
@keys = RailsI18nterface::Keys.new(@root_dir, :sv, :no)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
]
|
37
|
-
end
|
14
|
+
it 'extracts keys from I18n lookups in .rb, .html.erb, and .rhtml files' do
|
15
|
+
@keys.files.keys.map(&:to_s).sort.should == [
|
16
|
+
'activerecord.attributes.article.active',
|
17
|
+
'activerecord.attributes.article.body',
|
18
|
+
'activerecord.attributes.article.created_at',
|
19
|
+
'activerecord.attributes.article.title',
|
20
|
+
'activerecord.attributes.article.updated_at',
|
21
|
+
'activerecord.attributes.topic.created_at',
|
22
|
+
'activerecord.attributes.topic.title',
|
23
|
+
'activerecord.attributes.topic.updated_at',
|
24
|
+
'activerecord.models.article',
|
25
|
+
'activerecord.models.topic',
|
26
|
+
'article.key1',
|
27
|
+
'article.key2',
|
28
|
+
'article.key3',
|
29
|
+
'article.key4',
|
30
|
+
'article.key5',
|
31
|
+
'category_erb.key1',
|
32
|
+
'category_html_erb.key1',
|
33
|
+
'category_rhtml.key1',
|
34
|
+
'js.alert'
|
35
|
+
]
|
38
36
|
end
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
it 'return a hash with I18n keys and file lists' do
|
39
|
+
@keys.files[:'article.key3'].should == ['app/models/article.rb']
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'reloads the translatable strings' do
|
43
|
+
@keys.reload(@root_dir).size.should == 123
|
44
44
|
end
|
45
45
|
|
46
46
|
describe 'i18n_keys' do
|
@@ -4,6 +4,12 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe RailsI18nterface::Sourcefiles do
|
6
6
|
|
7
|
+
before :each do
|
8
|
+
@root_dir = File.expand_path(File.join('..', '..', '..', 'spec', 'internal'), __FILE__)
|
9
|
+
@cache_file = File.join(@root_dir, 'tmp', 'translation_strings')
|
10
|
+
FileUtils.rm @cache_file if File.exists? @cache_file
|
11
|
+
end
|
12
|
+
|
7
13
|
it 'grabs field from schema.rb' do
|
8
14
|
expected = {
|
9
15
|
'activerecord.models.article'=>['db/schema.rb'],
|
@@ -17,9 +23,34 @@ describe RailsI18nterface::Sourcefiles do
|
|
17
23
|
'activerecord.attributes.topic.created_at'=>['db/schema.rb'],
|
18
24
|
'activerecord.attributes.topic.updated_at'=>['db/schema.rb']
|
19
25
|
}
|
20
|
-
|
21
|
-
hash = RailsI18nterface::Sourcefiles.extract_activerecords(root_dir)
|
26
|
+
hash = RailsI18nterface::Sourcefiles.extract_activerecords(@root_dir)
|
22
27
|
hash.should == expected
|
23
28
|
end
|
24
29
|
|
30
|
+
it 'extracts translatable string from code source' do
|
31
|
+
x = RailsI18nterface::Sourcefiles.load_files(@root_dir)
|
32
|
+
File.exists?(@cache_file).should be_true
|
33
|
+
x.size.should == 19
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'refreshing' do
|
37
|
+
before :each do
|
38
|
+
RailsI18nterface::Sourcefiles.load_files(@root_dir)
|
39
|
+
@testfile = File.join(@root_dir,'app','views','test.html.erb')
|
40
|
+
end
|
41
|
+
|
42
|
+
after :each do
|
43
|
+
FileUtils.rm @testfile if File.exists? @testfile
|
44
|
+
FileUtils.rm @cache_file if File.exists? @cache_file
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'refreshes translatable strings cache' do
|
48
|
+
File.open(File.join(@root_dir,'app','views','test.html.erb'),'w') do |f|
|
49
|
+
f.puts "<%= t('something') %>"
|
50
|
+
end
|
51
|
+
y = RailsI18nterface::Sourcefiles.refresh(@root_dir)
|
52
|
+
y.size.should == 20
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
25
56
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
if ENV['COV']
|
4
4
|
require 'simplecov'
|
5
|
+
require 'coveralls'
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
5
10
|
SimpleCov.start do
|
6
11
|
add_filter '/spec/'
|
7
12
|
add_filter '/config/'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-i18nterface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -200,7 +200,6 @@ files:
|
|
200
200
|
- lib/rails-i18nterface/cache.rb
|
201
201
|
- lib/rails-i18nterface/utils.rb
|
202
202
|
- lib/rails-i18nterface/engine.rb
|
203
|
-
- lib/rails-i18nterface/storage.rb
|
204
203
|
- lib/rails-i18nterface/yamlfile.rb
|
205
204
|
- lib/rails-i18nterface/version.rb
|
206
205
|
- MIT-LICENSE
|
@@ -217,13 +216,13 @@ files:
|
|
217
216
|
- spec/internal/app/assets/stylesheets/application.css
|
218
217
|
- spec/internal/app/controllers/application_controller.rb
|
219
218
|
- spec/internal/log/test.log
|
219
|
+
- spec/internal/tmp/translation_strings
|
220
220
|
- spec/internal/config/routes.rb
|
221
221
|
- spec/internal/config/database.yml
|
222
222
|
- spec/internal/db/schema.rb
|
223
223
|
- spec/internal/db/combustion_test.sqlite
|
224
224
|
- spec/requests/search_spec.rb
|
225
225
|
- spec/lib/utils_spec.rb
|
226
|
-
- spec/lib/storage_spec.rb
|
227
226
|
- spec/lib/cache_spec.rb
|
228
227
|
- spec/lib/yamlfile_spec.rb
|
229
228
|
- spec/lib/keys_spec.rb
|
@@ -245,7 +244,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
245
244
|
version: '0'
|
246
245
|
segments:
|
247
246
|
- 0
|
248
|
-
hash: -
|
247
|
+
hash: -901846675
|
249
248
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
249
|
none: false
|
251
250
|
requirements:
|
@@ -254,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
253
|
version: '0'
|
255
254
|
segments:
|
256
255
|
- 0
|
257
|
-
hash: -
|
256
|
+
hash: -901846675
|
258
257
|
requirements: []
|
259
258
|
rubyforge_project:
|
260
259
|
rubygems_version: 1.8.25
|
@@ -273,13 +272,13 @@ test_files:
|
|
273
272
|
- spec/internal/app/assets/stylesheets/application.css
|
274
273
|
- spec/internal/app/controllers/application_controller.rb
|
275
274
|
- spec/internal/log/test.log
|
275
|
+
- spec/internal/tmp/translation_strings
|
276
276
|
- spec/internal/config/routes.rb
|
277
277
|
- spec/internal/config/database.yml
|
278
278
|
- spec/internal/db/schema.rb
|
279
279
|
- spec/internal/db/combustion_test.sqlite
|
280
280
|
- spec/requests/search_spec.rb
|
281
281
|
- spec/lib/utils_spec.rb
|
282
|
-
- spec/lib/storage_spec.rb
|
283
282
|
- spec/lib/cache_spec.rb
|
284
283
|
- spec/lib/yamlfile_spec.rb
|
285
284
|
- spec/lib/keys_spec.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module RailsI18nterface
|
4
|
-
class Storage
|
5
|
-
|
6
|
-
include Utils
|
7
|
-
|
8
|
-
attr_accessor :locale
|
9
|
-
|
10
|
-
def initialize(locale)
|
11
|
-
self.locale = locale.to_sym
|
12
|
-
end
|
13
|
-
|
14
|
-
def write_to_file
|
15
|
-
Yamlfile.new(file_path).write(remove_blanks(keys))
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.root_dir
|
19
|
-
Rails.root
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def keys
|
25
|
-
{ locale => I18n.backend.send(:translations)[locale] }
|
26
|
-
end
|
27
|
-
|
28
|
-
def file_path
|
29
|
-
File.join(self.class.root_dir, 'config', 'locales', "#{locale}.yml")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/spec/lib/storage_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe RailsI18nterface::Storage do
|
6
|
-
describe 'write_to_file' do
|
7
|
-
before(:each) do
|
8
|
-
@storage = RailsI18nterface::Storage.new(:en)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'writes all I18n messages for a locale to YAML file' do
|
12
|
-
I18n.backend.should_receive(:translations).and_return(translations)
|
13
|
-
@storage.stub!(:file_path).and_return(file_path)
|
14
|
-
file = mock(:file)
|
15
|
-
file.should_receive(:write).with(translations)
|
16
|
-
RailsI18nterface::Yamlfile.should_receive(:new).with(file_path).and_return(file)
|
17
|
-
@storage.write_to_file
|
18
|
-
end
|
19
|
-
|
20
|
-
def file_path
|
21
|
-
File.join(File.dirname(__FILE__), 'files', 'en.yml')
|
22
|
-
end
|
23
|
-
|
24
|
-
def translations
|
25
|
-
{
|
26
|
-
en: {
|
27
|
-
article: {
|
28
|
-
title: 'One Article'
|
29
|
-
},
|
30
|
-
category: 'Category'
|
31
|
-
}
|
32
|
-
}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|