balinterdi-missing_t 0.1.1 → 0.1.2

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/CHANGELOG ADDED
@@ -0,0 +1,5 @@
1
+ v0.1.2 Extraction of I18n messages became better (will now correctly extract messages with dynamic keys, like "myapp.title.#{key}"). Added colorization of output.
2
+
3
+ v0.1.1 Remove dependencies to ruby-debug and pp.
4
+
5
+ v0.1.0 I am alive!
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Balint Erdi (balint.erdi@gmail.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('missing_t', '0.1.1') do |p|
5
+ Echoe.new('missing_t', '0.1.2') do |p|
6
6
  p.description = "See all the missing I18n translations in your Rails project"
7
7
  p.url = "http://github.com/balinterdi/missing_t"
8
8
  p.author = "Balint Erdi"
data/bin/missing_t CHANGED
@@ -4,11 +4,13 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
4
4
 
5
5
  require 'missing_t'
6
6
 
7
- MissingT.new.find_missing_translations(ARGV[0]).each do |file, queries|
7
+ @missing_t = MissingT.new
8
+ @missing_t.instance_eval do
9
+ find_missing_translations(ARGV[0]).each do |file, queries|
8
10
  puts
9
11
  puts "#{file}:"
10
12
  puts
11
- queries.each { |q| puts " #{q}" }
13
+ queries.each { |q| puts " #{red(q)}" }
14
+ end
12
15
  end
13
16
 
14
-
data/lib/missing_t.rb CHANGED
@@ -34,7 +34,22 @@ class Hash
34
34
 
35
35
  end
36
36
 
37
+ module Helpers
38
+ # snatched from rspec source
39
+ def colour(text, colour_code)
40
+ "#{colour_code}#{text}\e[0m"
41
+ end
42
+
43
+ def green(text); colour(text, "\e[32m"); end
44
+ def red(text); colour(text, "\e[31m"); end
45
+ def magenta(text); colour(text, "\e[35m"); end
46
+ def yellow(text); colour(text, "\e[33m"); end
47
+ def blue(text); colour(text, "\e[34m"); end
48
+
49
+ end
50
+
37
51
  class MissingT
52
+ include Helpers
38
53
  extend Forwardable
39
54
  def_delegators :@translations, :[]
40
55
 
@@ -95,9 +110,11 @@ class MissingT
95
110
  end
96
111
 
97
112
  def extract_i18n_queries(file)
98
- i18n_query_pattern = /I18n\.(?:translate|t)\s*\((.*?)[,\)]/
99
- get_content_of_file_with_i18n_queries(file).
100
- scan(i18n_query_pattern).map { |match| match.first.gsub(/[^\w\.]/, '') }
113
+ i18n_query_pattern = /[^\w]+(?:I18n\.translate|I18n\.t|translate|t)\s*\((.*?)[,\)]/
114
+ i18n_query_no_parens_pattern = /[^\w]+(?:I18n\.translate|I18n\.t|translate|t)\s+(['"])(.*?)\1/
115
+ file_content = get_content_of_file_with_i18n_queries(file)
116
+ file_content.scan(i18n_query_pattern).map { |match| match.first.gsub(/['"\s]/, '') }.
117
+ concat(file_content.scan(i18n_query_no_parens_pattern).map { |match| match[1].gsub(/['"\s]/, '') })
101
118
  end
102
119
 
103
120
  def collect_translation_queries
@@ -158,12 +175,14 @@ class MissingT
158
175
  end
159
176
 
160
177
  if __FILE__ == $0
161
- # puts "ARGV[1] = #{ARGV[0]}"
162
178
  # pp MissingT.new.find_missing_translations(ARGV[0]).values.inject(0) { |sum, qs| sum + qs.length }
163
- MissingT.new.find_missing_translations(ARGV[0]).each do |file, queries|
179
+ @missing_t = MissingT.new
180
+ @missing_t.instance_eval do
181
+ find_missing_translations(ARGV[0]).each do |file, queries|
164
182
  puts
165
183
  puts "#{file}:"
166
184
  puts
167
- queries.each { |q| puts " #{q}" }
185
+ queries.each { |q| puts " #{red(q)}" }
186
+ end
168
187
  end
169
188
  end
data/missing_t.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{missing_t}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Balint Erdi"]
9
- s.date = %q{2009-03-03}
9
+ s.date = %q{2009-03-10}
10
10
  s.default_executable = %q{missing_t}
11
11
  s.description = %q{See all the missing I18n translations in your Rails project}
12
12
  s.email = %q{balint.erdi@gmail.com}
13
13
  s.executables = ["missing_t"]
14
- s.extra_rdoc_files = ["bin/missing_t", "lib/missing_t.rb", "README.markdown", "tasks/missing_t.rake"]
15
- s.files = ["bin/missing_t", "init.rb", "lib/missing_t.rb", "Manifest", "Rakefile", "README.markdown", "spec/missing_t_spec.rb", "spec/spec_helper.rb", "tasks/missing_t.rake", "missing_t.gemspec"]
14
+ s.extra_rdoc_files = ["bin/missing_t", "CHANGELOG", "lib/missing_t.rb", "README.markdown", "tasks/missing_t.rake"]
15
+ s.files = ["bin/missing_t", "CHANGELOG", "init.rb", "lib/missing_t.rb", "Manifest", "missing_t.gemspec", "MIT-LICENSE", "Rakefile", "README.markdown", "spec/missing_t_spec.rb", "spec/spec_helper.rb", "tasks/missing_t.rake"]
16
16
  s.has_rdoc = true
17
17
  s.homepage = %q{http://github.com/balinterdi/missing_t}
18
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Missing_t", "--main", "README.markdown"]
@@ -83,21 +83,86 @@ describe "MissingT" do
83
83
  end
84
84
  end
85
85
 
86
- describe "extracting i18n queries" do
86
+ describe "the i18n query extracion" do
87
87
  before do
88
+ $stubba = Mocha::Central.new
89
+ metaclass = class << @missing_t; self; end
90
+ metaclass.instance_eval do
91
+ define_method :get_content_of_file_with_i18n_queries do |content|
92
+ content
93
+ end
94
+ end
95
+ end
96
+
97
+ it "should correctly extract the I18n.t type of messages" do
88
98
  content = <<-EOS
89
99
  <div class="title_gray"><span><%= I18n.t("anetcom.member.projects.new.page_title") %></span></div>
100
+ EOS
101
+ @missing_t.extract_i18n_queries(content).should == ["anetcom.member.projects.new.page_title"]
102
+ end
103
+
104
+ it "should correctly extract the I18n.t type of messages not right after the <%= mark" do
105
+ content = <<-EOS
90
106
  <%= submit_tag I18n.t('anetcom.member.projects.new.create_project'), :class => 'button' %>
107
+ EOS
108
+ @missing_t.extract_i18n_queries(content).should == ["anetcom.member.projects.new.create_project"]
109
+ end
110
+
111
+ it "should correctly extract the I18n.t type of messages from a link_to" do
112
+ # honestly, I am not sure anymore why this qualifies as a sep. test case
113
+ # but I am sure there was something special about this one :)
114
+ content = <<-EOS
91
115
  <%= link_to I18n.t("tog_headlines.admin.publish"), publish_admin_headlines_story_path(story), :class => 'button' %>
92
- :html => {:title => I18n.t("tog_social.sharing.share_with", :name => shared.name)}
93
116
  EOS
94
- $stubba = Mocha::Central.new
95
- @missing_t.stubs(:get_content_of_file_with_i18n_queries).returns(content)
117
+ @missing_t.extract_i18n_queries(content).should == ["tog_headlines.admin.publish"]
118
+ end
119
+
120
+ it "should correctly extract the I18n.t type of messages with an argument in the message" do
121
+ content = <<-EOS
122
+ :html => {:title => I18n.t("tog_social.sharing.share_with", :name => shared.name)}
123
+ EOS
124
+ @missing_t.extract_i18n_queries(content).should == ["tog_social.sharing.share_with"]
125
+ end
126
+
127
+ it "should correctly extract the I18n.translate type of messages" do
128
+ content = <<-EOS
129
+ <div class="title_gray"><span><%= I18n.translate("anetcom.member.projects.new.page_title") %></span></div>
130
+ EOS
131
+ @missing_t.extract_i18n_queries(content).should == ["anetcom.member.projects.new.page_title"]
132
+ end
133
+
134
+ it "should correctly extract the t type of messages" do
135
+ content = <<-EOS
136
+ <div class="title_gray"><span><%= t("anetcom.member.projects.new.page_title") %></span></div>
137
+ EOS
138
+ @missing_t.extract_i18n_queries(content).should == ["anetcom.member.projects.new.page_title"]
139
+ end
140
+
141
+ it "should find several messages on the same line" do
142
+ content = <<-EOS
143
+ <div class="title_gray"><span><%= t("anetcom.member.projects.new.page_title") %></span><span>t("anetcom.member.projects.new.page_size")</span></div>
144
+ EOS
145
+ @missing_t.extract_i18n_queries(content).should == ["anetcom.member.projects.new.page_title", "anetcom.member.projects.new.page_size"]
146
+ end
147
+
148
+ it "should find messages with a parens-less call" do
149
+ content = <<-EOS
150
+ <div class="title_gray"><span><%= t "anetcom.member.projects.new.page_title" %></span></div>
151
+ EOS
152
+ @missing_t.extract_i18n_queries(content).should == ["anetcom.member.projects.new.page_title"]
153
+ end
154
+
155
+ it "should not extract a function call that just ends in t" do
156
+ content = <<-EOS
157
+ <div class="title_gray"><span><%= at(3) %></span></div>
158
+ EOS
159
+ @missing_t.extract_i18n_queries(content).should == []
96
160
  end
97
161
 
98
- it "should extract the I18n queries correctly when do" do
99
- i18n_queries = @missing_t.extract_i18n_queries(nil)
100
- i18n_queries.should == ["anetcom.member.projects.new.page_title", "anetcom.member.projects.new.create_project", "tog_headlines.admin.publish", "tog_social.sharing.share_with"]
162
+ it "should find and correctly extract a dynamic key translation message" do
163
+ # @missing_t.stubs(:get_content_of_file_with_i18n_queries).returns(content)
164
+ content = %q(<div class="title_gray"><span><%= I18n.t("mycompany.welcome.#{key}") %></span></div>)
165
+ @missing_t.extract_i18n_queries(content).should == [%q(mycompany.welcome.#{key})]
101
166
  end
102
167
 
103
168
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: balinterdi-missing_t
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balint Erdi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-03 00:00:00 -08:00
12
+ date: 2009-03-10 00:00:00 -07:00
13
13
  default_executable: missing_t
14
14
  dependencies: []
15
15
 
@@ -21,20 +21,23 @@ extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
23
  - bin/missing_t
24
+ - CHANGELOG
24
25
  - lib/missing_t.rb
25
26
  - README.markdown
26
27
  - tasks/missing_t.rake
27
28
  files:
28
29
  - bin/missing_t
30
+ - CHANGELOG
29
31
  - init.rb
30
32
  - lib/missing_t.rb
31
33
  - Manifest
34
+ - missing_t.gemspec
35
+ - MIT-LICENSE
32
36
  - Rakefile
33
37
  - README.markdown
34
38
  - spec/missing_t_spec.rb
35
39
  - spec/spec_helper.rb
36
40
  - tasks/missing_t.rake
37
- - missing_t.gemspec
38
41
  has_rdoc: true
39
42
  homepage: http://github.com/balinterdi/missing_t
40
43
  post_install_message: