vocab 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +58 -0
- data/Rakefile +13 -0
- data/bin/vocab +11 -0
- data/lib/vocab/application.rb +58 -0
- data/lib/vocab/extractor/android.rb +56 -0
- data/lib/vocab/extractor/base.rb +92 -0
- data/lib/vocab/extractor/rails.rb +81 -0
- data/lib/vocab/extractor.rb +7 -0
- data/lib/vocab/merger/android.rb +59 -0
- data/lib/vocab/merger/base.rb +21 -0
- data/lib/vocab/merger/rails.rb +105 -0
- data/lib/vocab/merger.rb +7 -0
- data/lib/vocab/settings.rb +35 -0
- data/lib/vocab/translator/android.rb +43 -0
- data/lib/vocab/translator/base.rb +12 -0
- data/lib/vocab/translator/rails.rb +67 -0
- data/lib/vocab/translator.rb +7 -0
- data/lib/vocab/ui.rb +19 -0
- data/lib/vocab/validator/android.rb +23 -0
- data/lib/vocab/validator/base.rb +40 -0
- data/lib/vocab/validator/rails.rb +31 -0
- data/lib/vocab/validator.rb +7 -0
- data/lib/vocab/version.rb +3 -0
- data/lib/vocab.rb +36 -0
- data/spec/application_spec.rb +20 -0
- data/spec/data/android/current.xml +8 -0
- data/spec/data/android/locales/values/strings.xml +10 -0
- data/spec/data/android/locales/values-es/strings.xml +6 -0
- data/spec/data/android/locales/values-large-hdpi/dimens.xml +1 -0
- data/spec/data/android/locales/values-large-hdpi/styles.xml +1 -0
- data/spec/data/android/previous.xml +6 -0
- data/spec/data/android/translations/values-es/es-string-file.xml +7 -0
- data/spec/data/android/write.xml +6 -0
- data/spec/data/rails/locales/en.yml +10 -0
- data/spec/data/rails/locales/es.yml +6 -0
- data/spec/data/rails/locales/models/product/en.yml +13 -0
- data/spec/data/rails/locales/models/product/es.yml +13 -0
- data/spec/data/rails/translations/cn.yml +21 -0
- data/spec/data/rails/translations/es.yml +12 -0
- data/spec/extractor/android_spec.rb +95 -0
- data/spec/extractor/base_spec.rb +134 -0
- data/spec/extractor/rails_spec.rb +116 -0
- data/spec/merger/android_spec.rb +138 -0
- data/spec/merger/base_spec.rb +24 -0
- data/spec/merger/rails_spec.rb +183 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/matchers.rb +13 -0
- data/spec/support/shared.rb +6 -0
- data/spec/tmp/.gitkeep +0 -0
- data/spec/translator/android_spec.rb +24 -0
- data/spec/translator/rails_spec.rb +155 -0
- data/spec/ui_spec.rb +15 -0
- data/spec/validator/android_spec.rb +54 -0
- data/spec/validator/base_spec.rb +5 -0
- data/spec/validator/rails_spec.rb +83 -0
- data/spec/vocab_spec.rb +13 -0
- data/vocab.gemspec +25 -0
- metadata +171 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Vocab::Extractor::Rails" do
|
4
|
+
|
5
|
+
describe 'write_full' do
|
6
|
+
|
7
|
+
it 'writes the full en translation to a file' do
|
8
|
+
translation = { :en => { :full => 'translation' } }
|
9
|
+
path = "#{vocab_root}/spec/tmp/en.full.yml"
|
10
|
+
Vocab::Extractor::Rails.write_full( translation, path )
|
11
|
+
YAML.load_file( path ).should eql( translation )
|
12
|
+
File.delete( path )
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'hasherize' do
|
18
|
+
|
19
|
+
it 'writes the diff in standard rails locale yaml format' do
|
20
|
+
flattened = { :"en.video_mail.kid.approve" => "To let %{kid} start sending video mail",
|
21
|
+
:"en.models.subject.id_125.name" => "Recording Data Stuff" }
|
22
|
+
hash = Vocab::Extractor::Rails.hasherize( flattened )
|
23
|
+
expected = { :en=> { :models => { :subject => { :id_125=> { :name => "Recording Data Stuff" } } },
|
24
|
+
:video_mail=> { :kid=>{ :approve=>"To let %{kid} start sending video mail" } } } }
|
25
|
+
hash.should == expected
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "previous" do
|
31
|
+
|
32
|
+
before( :each ) do
|
33
|
+
@last_translation = '5ab8cf4d081d7ba1d5f020118dd00c3ea2d0437a'
|
34
|
+
@locales_root = "spec/data/rails/locales"
|
35
|
+
Vocab.settings.stub!( :last_translation ).and_return( @last_translation )
|
36
|
+
Dir.chdir( vocab_root )
|
37
|
+
end
|
38
|
+
|
39
|
+
it "creates a hash of the english translation strings from the last translation" do
|
40
|
+
actual = Vocab::Extractor::Rails.extract_previous( @locales_root )
|
41
|
+
expected = { :"en.models.product.id_36.description" =>"Polarized and lazer resistant",
|
42
|
+
:"en.marketing.banner" =>"This product is so good",
|
43
|
+
:"en.models.product.id_36.name" =>"This nested value has changed",
|
44
|
+
:"en.menu.first" =>"First menu item",
|
45
|
+
:"en.models.product.id_55.description" =>"A new nested description",
|
46
|
+
:"en.models.product.id_125.description"=>"Green with megawatts",
|
47
|
+
:"en.dashboard.chart" =>"This value has changed",
|
48
|
+
:"en.models.product.id_55.name" =>"a new nested name",
|
49
|
+
:"en.models.product.id_125.name" =>"Lazer",
|
50
|
+
:"en.dashboard.details" =>"This key/value has been added" }
|
51
|
+
actual.should eql( expected )
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'creates a tmp folder if one does not exist' do
|
55
|
+
dir = "#{vocab_root}/tmp/last_translation"
|
56
|
+
FileUtils.rm_rf( "#{vocab_root}/tmp/last_translation" )
|
57
|
+
Vocab::Extractor::Rails.extract_previous( @locales_root )
|
58
|
+
File.exists?( dir ).should be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "current" do
|
64
|
+
|
65
|
+
before( :each ) do
|
66
|
+
Dir.chdir( vocab_root )
|
67
|
+
@locales_root = "spec/data/rails/locales"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "creates a hash of the english translation strings currently in the config" do
|
71
|
+
actual = Vocab::Extractor::Rails.extract_current( @locales_root )
|
72
|
+
expected = { :"en.menu.second" =>"Second menu item",
|
73
|
+
:"en.models.product.id_36.description" =>"Polarized and lazer resistant",
|
74
|
+
:"en.marketing.banner" =>"This product is so good",
|
75
|
+
:"en.models.product.id_36.name" =>"This nested value has changed",
|
76
|
+
:"en.menu.first" =>"First menu item",
|
77
|
+
:"en.models.product.id_55.description" =>"A new nested description",
|
78
|
+
:"en.models.product.id_125.description"=>"Green with megawatts",
|
79
|
+
:"en.dashboard.chart" =>"This value has changed",
|
80
|
+
:"en.models.product.id_55.name" =>"a new nested name",
|
81
|
+
:"en.models.product.id_125.name" =>"Lazer",
|
82
|
+
:"en.dashboard.details" =>"This key/value has been added",
|
83
|
+
:"en.not_in_es" =>"This key not in spanish" }
|
84
|
+
actual.should eql( expected )
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "extract" do
|
90
|
+
|
91
|
+
before( :each ) do
|
92
|
+
@diff_path = "#{vocab_root}/spec/tmp/en.yml"
|
93
|
+
@full_path = "#{vocab_root}/spec/tmp/en.full.yml"
|
94
|
+
end
|
95
|
+
|
96
|
+
it "extracts the strings that need to be translated into a yml file" do
|
97
|
+
Vocab::Extractor::Rails.should_receive( :extract_current ).and_return( { :en => { 1 => 5, 3 => 4 } } )
|
98
|
+
Vocab::Extractor::Rails.should_receive( :extract_previous ).and_return( { :en => { 1 => 2 } } )
|
99
|
+
Vocab::Extractor::Rails.extract( @diff_path, @full_path )
|
100
|
+
YAML.load_file( @diff_path ).should == { :en => { 1 => 5, 3 => 4 } }
|
101
|
+
|
102
|
+
File.delete( @diff_path ) if File.exists?( @diff_path )
|
103
|
+
File.delete( @full_path ) if File.exists?( @full_path )
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "examples" do
|
109
|
+
|
110
|
+
it 'returns the directory to put the yml files' do
|
111
|
+
Vocab::Extractor::Rails.examples.should eql( [ "#{vocab_root}/tmp/translations" ] )
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe "Vocab::Merger::Android" do
|
6
|
+
|
7
|
+
before( :each ) do
|
8
|
+
@update_dir = "#{vocab_root}/spec/data/android/translations"
|
9
|
+
@merge_dir = clear_merge_dir
|
10
|
+
FileUtils.cp_r( "#{vocab_root}/spec/data/android/locales/.", @merge_dir )
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'defaults to reasonable android paths' do
|
14
|
+
merger = Vocab::Merger::Android.new
|
15
|
+
merger.locales_dir.should eql( 'res' )
|
16
|
+
merger.updates_dir.should eql( 'tmp/translations' )
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'allows custom android paths' do
|
20
|
+
locales_dir = 'custom/locales/dir'
|
21
|
+
updates_dir = 'custom/updates/dir'
|
22
|
+
merger = Vocab::Merger::Android.new( locales_dir, updates_dir )
|
23
|
+
merger.locales_dir.should eql( locales_dir )
|
24
|
+
merger.updates_dir.should eql( updates_dir )
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "merge" do
|
28
|
+
|
29
|
+
before( :each ) do
|
30
|
+
Vocab.settings.should_receive( :update_translation )
|
31
|
+
@merger = Vocab::Merger::Android.new( @merge_dir, @update_dir )
|
32
|
+
@merger.merge
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'merges non-english translations' do
|
36
|
+
@merged = Vocab::Translator::Android.hash_from_xml( "#{@merge_dir}/values-es/strings.xml" )
|
37
|
+
@merged['app_name'].should eql( 'Modo Niños' )
|
38
|
+
@merged['pd_app_name'].should eql( 'el Panel para padres bien' )
|
39
|
+
@merged['delete'].should eql( "La función Child Lock" )
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'merge_file' do
|
45
|
+
|
46
|
+
before( :each ) do
|
47
|
+
@file = "#{@merge_dir}/values-es/strings.xml"
|
48
|
+
@merger = Vocab::Merger::Android.new( @merge_dir, @update_dir )
|
49
|
+
@merger.merge_file( @file )
|
50
|
+
@merged = Vocab::Translator::Android.hash_from_xml( @file )
|
51
|
+
end
|
52
|
+
|
53
|
+
it "merges updated android translations" do
|
54
|
+
@merged['pd_app_name'].should eql( 'el Panel para padres bien' )
|
55
|
+
end
|
56
|
+
|
57
|
+
it "integrates new android translations" do
|
58
|
+
@merged['cancel'].should eql( 'Cancelar' )
|
59
|
+
end
|
60
|
+
|
61
|
+
it "properly encodes html entities" do
|
62
|
+
@merged['delete'].should eql( "La función Child Lock" )
|
63
|
+
end
|
64
|
+
|
65
|
+
it "ignores key accidentally introduced by the translators into android translations" do
|
66
|
+
@merged['translator_cruft'].should be( nil )
|
67
|
+
end
|
68
|
+
|
69
|
+
it "retains unchanged android translations" do
|
70
|
+
@merged['app_name'].should eql( 'Modo Niños' )
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not include keys where there is no translation' do
|
74
|
+
@merged['not_in_es'].should be( nil )
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'english_keys' do
|
80
|
+
|
81
|
+
it 'fetches the english keys' do
|
82
|
+
merger = Vocab::Merger::Android.new( @merge_dir )
|
83
|
+
keys = ["app_name", "delete", "cancel", "app_current", "not_in_es", "pd_app_name"]
|
84
|
+
merger.english_keys.should =~ keys
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'current_for_locale' do
|
90
|
+
|
91
|
+
it 'returns hash of the current translations that match a locale file' do
|
92
|
+
merger = Vocab::Merger::Android.new( @merge_dir )
|
93
|
+
expected = { "app_name" =>"Modo Niños",
|
94
|
+
"app_current"=>"actual",
|
95
|
+
"pd_app_name"=>"el Panel para padres"}
|
96
|
+
merger.current_for_locale( "#{@merge_dir}/values-es/strings.xml" ).should == expected
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'updates' do
|
102
|
+
|
103
|
+
it 'returns hash of the updates that match a locale file' do
|
104
|
+
merger = Vocab::Merger::Android.new( @merge_dir, @update_dir )
|
105
|
+
expected = { 'cancel' => 'Cancelar',
|
106
|
+
'delete' => "La función Child Lock",
|
107
|
+
'pd_app_name' => 'el Panel para padres bien',
|
108
|
+
'translator_cruft' => 'Malo' }
|
109
|
+
merger.updates_for_locale( "#{@merge_dir}/values-es/strings.xml" ).should == expected
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'translation_locales' do
|
115
|
+
|
116
|
+
it 'returns the locales in the android updates directory' do
|
117
|
+
merger = Vocab::Merger::Android.new( @merge_dir, @update_dir )
|
118
|
+
locales = [ 'es' ]
|
119
|
+
Vocab::Translator::Android.should_receive( :locales ).with( @update_dir, false ).and_return( locales )
|
120
|
+
merger.translation_locales.should eql( locales )
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'files_to_merge' do
|
126
|
+
|
127
|
+
before ( :each ) do
|
128
|
+
@merger = Vocab::Merger::Android.new( @merge_dir, @update_dir )
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'returns an array of files for translation' do
|
132
|
+
expected = ["#{@merge_dir}/values-es/strings.xml"]
|
133
|
+
@merger.files_to_merge.sort.should eql( expected )
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Vocab::Extractor::Base" do
|
4
|
+
|
5
|
+
describe 'merge' do
|
6
|
+
|
7
|
+
before( :each ) do
|
8
|
+
@merger = Vocab::Merger::Base.new
|
9
|
+
@merger.should_receive( :update_settings )
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'merges a list of files' do
|
13
|
+
files = [ 'es.yml', 'zh.yml' ]
|
14
|
+
@merger.should_receive( :files_to_merge ).and_return( files )
|
15
|
+
files.each do |file|
|
16
|
+
@merger.should_receive( :merge_file ).with( file )
|
17
|
+
Vocab.ui.should_receive( :say ).with( "Merging file: #{file}" )
|
18
|
+
end
|
19
|
+
@merger.merge
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
describe "Vocab::Merger::Rails" do
|
7
|
+
|
8
|
+
def init_merge_dir
|
9
|
+
@merge_dir = clear_merge_dir
|
10
|
+
FileUtils.cp_r( "#{vocab_root}/spec/data/rails/locales/.", @merge_dir )
|
11
|
+
return @merge_dir
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'defaults to reasonable paths' do
|
15
|
+
merger = Vocab::Merger::Rails.new
|
16
|
+
merger.locales_dir.should eql( 'config/locales' )
|
17
|
+
merger.updates_dir.should eql( 'tmp/translations' )
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'allows custom paths' do
|
21
|
+
locales_dir = 'custom/locales/dir'
|
22
|
+
updates_dir = 'custom/updates/dir'
|
23
|
+
merger = Vocab::Merger::Rails.new( locales_dir, updates_dir )
|
24
|
+
merger.locales_dir.should eql( locales_dir )
|
25
|
+
merger.updates_dir.should eql( updates_dir )
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "merge_file" do
|
29
|
+
|
30
|
+
before( :each ) do
|
31
|
+
init_merge_dir
|
32
|
+
@file = "#{@merge_dir}/es.yml"
|
33
|
+
@update_dir = "#{vocab_root}/spec/data/rails/translations"
|
34
|
+
|
35
|
+
@merger = Vocab::Merger::Rails.new( @merge_dir, @update_dir )
|
36
|
+
@merger.merge_file( @file )
|
37
|
+
@merged = YAML.load_file( @file )
|
38
|
+
end
|
39
|
+
|
40
|
+
it "merges updated translations" do
|
41
|
+
@merged[:es][:marketing][:banner].should eql( 'hola mi amigo' )
|
42
|
+
end
|
43
|
+
|
44
|
+
it "ignores key accidentally introduced by the translators" do
|
45
|
+
@merged[:es][:translator_cruft].should be( nil )
|
46
|
+
end
|
47
|
+
|
48
|
+
it "retains unchanged translations" do
|
49
|
+
@merged[:es][:dashboard][:chart].should eql( 'Es muy bonita' )
|
50
|
+
end
|
51
|
+
|
52
|
+
it "does not include translations from nested files" do
|
53
|
+
@merged[:es][:models].should eql( nil )
|
54
|
+
end
|
55
|
+
|
56
|
+
it "does not include translations from other languages" do
|
57
|
+
@merged[:es][:marketing][:banner].should_not eql( '這改變了營銷信息' )
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'does not include keys where there is no translation in yml' do
|
61
|
+
@merged[:es].keys.should_not include( :not_in_es )
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "create_file" do
|
67
|
+
|
68
|
+
before( :each ) do
|
69
|
+
init_merge_dir
|
70
|
+
@file = "#{@merge_dir}/cn.yml"
|
71
|
+
@update_dir = "#{vocab_root}/spec/data/rails/translations"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "creates a file for missing translations" do
|
75
|
+
File.exists?( @file ).should be_false
|
76
|
+
@merger = Vocab::Merger::Rails.new( @merge_dir, @update_dir )
|
77
|
+
@merger.merge_file( @file )
|
78
|
+
File.exists?( @file ).should be_true
|
79
|
+
|
80
|
+
@merged = YAML.load_file( @file )
|
81
|
+
@merged[:cn][:marketing][:banner].should eql( '這改變了營銷信息' )
|
82
|
+
@merged[:cn][:translator_cruft].should eql( nil )
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "merge" do
|
88
|
+
|
89
|
+
before( :each ) do
|
90
|
+
init_merge_dir
|
91
|
+
@update_dir = "#{vocab_root}/spec/data/rails/translations"
|
92
|
+
Vocab.settings.should_receive( :update_translation )
|
93
|
+
@merger = Vocab::Merger::Rails.new( @merge_dir, @update_dir )
|
94
|
+
@merger.merge
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'merges nested files' do
|
98
|
+
@merged = YAML.load_file( "#{@merge_dir}/models/product/es.yml" )
|
99
|
+
@merged[:es][:models][:product][:id_125][:description].should eql( 'mucho Verde' )
|
100
|
+
@merged[:es][:models][:product][:id_125][:name].should eql( 'mucho Lazero' )
|
101
|
+
@merged[:es][:models][:product][:id_55][:description].should eql( 'Azul' )
|
102
|
+
@merged[:es][:models][:product][:id_55][:name].should eql( 'Muy bonita' )
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'merges non-english translations' do
|
106
|
+
@merged = YAML.load_file( "#{@merge_dir}/es.yml" )
|
107
|
+
@merged[:es][:marketing][:banner].should eql( 'hola mi amigo' )
|
108
|
+
@merged[:es][:dashboard][:chart].should eql( 'Es muy bonita' )
|
109
|
+
@merged[:es][:menu][:first].should eql( 'Uno' )
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "keys_for_file" do
|
115
|
+
|
116
|
+
it "returns the keys that should be in a file" do
|
117
|
+
path = "#{vocab_root}/spec/data/rails/locales/es.yml"
|
118
|
+
actual = Vocab::Merger::Rails.keys_for_file( path )
|
119
|
+
expected = [:"dashboard.details", :"menu.first", :"dashboard.chart", :"menu.second", :"marketing.banner", :"not_in_es"]
|
120
|
+
actual.each { |key| expected.should include( key ) }
|
121
|
+
actual.size.should eql( expected.size )
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "translatable?" do
|
127
|
+
|
128
|
+
before( :each ) do
|
129
|
+
@merger = Vocab::Merger::Rails.new
|
130
|
+
end
|
131
|
+
|
132
|
+
it "doesn't translate english files because that should be the reference language anyway" do
|
133
|
+
@merger.translatable?( "#{vocab_root}/spec/data/rails/locales/es.yml" ).should be_true
|
134
|
+
@merger.translatable?( "#{vocab_root}/spec/data/rails/locales/en.yml" ).should be_false
|
135
|
+
end
|
136
|
+
|
137
|
+
it "ignores files that don't have matching filename and contents" do
|
138
|
+
spanish_file = "#{vocab_root}/spec/tmp/es.yml"
|
139
|
+
english_file = Vocab::Translator::Rails.en_equivalent_path( spanish_file )
|
140
|
+
english_contents = { :en => { :english => 'stuff here' } }
|
141
|
+
File.open( spanish_file, 'w+' ) { |file| file.write( english_contents.to_yaml ) }
|
142
|
+
File.open( english_file, 'w+' ) { |file| file.write( english_contents.to_yaml ) }
|
143
|
+
Vocab.ui.should_receive( :warn ).with( "File extension does not match file contents in #{spanish_file}" )
|
144
|
+
@merger.translatable?( spanish_file ).should be_false
|
145
|
+
File.delete( spanish_file ) if File.exists?( spanish_file )
|
146
|
+
File.delete( english_file ) if File.exists?( english_file )
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'translation_locales' do
|
152
|
+
|
153
|
+
before ( :each ) do
|
154
|
+
@updates_dir = "#{vocab_root}/spec/data/rails/translations"
|
155
|
+
@merger = Vocab::Merger::Rails.new
|
156
|
+
@merger.updates_dir = @updates_dir
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'returns a list of locales in the translations' do
|
160
|
+
@merger.translation_locales.sort.should eql( [ 'cn', 'es' ] )
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
describe 'files_to_merge' do
|
166
|
+
|
167
|
+
before ( :each ) do
|
168
|
+
@locales_dir = "#{vocab_root}/spec/data/rails/locales"
|
169
|
+
@updates_dir = "#{vocab_root}/spec/data/rails/translations"
|
170
|
+
@merger = Vocab::Merger::Rails.new( @locales_dir, @updates_dir )
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'returns an array of files for translation' do
|
174
|
+
expected = ["#{@locales_dir}/cn.yml",
|
175
|
+
"#{@locales_dir}/es.yml",
|
176
|
+
"#{@locales_dir}/models/product/cn.yml",
|
177
|
+
"#{@locales_dir}/models/product/es.yml"]
|
178
|
+
@merger.files_to_merge.sort.should eql( expected )
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require "rspec"
|
5
|
+
require "vocab"
|
6
|
+
require "support/matchers"
|
7
|
+
require "support/shared"
|
8
|
+
|
9
|
+
Vocab.ui.silent = true
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.include Vocab::Spec::Matchers
|
13
|
+
end
|
14
|
+
|
15
|
+
def vocab_root
|
16
|
+
return File.expand_path( '../..', __FILE__ )
|
17
|
+
end
|
18
|
+
|
19
|
+
def should_eql_file( actual, path )
|
20
|
+
@tmp = File.open( "#{vocab_root}/#{path}.tmp","wb") { |io| io.write actual }
|
21
|
+
@expected = File.open("#{vocab_root}/#{path}","rb") {|io| io.read }
|
22
|
+
actual.chomp.strip.should eql( @expected.chomp.strip )
|
23
|
+
end
|
data/spec/tmp/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe 'Vocab::Translator::Android' do
|
4
|
+
|
5
|
+
describe 'english_keys' do
|
6
|
+
|
7
|
+
it 'returns the english keys for a locales dir' do
|
8
|
+
locales_dir = "#{vocab_root}/spec/data/android/locales"
|
9
|
+
expected = ["app_name", "delete", "cancel", "app_current", "not_in_es", "pd_app_name"]
|
10
|
+
Vocab::Translator::Android.english_keys( locales_dir ).should =~ expected
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'locales' do
|
16
|
+
|
17
|
+
it 'returns the locales in the android updates directory' do
|
18
|
+
dir = "#{vocab_root}/spec/data/android/translations"
|
19
|
+
Vocab::Translator::Android.locales( dir, false ).should eql( [ 'es' ] )
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|