rails-i18nterface 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -11
- data/Rakefile +13 -2
- data/app/controllers/rails_i18nterface/translate_controller.rb +10 -24
- data/app/helpers/rails_i18nterface/translate_helper.rb +12 -19
- data/app/views/rails_i18nterface/translate/index.html.erb +91 -105
- data/config/initializers/missing_translation.rb +4 -2
- data/lib/rails-i18nterface.rb +1 -0
- data/lib/rails-i18nterface/cache.rb +3 -3
- data/lib/rails-i18nterface/keys.rb +21 -11
- data/lib/rails-i18nterface/sourcefiles.rb +38 -19
- data/lib/rails-i18nterface/translation.rb +34 -0
- data/lib/rails-i18nterface/utils.rb +13 -9
- data/lib/rails-i18nterface/version.rb +1 -1
- data/lib/rails-i18nterface/yamlfile.rb +1 -1
- data/spec/controllers/translate_controller_spec.rb +72 -51
- data/spec/internal/app/controllers/application_controller.rb +2 -1
- data/spec/internal/app/models/article.rb +1 -0
- data/spec/internal/db/schema.rb +2 -0
- data/spec/internal/log/test.log +0 -2370
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/0PMwId9157j93ZuEBNCPa71HO-BWiCNHuiZtCkqHovk.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/172YbT7Y9QCTtQpYWCn3GiUa1XYF30IZjymEsgPF2r4.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/1RE9Nc-99pz5dq3J_WTniU9ihuoYrOprEnGvyXAa5cY.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/1vT4QnCK-tMzI13mEL_FMuTrb5BgAdA3XBhVxNv4-r8.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/3V-PndZUHey8S35jzCvUM5n8ObasIDurRCq_RlH0jKo.cache +0 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/3l6G7l7GutWzjmS7bo548k2NQXCbu3FuG0RCqtNuUL8.cache +2 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/4vXT_Tqow4flv0JjTjeIZO4MHOerMmqrPSyHiyf3SYE.cache +2 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/7Ki489aXvXh1c80Q1MzMtZpbfnotMDd6A3yHY-HEecw.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/9kyHNOVXEDTe7kg34AKp3C9rb7GbxRKGQYV0smgM01I.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/DgOE4dVOvx7Kg6yuTxyUSupElQF47xWnXtMcz2TXBaw.cache +2 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/FZqMgA_zpqV7sBthUsaF-loYETVrVCEtlxczLF730GY.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/M-S52Jney4p15fjNRm25zSHatM5QqthKsrEU_Q7GTVA.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/PaP9vMCDQ63NoJWLaM8fSu0YeRy-eLKbArpgNOm8Z_4.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/UHhQ3Te4YSyiy1iqqTRt4nt2dyXqSXxkwAkjepufrsY.cache +2 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/VOKFuKrh87uBuA6qI4LzN8vVjP5mXjzL0j-iaq5sNNg.cache +2 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/Vjw0tPMcLKXFR62wwfemKkM4UCNkbPeERe-8KqFrez0.cache +0 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/YGEo5ly-YOZRgLRVZp1HmXC1FVjMcAWo8Pc006mVUEc.cache +0 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/_RHrJ0guSCf-x6bLKcowvNq4a-4N5p1m_5Abxsef-Zw.cache +0 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/bZt89CxopsDo8--1TGPUMLxKV-mDvRqFMTNNZOfnN08.cache +0 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/frFXg-urENHAZ5rXQ1GpQfRRjJu9Fp_-RvTvn9UugJc.cache +0 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/gaOEShTR6QyHBz9Pv5Ylz1vVWcNP7Dz2DRcuDIl52cs.cache +3 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/mr2V_uFvIXsHQ7VrC70TymoM9CO0RMKHzQgBkn3deHw.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/nbwa8EHOBiuE0pKOTtnWN0gAQOC27loObjVaVMX_wZE.cache +0 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/oQxOm6wUSyQ0jKnI8eKFRJLgEQ-dFvxofYtnbn-haqA.cache +1 -0
- data/spec/internal/tmp/cache/assets/test/sprockets/v3.0/v6huIOApjM-My2aA3RhSsO6U2my-O0Ht7A0lo0YKqPI.cache +2 -0
- data/spec/internal/tmp/translation_strings +2 -1
- data/spec/lib/cache_spec.rb +32 -29
- data/spec/lib/keys_spec.rb +77 -66
- data/spec/lib/sourcefiles_spec.rb +53 -50
- data/spec/lib/utils_spec.rb +55 -29
- data/spec/lib/yamlfile_spec.rb +2 -2
- data/spec/requests/search_spec.rb +4 -4
- data/spec/selenium/nav_spec.rb +23 -0
- data/spec/selenium/sauce.rb +68 -0
- data/spec/selenium/translation_spec.rb +19 -0
- data/spec/spec_helper.rb +19 -18
- metadata +225 -74
- data/app/helpers/rails_i18nterface/application_helper.rb +0 -6
- data/config/initializers/rails_i18nterface/missing_translation.rb +0 -13
- data/spec/internal/app/views/categories/category.erb +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
"%Hl��/H5mU�[��I K�s�~)�i����
|
@@ -0,0 +1 @@
|
|
1
|
+
"%��$eBzz�q�q��p: ��D�Iz�Q�t�%�
|
@@ -0,0 +1 @@
|
|
1
|
+
"% &�}ۺ5l��K,RAF,��U�m���hA�
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�/home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/application.js?type=application/javascript&id=ca3a7e749f47da8215a7af8a18b4a2f8ae3dd77dabe2c0d8d53fbd4efbbb7217:ET
|
Binary file
|
@@ -0,0 +1,2 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash{I"environment-version:ETTI"environment-paths;TTI"Lprocessors:type=application/javascript&file_type=application/javascript;TTI"pfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/application.js;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"jfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender.js;TTI"ifile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base.js;TTI";file-digest://app/assets/javascripts/rails_i18nterface;TTI"Afile-digest://app/assets/javascripts/rails_i18nterface/ender;TTI";file-digest://app/assets/stylesheets/rails_i18nterface;TTI"Afile-digest://app/assets/stylesheets/rails_i18nterface/ender;TTI"\file-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface;TTI"bfile-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface/ender;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface;TTI"gfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender;TTI"@file-digest://app/assets/javascripts/rails_i18nterface/base;TTI"@file-digest://app/assets/stylesheets/rails_i18nterface/base;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface/base;TTI"ffile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base;TT
|
@@ -0,0 +1,2 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash{I"environment-version:ETTI"environment-paths;TTI"0processors:type=text/css&file_type=text/css;TTI"qfile-digest:///home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface/application.css;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface;TT
|
@@ -0,0 +1 @@
|
|
1
|
+
"%��B�����șo�$'�A�d��L���xR�U
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�/home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base.js?type=application/javascript&pipeline=self&id=0e24e105e05d47978596535199ade26a05f6f721cd0e9bf76895824db8df0251:ET
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�/home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface/application.css?type=text/css&id=b6cba33efb2835dbb344633979db7cd0105fe0e6cf2d3e125a4eac2c0db2255e:ET
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�/home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender.js?type=application/javascript&pipeline=self&id=a9740c285b53359e30411a2ee1f51fb3bf188aff8eebacde8de233d02a3b7e2f:ET
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�/home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/application.js?type=application/javascript&pipeline=self&id=4e30a07808cb3134b85e36db6db8f1853e9acc7957aee14c53196bf9fe0860ba:ET
|
@@ -0,0 +1,2 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash{I"environment-version:ETTI"environment-paths;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"pfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/application.js;TTI";file-digest://app/assets/javascripts/rails_i18nterface;TTI"Afile-digest://app/assets/javascripts/rails_i18nterface/ender;TTI";file-digest://app/assets/stylesheets/rails_i18nterface;TTI"Afile-digest://app/assets/stylesheets/rails_i18nterface/ender;TTI"\file-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface;TTI"bfile-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface/ender;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface;TTI"gfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender;TTI"jfile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/ender.js;TTI"@file-digest://app/assets/javascripts/rails_i18nterface/base;TTI"@file-digest://app/assets/stylesheets/rails_i18nterface/base;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/images/rails_i18nterface/base;TTI"ffile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base;TTI"ifile-digest:///home/mose/projects/rails-i18nterface/app/assets/javascripts/rails_i18nterface/base.js;TT
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,3 @@
|
|
1
|
+
[o:Set:
|
2
|
+
@hash{
|
3
|
+
I"environment-version:ETTI"environment-paths;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI"qfile-digest:///home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface/application.css;TTI"afile-digest:///home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface;TT
|
@@ -0,0 +1 @@
|
|
1
|
+
"%��Rm�v�S3.��O�L���ڹc�ƕq�=_j�
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
I"�/home/mose/projects/rails-i18nterface/app/assets/stylesheets/rails_i18nterface/application.css?type=text/css&pipeline=self&id=a404df2f972b01180a1b326f0a9aeaebf33288a077ff894c4e7f5ec3c3ede9d6:ET
|
@@ -1 +1,2 @@
|
|
1
|
-
C:-ActiveSupport::HashWithIndifferentAccess{
|
1
|
+
C:-ActiveSupport::HashWithIndifferentAccess{I"
|
2
|
+
title:EF[I".app/controllers/application_controller.rb;FI"article.key1;F[I"app/models/article.rb;FI"article.key2;F[I"app/models/article.rb;FI"article.key3;F[I"app/models/article.rb;FI"article.key4.zero;F[I"app/models/article.rb;FI"article.key4.one;F[@I"article.key4.other;F[@I"article.key5;F[I"app/models/article.rb;FI"article.key6.zero;F[I"app/models/article.rb;FI"article.key6.one;F[@I"article.key6.other;F[@I"symbol_key;F[I"app/models/article.rb;FI"category_html_erb.key1;F[I"+app/views/categories/category.html.erb;FI"category_rhtml.key1;F[I"(app/views/categories/category.rhtml;FI"
|
data/spec/lib/cache_spec.rb
CHANGED
@@ -5,43 +5,46 @@ require 'spec_helper'
|
|
5
5
|
describe RailsI18nterface::Cache do
|
6
6
|
include RailsI18nterface::Cache
|
7
7
|
|
8
|
-
|
9
|
-
@cachefile = File.expand_path(File.join('..', 'files', 'cache_test'), __FILE__)
|
10
|
-
end
|
8
|
+
let(:cachefile) { File.expand_path(File.join('..', 'files', 'cache_test'), __FILE__) }
|
11
9
|
|
12
|
-
after
|
13
|
-
FileUtils.rm @cachefile if File.exists? @cachefile
|
14
|
-
end
|
10
|
+
after { FileUtils.rm cachefile if File.exists? cachefile }
|
15
11
|
|
16
|
-
|
17
|
-
a
|
18
|
-
cache_save a,
|
19
|
-
|
12
|
+
describe '.save' do
|
13
|
+
let(:a) { { a: 'a' } }
|
14
|
+
before { cache_save a, cachefile }
|
15
|
+
it 'stores cache of an object' do
|
16
|
+
expect(File.exists? cachefile).to be_truthy
|
17
|
+
end
|
20
18
|
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
describe '.load' do
|
21
|
+
context 'reads cache from marshalled file' do
|
22
|
+
let(:a) { { a: 'a' } }
|
23
|
+
let(:b) { cache_load cachefile }
|
24
|
+
before { cache_save a, cachefile }
|
25
|
+
it { expect(b).to eq a }
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
context 'when the cache if not present' do
|
29
|
+
before {
|
30
|
+
@b = cache_load cachefile do
|
31
|
+
20
|
32
|
+
end
|
33
|
+
}
|
34
|
+
it { expect(@b).to be 20 }
|
35
|
+
it { expect(File.exists? cachefile).to be_truthy }
|
32
36
|
end
|
33
|
-
File.exists?(@cachefile).should be_true
|
34
|
-
b.should == 20
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
context 'when the cache if not present, using an argument' do
|
39
|
+
before {
|
40
|
+
@b = cache_load cachefile, 'something' do |options|
|
41
|
+
options
|
42
|
+
end
|
43
|
+
}
|
44
|
+
it { expect(@b).to eq 'something' }
|
45
|
+
it { expect(File.exists? cachefile).to be_truthy }
|
40
46
|
end
|
41
|
-
File.exists?(@cachefile).should be_true
|
42
|
-
b.should == 'something'
|
43
47
|
end
|
44
48
|
|
45
49
|
|
46
|
-
|
47
|
-
end
|
50
|
+
end
|
data/spec/lib/keys_spec.rb
CHANGED
@@ -3,16 +3,13 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe RailsI18nterface::Keys do
|
6
|
-
|
7
6
|
include RailsI18nterface::Utils
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
@keys = RailsI18nterface::Keys.new(@root_dir, :sv, :no)
|
12
|
-
end
|
8
|
+
let(:root_dir) { File.expand_path(File.join('..', '..', '..', 'spec', 'internal'), __FILE__) }
|
9
|
+
let(:keys) { RailsI18nterface::Keys.new(root_dir, :sv, :no) }
|
13
10
|
|
14
|
-
|
15
|
-
|
11
|
+
describe '.files' do
|
12
|
+
let(:expected) { [
|
16
13
|
'activerecord.attributes.article.active',
|
17
14
|
'activerecord.attributes.article.body',
|
18
15
|
'activerecord.attributes.article.created_at',
|
@@ -33,86 +30,100 @@ describe RailsI18nterface::Keys do
|
|
33
30
|
'article.key6.one',
|
34
31
|
'article.key6.other',
|
35
32
|
'article.key6.zero',
|
36
|
-
'category_erb.key1',
|
37
33
|
'category_html_erb.key1',
|
38
34
|
'category_rhtml.key1',
|
39
|
-
'js.alert'
|
40
|
-
|
35
|
+
'js.alert',
|
36
|
+
'symbol_key',
|
37
|
+
'title'
|
38
|
+
] }
|
39
|
+
it 'extracts keys from I18n lookups in .rb, .html.erb, and .rhtml files' do
|
40
|
+
expect(keys.files.keys.sort).to eq expected
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "sorts by keys" do
|
45
|
+
#before { allow(keys).to receive(:lookup).with('en', 'article.key6.zero').and_return('xxx') }
|
46
|
+
it { expect(keys.sort_keys.last).to eq 'title' }
|
41
47
|
end
|
42
48
|
|
43
|
-
|
44
|
-
|
49
|
+
describe "sorts by translation" do
|
50
|
+
it { expect(keys.sort_keys('text').last).to eq 'time.pm' }
|
45
51
|
end
|
46
52
|
|
47
|
-
|
48
|
-
|
49
|
-
|
53
|
+
describe 'return a hash with I18n keys and file lists' do
|
54
|
+
it { expect(keys.files[:'article.key3']).to eq ['app/models/article.rb'] }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'reloads the translatable strings' do
|
58
|
+
let(:size) { keys.all_keys.size }
|
59
|
+
it { expect(keys.reload(root_dir).size).to be size }
|
50
60
|
end
|
51
61
|
|
52
62
|
describe 'i18n_keys' do
|
53
|
-
before
|
63
|
+
before do
|
54
64
|
I18n.backend.send(:init_translations) unless I18n.backend.initialized?
|
55
65
|
end
|
56
66
|
|
57
|
-
|
58
|
-
I18n.backend.
|
59
|
-
|
67
|
+
describe 'should return all keys in the I18n backend translations hash' do
|
68
|
+
before { allow(I18n.backend).to receive(:translations).and_return(translations) }
|
69
|
+
it { expect(keys.i18n_keys :en).to eq ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about'] }
|
60
70
|
end
|
61
71
|
|
62
72
|
describe 'untranslated_keys' do
|
63
|
-
|
64
|
-
|
65
|
-
|
73
|
+
let(:expected) {
|
74
|
+
{
|
75
|
+
sv: ['articles.new.page_title', 'categories.flash.created', 'empty'],
|
76
|
+
no: ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
|
77
|
+
}
|
78
|
+
}
|
79
|
+
before { allow(I18n.backend).to receive(:translations).and_return(translations) }
|
66
80
|
|
67
81
|
it 'should return a hash with keys with missing translations in each locale' do
|
68
|
-
|
69
|
-
:sv => ['articles.new.page_title', 'categories.flash.created', 'empty'],
|
70
|
-
:no => ['articles.new.page_title', 'categories.flash.created', 'empty', 'home.about']
|
71
|
-
}
|
82
|
+
expect(keys.untranslated_keys).to eq expected
|
72
83
|
end
|
73
84
|
end
|
74
85
|
|
75
86
|
describe 'missing_keys' do
|
76
|
-
|
77
|
-
|
78
|
-
yaml = RailsI18nterface::Yamlfile.new(
|
87
|
+
let(:file_path) { File.join(root_dir, 'config', 'locales', 'en.yml') }
|
88
|
+
before do
|
89
|
+
yaml = RailsI18nterface::Yamlfile.new(root_dir, :en)
|
79
90
|
yaml.write({
|
80
|
-
:
|
81
|
-
:
|
82
|
-
:
|
83
|
-
:
|
84
|
-
:
|
85
|
-
:
|
91
|
+
en: {
|
92
|
+
home: {
|
93
|
+
page_title: false,
|
94
|
+
intro: {
|
95
|
+
one: 'intro one',
|
96
|
+
other: 'intro other'
|
86
97
|
}
|
87
98
|
}
|
88
99
|
}
|
89
100
|
})
|
101
|
+
allow(keys).to receive(:files).and_return({
|
102
|
+
:'home.page_title' => 'app/views/home/index.rhtml',
|
103
|
+
:'home.intro' => 'app/views/home/index.rhtml',
|
104
|
+
:'home.signup' => 'app/views/home/_signup.rhtml',
|
105
|
+
:'about.index.page_title' => 'app/views/about/index.rhtml'
|
106
|
+
})
|
90
107
|
end
|
91
108
|
|
92
109
|
after(:each) do
|
93
|
-
FileUtils.rm(
|
110
|
+
FileUtils.rm(file_path) if File.exists? file_path
|
94
111
|
end
|
95
112
|
|
96
113
|
it 'should return a hash with keys that are not in the locale file' do
|
97
|
-
|
98
|
-
:'home.page_title' => 'app/views/home/index.rhtml',
|
99
|
-
:'home.intro' => 'app/views/home/index.rhtml',
|
100
|
-
:'home.signup' => 'app/views/home/_signup.rhtml',
|
101
|
-
:'about.index.page_title' => 'app/views/about/index.rhtml'
|
102
|
-
})
|
103
|
-
@keys.missing_keys.size.should == 24
|
114
|
+
expect(keys.missing_keys.sort[0]).to eq "activerecord.attributes.article.active"
|
104
115
|
end
|
105
116
|
end
|
106
117
|
|
107
118
|
|
108
119
|
describe 'translated_locales' do
|
109
|
-
before
|
110
|
-
I18n.
|
111
|
-
I18n.
|
120
|
+
before do
|
121
|
+
allow(I18n).to receive(:default_locale).and_return(:en)
|
122
|
+
allow(I18n).to receive(:available_locales).and_return([:sv, :no, :en, :root])
|
112
123
|
end
|
113
124
|
|
114
125
|
it 'returns all avaiable except :root and the default' do
|
115
|
-
RailsI18nterface::Keys.translated_locales.
|
126
|
+
expect(RailsI18nterface::Keys.translated_locales).to eq [:sv, :no]
|
116
127
|
end
|
117
128
|
end
|
118
129
|
|
@@ -125,25 +136,25 @@ describe RailsI18nterface::Keys do
|
|
125
136
|
|
126
137
|
def translations
|
127
138
|
{
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
139
|
+
en: {
|
140
|
+
home: {
|
141
|
+
about: 'This site is about making money'
|
131
142
|
},
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
143
|
+
articles: {
|
144
|
+
new: {
|
145
|
+
page_title: 'New Article'
|
135
146
|
}
|
136
147
|
},
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
148
|
+
categories: {
|
149
|
+
flash: {
|
150
|
+
created: 'Category created'
|
140
151
|
}
|
141
152
|
},
|
142
|
-
:
|
153
|
+
empty: nil
|
143
154
|
},
|
144
|
-
:
|
145
|
-
:
|
146
|
-
:
|
155
|
+
sv: {
|
156
|
+
home: {
|
157
|
+
about: false
|
147
158
|
}
|
148
159
|
}
|
149
160
|
}
|
@@ -161,14 +172,14 @@ describe RailsI18nterface::Keys do
|
|
161
172
|
|
162
173
|
def deep_hash
|
163
174
|
{
|
164
|
-
:
|
165
|
-
:
|
166
|
-
:
|
167
|
-
:
|
175
|
+
pressrelease: {
|
176
|
+
label: {
|
177
|
+
one: 'Pressmeddelande',
|
178
|
+
other: 'Pressmeddelanden'
|
168
179
|
}
|
169
180
|
},
|
170
|
-
:
|
171
|
-
:
|
181
|
+
article: 'Artikel',
|
182
|
+
category: ''
|
172
183
|
}
|
173
184
|
end
|
174
185
|
|
@@ -4,70 +4,73 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe RailsI18nterface::Sourcefiles do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
@cache_file = File.join(@root_dir, 'tmp', 'translation_strings')
|
10
|
-
FileUtils.rm @cache_file if File.exists? @cache_file
|
11
|
-
end
|
7
|
+
let(:root_dir) { File.expand_path(File.join('..', '..', '..', 'spec', 'internal'), __FILE__) }
|
8
|
+
let(:cache_file) { File.join(root_dir, 'tmp', 'translation_strings') }
|
12
9
|
|
13
|
-
|
14
|
-
expected = {
|
15
|
-
'activerecord.models.article'=>['db/schema.rb'],
|
16
|
-
'activerecord.attributes.article.title'=>['db/schema.rb'],
|
17
|
-
'activerecord.attributes.article.body'=>['db/schema.rb'],
|
18
|
-
'activerecord.attributes.article.created_at'=>['db/schema.rb'],
|
19
|
-
'activerecord.attributes.article.updated_at'=>['db/schema.rb'],
|
20
|
-
'activerecord.attributes.article.active'=>['db/schema.rb'],
|
21
|
-
'activerecord.models.topic'=>['db/schema.rb'],
|
22
|
-
'activerecord.attributes.topic.title'=>['db/schema.rb'],
|
23
|
-
'activerecord.attributes.topic.created_at'=>['db/schema.rb'],
|
24
|
-
'activerecord.attributes.topic.updated_at'=>['db/schema.rb']
|
25
|
-
}
|
26
|
-
hash = RailsI18nterface::Sourcefiles.extract_activerecords(@root_dir)
|
27
|
-
hash.should == expected
|
28
|
-
end
|
10
|
+
after { FileUtils.rm cache_file if File.exists? cache_file}
|
29
11
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
12
|
+
describe '.hash' do
|
13
|
+
let(:expected) { {
|
14
|
+
'activerecord.models.article' => ['db/schema.rb'],
|
15
|
+
'activerecord.attributes.article.title' => ['db/schema.rb'],
|
16
|
+
'activerecord.attributes.article.body' => ['db/schema.rb'],
|
17
|
+
'activerecord.attributes.article.created_at' => ['db/schema.rb'],
|
18
|
+
'activerecord.attributes.article.updated_at' => ['db/schema.rb'],
|
19
|
+
'activerecord.attributes.article.active' => ['db/schema.rb'],
|
20
|
+
'activerecord.models.topic' => ['db/schema.rb'],
|
21
|
+
'activerecord.attributes.topic.title' => ['db/schema.rb'],
|
22
|
+
'activerecord.attributes.topic.created_at' => ['db/schema.rb'],
|
23
|
+
'activerecord.attributes.topic.updated_at' => ['db/schema.rb']
|
24
|
+
} }
|
25
|
+
let(:hash) { RailsI18nterface::Sourcefiles.extract_activerecords(root_dir) }
|
26
|
+
it 'grabs field from schema.rb' do
|
27
|
+
expect(hash).to eq expected
|
28
|
+
end
|
34
29
|
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
keys[:"article.key4.other"].should == ["app/models/article.rb"]
|
31
|
+
describe '.allfiles' do
|
32
|
+
before { @allfiles = RailsI18nterface::Sourcefiles.load_files(root_dir) }
|
33
|
+
it 'extracts translatable string from code source' do
|
34
|
+
expect(File.exists? cache_file).to be_truthy
|
35
|
+
expect(@allfiles['title']).to eq ['app/controllers/application_controller.rb']
|
36
|
+
end
|
43
37
|
end
|
44
38
|
|
45
|
-
|
46
|
-
file
|
47
|
-
keys
|
48
|
-
|
49
|
-
|
50
|
-
|
39
|
+
describe '.keys' do
|
40
|
+
let(:file) { File.join(root_dir, 'app/models/article.rb') }
|
41
|
+
let(:keys) { RailsI18nterface::Sourcefiles.populate_keys(root_dir, file) }
|
42
|
+
it 'populates from plural form when a :count is passed as param' do
|
43
|
+
expect(keys[:'article.key3.zero']).to be_nil
|
44
|
+
expect(keys[:'article.key4.zero']).to eq ['app/models/article.rb']
|
45
|
+
expect(keys[:'article.key4.one']).to eq ['app/models/article.rb']
|
46
|
+
expect(keys[:'article.key4.other']).to eq ['app/models/article.rb']
|
47
|
+
end
|
48
|
+
it 'populates from plural form when a :count => is passed as param' do
|
49
|
+
expect(keys[:'article.key6.zero']).to eq ['app/models/article.rb']
|
50
|
+
expect(keys[:'article.key6.one']).to eq ['app/models/article.rb']
|
51
|
+
expect(keys[:'article.key6.other']).to eq ['app/models/article.rb']
|
52
|
+
end
|
51
53
|
end
|
52
54
|
|
53
55
|
describe 'refreshing' do
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
let(:testfile) { File.join(root_dir, 'app', 'views', 'test.html.erb') }
|
57
|
+
|
58
|
+
before do
|
59
|
+
RailsI18nterface::Sourcefiles.load_files(root_dir)
|
60
|
+
File.open(File.join(root_dir, 'app', 'views', 'test.html.erb'),'w') do |f|
|
61
|
+
f.puts "<%= t('something') %>"
|
62
|
+
end
|
63
|
+
@allfiles = RailsI18nterface::Sourcefiles.refresh(root_dir)
|
57
64
|
end
|
58
65
|
|
59
|
-
after
|
60
|
-
FileUtils.rm
|
61
|
-
FileUtils.rm
|
66
|
+
after do
|
67
|
+
FileUtils.rm testfile if File.exists? testfile
|
68
|
+
FileUtils.rm cache_file if File.exists? cache_file
|
62
69
|
end
|
63
70
|
|
64
71
|
it 'refreshes translatable strings cache' do
|
65
|
-
|
66
|
-
f.puts "<%= t('something') %>"
|
67
|
-
end
|
68
|
-
y = RailsI18nterface::Sourcefiles.refresh(@root_dir)
|
69
|
-
y.size.should == 25
|
72
|
+
expect(@allfiles['something']).to eq ['app/views/test.html.erb']
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
73
|
-
end
|
76
|
+
end
|