missing_t 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- missing_t (0.3.0)
4
+ missing_t (0.3.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/bin/missing_t CHANGED
@@ -4,16 +4,32 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
4
 
5
5
  require 'missing_t'
6
6
 
7
- @missing_t = MissingT.new
7
+ def hashify(strings)
8
+ strings.map { |s| s.split('.') }.each_with_object({}) do |segmented_string, h|
9
+ segmented_string.each do |segment|
10
+ h[segment] ||= {}
11
+ h = h[segment]
12
+ end
13
+ end
14
+ end
8
15
 
9
- @missing_t = MissingT.new
10
- @missing_t.instance_eval do
11
- parse_options(ARGV)
12
- find_missing_translations(ARGV[0]).each do |file, queries|
13
- puts
14
- puts "#{file}:"
15
- puts
16
- queries.each { |q| puts " #{red(q)}" }
16
+ def print_hash(h, level)
17
+ h.each_pair do |k,v|
18
+ puts %(#{" " * (level*2)}#{k}:)
19
+ print_hash(v, level+1)
17
20
  end
18
21
  end
19
22
 
23
+ missing_t = MissingT.new
24
+ missing_t.parse_options(ARGV)
25
+ missing_message_strings = missing_t.find_missing_translations(ARGV.first).values.map { |ms| hashify(ms) }
26
+
27
+ missing = missing_message_strings.each_with_object({}) do |h, all_message_strings|
28
+ all_message_strings.deep_safe_merge!(h)
29
+ end
30
+
31
+ missing.each do |language, missing_for_language|
32
+ puts
33
+ puts "#{language}:"
34
+ print_hash(missing_for_language, 1)
35
+ end
data/lib/missing_t.rb CHANGED
@@ -52,7 +52,7 @@ end
52
52
 
53
53
  class MissingT
54
54
 
55
- VERSION = "0.3.0"
55
+ VERSION = "0.3.1"
56
56
 
57
57
  include Helpers
58
58
  extend Forwardable
@@ -81,7 +81,7 @@ class MissingT
81
81
  end
82
82
 
83
83
  opts.on_tail("--version", "Show version") do
84
- puts "0.1.2"
84
+ puts VERSION
85
85
  exit
86
86
  end
87
87
 
@@ -108,19 +108,6 @@ class MissingT
108
108
  end
109
109
  end
110
110
 
111
- def hashify(strings)
112
- h = Hash.new
113
- strings.map { |s| s.split('.') }.
114
- each do |segmented_string|
115
- root = h
116
- segmented_string.each do |segment|
117
- root[segment] ||= {}
118
- root = root[segment]
119
- end
120
- end
121
- h
122
- end
123
-
124
111
  def translations_in_file(yaml_file)
125
112
  open(yaml_file) { |f| YAML.load(f.read) }
126
113
  end
@@ -152,14 +139,12 @@ class MissingT
152
139
  end
153
140
 
154
141
  def collect_translation_queries
155
- queries = {}
156
- files_with_i18n_queries.each do |file|
142
+ files_with_i18n_queries.each_with_object({}) do |file, queries|
157
143
  queries_in_file = extract_i18n_queries(file)
158
- unless queries_in_file.empty?
144
+ if queries_in_file.any?
159
145
  queries[file] = queries_in_file
160
146
  end
161
147
  end
162
- queries
163
148
  #TODO: remove duplicate queries across files
164
149
  end
165
150
 
@@ -172,21 +157,18 @@ class MissingT
172
157
  true
173
158
  end
174
159
 
175
- def get_missing_translations(queries, lang=nil)
176
- missing = {}
177
- languages = lang.nil? ? translations.keys : [lang]
178
- languages.each do |l|
179
- get_missing_translations_for_lang(queries, l).each do |file, qs|
160
+ def get_missing_translations(queries, languages)
161
+ languages.each_with_object({}) do |lang, missing|
162
+ get_missing_translations_for_lang(queries, lang).each do |file, queries|
180
163
  missing[file] ||= []
181
- missing[file].concat(qs).uniq!
164
+ missing[file].concat(queries).uniq!
182
165
  end
183
166
  end
184
- missing
185
167
  end
186
168
 
187
169
  def find_missing_translations(lang=nil)
188
170
  collect_translations
189
- get_missing_translations(collect_translation_queries, lang)
171
+ get_missing_translations(collect_translation_queries, lang ? [lang] : translations.keys)
190
172
  end
191
173
 
192
174
  private
@@ -188,7 +188,7 @@ describe "MissingT" do
188
188
  @missing_t.has_translation?("fr", "zoo.bee").should == false
189
189
  @missing_t.has_translation?("es", "mother").should == false
190
190
  end
191
-
191
+
192
192
  describe "of dynamic message strings" do
193
193
  it "should return true if it has a translation that matches the fix parts" do
194
194
  @missing_t.has_translation?("fr", %q(zoo.#{animal})).should == true
@@ -196,7 +196,7 @@ describe "MissingT" do
196
196
 
197
197
  it "should return false if it does not have a translation that matches all the fix parts" do
198
198
  @missing_t.has_translation?("fr", %q(household.#{animal})).should == false
199
- end
199
+ end
200
200
  end
201
201
 
202
202
  it "should correctly get missing translations for a spec. language" do
@@ -214,4 +214,4 @@ describe "MissingT" do
214
214
  end
215
215
  end
216
216
 
217
- end
217
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: missing_t
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.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-02-07 00:00:00.000000000 Z
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  segments:
150
150
  - 0
151
- hash: 1420340980301416439
151
+ hash: -311353985734395445
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  segments:
159
159
  - 0
160
- hash: 1420340980301416439
160
+ hash: -311353985734395445
161
161
  requirements: []
162
162
  rubyforge_project:
163
163
  rubygems_version: 1.8.23