vocab 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +4 -0
  3. data/README.md +58 -0
  4. data/Rakefile +13 -0
  5. data/bin/vocab +11 -0
  6. data/lib/vocab/application.rb +58 -0
  7. data/lib/vocab/extractor/android.rb +56 -0
  8. data/lib/vocab/extractor/base.rb +92 -0
  9. data/lib/vocab/extractor/rails.rb +81 -0
  10. data/lib/vocab/extractor.rb +7 -0
  11. data/lib/vocab/merger/android.rb +59 -0
  12. data/lib/vocab/merger/base.rb +21 -0
  13. data/lib/vocab/merger/rails.rb +105 -0
  14. data/lib/vocab/merger.rb +7 -0
  15. data/lib/vocab/settings.rb +35 -0
  16. data/lib/vocab/translator/android.rb +43 -0
  17. data/lib/vocab/translator/base.rb +12 -0
  18. data/lib/vocab/translator/rails.rb +67 -0
  19. data/lib/vocab/translator.rb +7 -0
  20. data/lib/vocab/ui.rb +19 -0
  21. data/lib/vocab/validator/android.rb +23 -0
  22. data/lib/vocab/validator/base.rb +40 -0
  23. data/lib/vocab/validator/rails.rb +31 -0
  24. data/lib/vocab/validator.rb +7 -0
  25. data/lib/vocab/version.rb +3 -0
  26. data/lib/vocab.rb +36 -0
  27. data/spec/application_spec.rb +20 -0
  28. data/spec/data/android/current.xml +8 -0
  29. data/spec/data/android/locales/values/strings.xml +10 -0
  30. data/spec/data/android/locales/values-es/strings.xml +6 -0
  31. data/spec/data/android/locales/values-large-hdpi/dimens.xml +1 -0
  32. data/spec/data/android/locales/values-large-hdpi/styles.xml +1 -0
  33. data/spec/data/android/previous.xml +6 -0
  34. data/spec/data/android/translations/values-es/es-string-file.xml +7 -0
  35. data/spec/data/android/write.xml +6 -0
  36. data/spec/data/rails/locales/en.yml +10 -0
  37. data/spec/data/rails/locales/es.yml +6 -0
  38. data/spec/data/rails/locales/models/product/en.yml +13 -0
  39. data/spec/data/rails/locales/models/product/es.yml +13 -0
  40. data/spec/data/rails/translations/cn.yml +21 -0
  41. data/spec/data/rails/translations/es.yml +12 -0
  42. data/spec/extractor/android_spec.rb +95 -0
  43. data/spec/extractor/base_spec.rb +134 -0
  44. data/spec/extractor/rails_spec.rb +116 -0
  45. data/spec/merger/android_spec.rb +138 -0
  46. data/spec/merger/base_spec.rb +24 -0
  47. data/spec/merger/rails_spec.rb +183 -0
  48. data/spec/spec_helper.rb +23 -0
  49. data/spec/support/matchers.rb +13 -0
  50. data/spec/support/shared.rb +6 -0
  51. data/spec/tmp/.gitkeep +0 -0
  52. data/spec/translator/android_spec.rb +24 -0
  53. data/spec/translator/rails_spec.rb +155 -0
  54. data/spec/ui_spec.rb +15 -0
  55. data/spec/validator/android_spec.rb +54 -0
  56. data/spec/validator/base_spec.rb +5 -0
  57. data/spec/validator/rails_spec.rb +83 -0
  58. data/spec/vocab_spec.rb +13 -0
  59. data/vocab.gemspec +25 -0
  60. metadata +171 -0
@@ -0,0 +1,155 @@
1
+ require "spec_helper"
2
+
3
+ describe 'Vocab::Translator::Rails' do
4
+
5
+ describe 'load_dir' do
6
+
7
+ before( :each ) do
8
+ @translator = Vocab::Translator::Rails.new
9
+ @translator.load_dir( "#{vocab_root}/spec/data/rails/locales" )
10
+ end
11
+
12
+ it 'loads translations from a directory of yml files' do
13
+
14
+ actual = @translator.translations
15
+ expected = { :marketing=>{ :banner=>"This product is so good" },
16
+ :models =>{ :product=>{ :id_125=>{ :description=>"Green with megawatts",
17
+ :name =>"Lazer" },
18
+ :id_55 =>{ :description=>"A new nested description",
19
+ :name =>"a new nested name" },
20
+ :id_36 =>{ :description=>"Polarized and lazer resistant",
21
+ :name =>"This nested value has changed" } } },
22
+ :menu =>{ :second=>"Second menu item",
23
+ :first=>"First menu item" },
24
+ :dashboard=>{ :chart =>"This value has changed",
25
+ :details=>"This key/value has been added" },
26
+ :not_in_es=>"This key not in spanish" }
27
+ actual.should eql( expected )
28
+ end
29
+
30
+ end
31
+
32
+ describe 'load_file' do
33
+
34
+ before( :each ) do
35
+ @file = "#{vocab_root}/spec/tmp/en.yml"
36
+ @data = { :foo => :bar }
37
+ @yml_hash = { :en => @data }
38
+ File.open( @file, "w+" ) { |f| f.write( @yml_hash.to_yaml ) }
39
+ end
40
+
41
+ it 'loads translations from a yml file' do
42
+ translator = Vocab::Translator::Rails.new
43
+ translator.load_file( @file )
44
+ translator.translations.should == @data
45
+ end
46
+
47
+ it 'sets the language based on the file loaded' do
48
+ @file = "#{vocab_root}/spec/data/rails/locales/en.yml"
49
+ translator = Vocab::Translator::Rails.new
50
+ translator.load_file( @file )
51
+ translator.locale.should eql( :en )
52
+
53
+ @file = "#{vocab_root}/spec/data/rails/locales/es.yml"
54
+ translator = Vocab::Translator::Rails.new
55
+ translator.load_file( @file )
56
+ translator.locale.should eql( :es )
57
+ end
58
+
59
+ end
60
+
61
+ describe 'translations' do
62
+
63
+ before( :each ) do
64
+ @file_1 = "#{vocab_root}/spec/tmp/en.yml"
65
+ @data_1 = { :en => { :foo => :bar } }
66
+ File.open( @file_1, "w+" ) { |f| f.write( @data_1.to_yaml ) }
67
+
68
+ @file_2 = "#{vocab_root}/spec/tmp/en2.yml"
69
+ @data_2 = { :en => { :yee => :hah } }
70
+ File.open( @file_2, "w+" ) { |f| f.write( @data_2.to_yaml ) }
71
+ end
72
+
73
+ it 'caches the translations to protect against someone swapping I18n.load_path' do
74
+ translator_1 = Vocab::Translator::Rails.new
75
+ translator_1.load_file( @file_1 )
76
+ data_1 = translator_1.translations
77
+
78
+ # Implicitly changes the I18n.load_path
79
+ translator_2 = Vocab::Translator::Rails.new
80
+ translator_2.load_file( @file_2 )
81
+
82
+ translator_1.translations.should eql( data_1 )
83
+ end
84
+
85
+ it 'returns nil languages without a translation' do
86
+ translator = Vocab::Translator::Rails.new
87
+ translator.translations.should eql( nil )
88
+ end
89
+
90
+ end
91
+
92
+ describe 'flattened_translations' do
93
+
94
+ it 'returns the translations with flattened keys in english' do
95
+ translator = Vocab::Translator::Rails.new
96
+ translator.load_dir( "#{vocab_root}/spec/data/rails/locales" )
97
+ actual = translator.flattened_translations
98
+ expected = { :"dashboard.details" =>"This key/value has been added",
99
+ :"models.product.id_125.name" =>"Lazer",
100
+ :"models.product.id_55.name" =>"a new nested name",
101
+ :"models.product.id_36.name" =>"This nested value has changed",
102
+ :"menu.second" =>"Second menu item",
103
+ :"dashboard.chart" =>"This value has changed",
104
+ :"menu.first" =>"First menu item",
105
+ :"marketing.banner" =>"This product is so good",
106
+ :"models.product.id_125.description"=>"Green with megawatts",
107
+ :"models.product.id_55.description" =>"A new nested description",
108
+ :"models.product.id_36.description" =>"Polarized and lazer resistant",
109
+ :"not_in_es" =>"This key not in spanish" }
110
+ actual.should == expected
111
+ end
112
+
113
+ it 'returns the translations with flattened keys in other languages' do
114
+ translator = Vocab::Translator::Rails.new( :es )
115
+ translator.load_dir( "#{vocab_root}/spec/data/rails/locales" )
116
+ actual = translator.flattened_translations
117
+ expected = { :"models.product.id_125.name" =>"Lazero",
118
+ :"marketing.banner" =>"hola",
119
+ :"models.product.id_55.name" =>"Muy bonita",
120
+ :"models.product.id_125.description"=>"Verde",
121
+ :"models.product.id_36.name" =>"No Lazero",
122
+ :"models.product.id_55.description" =>"Azul",
123
+ :"models.product.id_36.description" =>"Negro",
124
+ :"dashboard.chart" =>"Es muy bonita",
125
+ :"dashboard.details" =>"grande" }
126
+ actual.should == expected
127
+ end
128
+
129
+ end
130
+
131
+ describe 'store' do
132
+
133
+ it 'stores translation' do
134
+ @key = 'foo.bar'
135
+ @value = 'baz'
136
+ translator = Vocab::Translator::Rails.new
137
+ translator.store( @key, @value )
138
+ translator.flattened_translations[ @key.to_sym ].should eql( @value )
139
+ end
140
+
141
+ end
142
+
143
+ describe 'fetch' do
144
+
145
+ it 'fetch a translation' do
146
+ @key = 'foo.bar'
147
+ @value = 'baz'
148
+ translator = Vocab::Translator::Rails.new
149
+ translator.store( @key, @value )
150
+ translator.fetch( @key ).should eql( @value )
151
+ end
152
+
153
+ end
154
+
155
+ end
data/spec/ui_spec.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe "UI" do
4
+
5
+ describe 'warn' do
6
+
7
+ it 'prepends a warning message to output' do
8
+ message = "there is a problem"
9
+ Vocab.ui.should_receive( :say ).with( "Warning: #{message}" )
10
+ Vocab.ui.warn( message )
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe "Vocab::Validator::Android" do
4
+
5
+ before( :each ) do
6
+ @locales_dir = "#{vocab_root}/spec/data/android/locales"
7
+ @validator = Vocab::Validator::Android.new( @locales_dir )
8
+ end
9
+
10
+ describe 'validate_file' do
11
+
12
+ before( :each ) do
13
+ @path = "#{vocab_root}/spec/data/android/locales/values-es/strings.xml"
14
+ end
15
+
16
+ it 'returns a hash containing the missing keys' do
17
+ result = @validator.validate_file( @path )
18
+ result[ :missing ].should eql( [ "cancel", "delete", "not_in_es" ] )
19
+ end
20
+
21
+ it 'returns a hash containing the extra keys' do
22
+ @validator.should_receive( :english_keys ).and_return( [ 'foo' ] )
23
+ @validator.should_receive( :other_keys ).and_return( [ 'foo', 'extra', 'stuff' ] )
24
+ result = @validator.validate_file( @path )
25
+ result[ :extra ].should eql( [ 'extra', 'stuff' ] )
26
+ end
27
+
28
+ end
29
+
30
+ describe 'files_to_validate' do
31
+
32
+ it 'returns the locale files to validate' do
33
+ files = [ "#{@locales_dir}/values-es/strings.xml" ]
34
+ @validator.files_to_validate.should eql( files )
35
+ end
36
+
37
+ end
38
+
39
+ describe 'validate' do
40
+
41
+ it 'validates android locales files' do
42
+ files = @validator.files_to_validate
43
+ files.each { |file| @validator.should_receive( :validate_file ).with( file ) }
44
+ @validator.should_receive( :print ).exactly( files.size ).times
45
+ @validator.validate
46
+ end
47
+
48
+ it 'prints without exception' do
49
+ @validator.validate
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe "Vocab::Validator::Base" do
4
+
5
+ end
@@ -0,0 +1,83 @@
1
+ require "spec_helper"
2
+
3
+ describe "Vocab::Validator::Rails" do
4
+
5
+ before( :each ) do
6
+ @locales_dir = "#{vocab_root}/spec/data/rails/locales"
7
+ @validator = Vocab::Validator::Rails.new( @locales_dir )
8
+ end
9
+
10
+ describe 'validate_file' do
11
+
12
+ before( :each ) do
13
+ @path = "#{vocab_root}/spec/data/rails/locales/es.yml"
14
+ end
15
+
16
+ it 'returns a hash containing the missing keys' do
17
+ result = @validator.validate_file( @path )
18
+ result[ :missing ].should =~ [ "menu.first", "menu.second", "not_in_es" ]
19
+ end
20
+
21
+ it 'returns a hash containing the extra keys' do
22
+ @validator.should_receive( :english_keys ).and_return( [ 'foo' ] )
23
+ @validator.should_receive( :other_keys ).and_return( [ 'foo', 'extra', 'stuff' ] )
24
+ result = @validator.validate_file( @path )
25
+ result[ :extra ].should eql( [ 'extra', 'stuff' ] )
26
+ end
27
+
28
+ end
29
+
30
+ describe 'files_to_validate' do
31
+
32
+ it 'returns the locale files to validate' do
33
+ files = ["#{@locales_dir}/es.yml",
34
+ "#{@locales_dir}/models/product/es.yml"]
35
+ @validator.files_to_validate.should eql( files )
36
+ end
37
+
38
+ end
39
+
40
+ describe 'validate' do
41
+
42
+ it 'validates android locales files' do
43
+ files = @validator.files_to_validate
44
+ files.each { |file| @validator.should_receive( :validate_file ).with( file ) }
45
+ @validator.should_receive( :print ).exactly( files.size ).times
46
+ @validator.validate
47
+ end
48
+
49
+ it 'prints without exception' do
50
+ @validator.validate
51
+ end
52
+
53
+ end
54
+
55
+ describe 'other_keys' do
56
+
57
+ before( :each ) do
58
+ @file = "#{@locales_dir}/es.yml"
59
+ @validator = Vocab::Validator::Rails.new( @locales_dir )
60
+ end
61
+
62
+ it 'returns the flattened keys from the file' do
63
+ keys = ["dashboard.chart", "dashboard.details", "marketing.banner"]
64
+ @validator.other_keys( @file ).should =~ keys
65
+ end
66
+
67
+ end
68
+
69
+ describe 'english_keys' do
70
+
71
+ before( :each ) do
72
+ @file = "#{@locales_dir}/es.yml"
73
+ @validator = Vocab::Validator::Rails.new( @locales_dir )
74
+ end
75
+
76
+ it 'returns the flattened keys from english equivalent file' do
77
+ keys = ["dashboard.chart", "dashboard.details", "marketing.banner", "menu.first", "menu.second", "not_in_es"]
78
+ @validator.english_keys( @file ).should =~ keys
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe "Vocab" do
4
+
5
+ describe 'root' do
6
+
7
+ it 'returns the root of the gem' do
8
+ Vocab.root.should == File.expand_path( Dir.pwd )
9
+ end
10
+
11
+ end
12
+
13
+ end
data/vocab.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "vocab/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "vocab"
7
+ s.version = Vocab::VERSION
8
+ s.authors = ["Jeff LaBarge"]
9
+ s.email = ["jefflabarge@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Automate management of i18n locale files}
12
+ s.description = %q{Export strings that need to be translated and integrate the completed translations}
13
+ s.rubyforge_project = "vocab"
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.bindir = 'bin'
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # specify any dependencies here; for example:
21
+ s.add_dependency "i18n"
22
+ s.add_dependency "nokogiri"
23
+ s.add_development_dependency "rspec", "~> 2.7.0"
24
+ # s.add_runtime_dependency "rest-client"
25
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vocab
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff LaBarge
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-08 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: i18n
16
+ requirement: &2152213440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152213440
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &2152210940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2152210940
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &2152205700 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.7.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2152205700
47
+ description: Export strings that need to be translated and integrate the completed
48
+ translations
49
+ email:
50
+ - jefflabarge@gmail.com
51
+ executables:
52
+ - vocab
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - Gemfile
58
+ - README.md
59
+ - Rakefile
60
+ - bin/vocab
61
+ - lib/vocab.rb
62
+ - lib/vocab/application.rb
63
+ - lib/vocab/extractor.rb
64
+ - lib/vocab/extractor/android.rb
65
+ - lib/vocab/extractor/base.rb
66
+ - lib/vocab/extractor/rails.rb
67
+ - lib/vocab/merger.rb
68
+ - lib/vocab/merger/android.rb
69
+ - lib/vocab/merger/base.rb
70
+ - lib/vocab/merger/rails.rb
71
+ - lib/vocab/settings.rb
72
+ - lib/vocab/translator.rb
73
+ - lib/vocab/translator/android.rb
74
+ - lib/vocab/translator/base.rb
75
+ - lib/vocab/translator/rails.rb
76
+ - lib/vocab/ui.rb
77
+ - lib/vocab/validator.rb
78
+ - lib/vocab/validator/android.rb
79
+ - lib/vocab/validator/base.rb
80
+ - lib/vocab/validator/rails.rb
81
+ - lib/vocab/version.rb
82
+ - spec/application_spec.rb
83
+ - spec/data/android/current.xml
84
+ - spec/data/android/locales/values-es/strings.xml
85
+ - spec/data/android/locales/values-large-hdpi/dimens.xml
86
+ - spec/data/android/locales/values-large-hdpi/styles.xml
87
+ - spec/data/android/locales/values/strings.xml
88
+ - spec/data/android/previous.xml
89
+ - spec/data/android/translations/values-es/es-string-file.xml
90
+ - spec/data/android/write.xml
91
+ - spec/data/rails/locales/en.yml
92
+ - spec/data/rails/locales/es.yml
93
+ - spec/data/rails/locales/models/product/en.yml
94
+ - spec/data/rails/locales/models/product/es.yml
95
+ - spec/data/rails/translations/cn.yml
96
+ - spec/data/rails/translations/es.yml
97
+ - spec/extractor/android_spec.rb
98
+ - spec/extractor/base_spec.rb
99
+ - spec/extractor/rails_spec.rb
100
+ - spec/merger/android_spec.rb
101
+ - spec/merger/base_spec.rb
102
+ - spec/merger/rails_spec.rb
103
+ - spec/spec_helper.rb
104
+ - spec/support/matchers.rb
105
+ - spec/support/shared.rb
106
+ - spec/tmp/.gitkeep
107
+ - spec/translator/android_spec.rb
108
+ - spec/translator/rails_spec.rb
109
+ - spec/ui_spec.rb
110
+ - spec/validator/android_spec.rb
111
+ - spec/validator/base_spec.rb
112
+ - spec/validator/rails_spec.rb
113
+ - spec/vocab_spec.rb
114
+ - vocab.gemspec
115
+ homepage: ''
116
+ licenses: []
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project: vocab
135
+ rubygems_version: 1.8.10
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: Automate management of i18n locale files
139
+ test_files:
140
+ - spec/application_spec.rb
141
+ - spec/data/android/current.xml
142
+ - spec/data/android/locales/values-es/strings.xml
143
+ - spec/data/android/locales/values-large-hdpi/dimens.xml
144
+ - spec/data/android/locales/values-large-hdpi/styles.xml
145
+ - spec/data/android/locales/values/strings.xml
146
+ - spec/data/android/previous.xml
147
+ - spec/data/android/translations/values-es/es-string-file.xml
148
+ - spec/data/android/write.xml
149
+ - spec/data/rails/locales/en.yml
150
+ - spec/data/rails/locales/es.yml
151
+ - spec/data/rails/locales/models/product/en.yml
152
+ - spec/data/rails/locales/models/product/es.yml
153
+ - spec/data/rails/translations/cn.yml
154
+ - spec/data/rails/translations/es.yml
155
+ - spec/extractor/android_spec.rb
156
+ - spec/extractor/base_spec.rb
157
+ - spec/extractor/rails_spec.rb
158
+ - spec/merger/android_spec.rb
159
+ - spec/merger/base_spec.rb
160
+ - spec/merger/rails_spec.rb
161
+ - spec/spec_helper.rb
162
+ - spec/support/matchers.rb
163
+ - spec/support/shared.rb
164
+ - spec/tmp/.gitkeep
165
+ - spec/translator/android_spec.rb
166
+ - spec/translator/rails_spec.rb
167
+ - spec/ui_spec.rb
168
+ - spec/validator/android_spec.rb
169
+ - spec/validator/base_spec.rb
170
+ - spec/validator/rails_spec.rb
171
+ - spec/vocab_spec.rb