missing_translations 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # missing_translations
2
2
 
3
- Shows missing I18n keys for Rails 3 application. It parses all view files searchign for ```t``` helper invocation. Currently only haml views suported.
3
+ Shows missing I18n keys for Rails 3 application. It parses all view files searching for ```t``` helper invocation. ```HAML``` and ```ERB``` views are supported.
4
+
5
+ ## Installation
6
+
7
+ Add the following line to your ```Gemfile```:
8
+
9
+ ```ruby
10
+ gem 'missing_translations'
11
+ ```
4
12
 
5
13
  ## How to run
6
14
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 1.0.0
@@ -1,25 +1,11 @@
1
1
  require 'hash_keys_dumper'
2
+ require 'templates_parser'
2
3
 
3
4
  namespace :missing_translations do
4
5
  desc 'Shows I18n translation keys which are missing (according to view parsing)'
5
6
  task :show => :environment do
6
- keys = Dir.glob('app/**/*.haml').map do |view|
7
- file = File.basename(view).gsub /^_?(.+?)\..+$/, '\1'
8
- dir = view.split('/')[-2]
9
- context = "#{dir}.#{file}"
10
-
11
- File.readlines(view).map do |line|
12
- line.scan(/\s+t\s*\(?['"]([^#+]+?)['"]/i).map do |m|
13
- arg = m[0]
14
- if arg != '.'
15
- arg[0] == '.' ? "en.#{context}#{arg}" : "en.#{arg}"
16
- end
17
- end
18
- end
19
- end
20
- used_keys = keys.compact.flatten.compact.uniq
21
-
22
- # puts used_keys
7
+ parser = TemplatesParser.new Dir.glob('app/**/*.haml') + Dir.glob('app/**/*.erb')
8
+ used_keys = parser.keys
23
9
 
24
10
  keys = Dir.glob('config/locales/*.yml').map { |locale| HashKeysDumper.dump YAML.load(File.read(locale)) }
25
11
  available_keys = keys.flatten
@@ -0,0 +1,32 @@
1
+ class TemplatesParser
2
+ def initialize(files)
3
+ @files = files
4
+ end
5
+
6
+ def keys
7
+ keys = @files.map do |template|
8
+ file = File.basename(template).gsub /^_?(.+?)\..+$/, '\1'
9
+ dir = template.split('/')[-2]
10
+ context = "#{dir}.#{file}"
11
+
12
+ File.readlines(template).map { |line| line_keys(line, context) }
13
+ end
14
+
15
+ keys.compact.flatten.compact.uniq
16
+ end
17
+
18
+ private
19
+
20
+ def locale
21
+ 'en'.freeze
22
+ end
23
+
24
+ def line_keys(line, context)
25
+ line.scan(/\W+t(ranslate)?\s*\(?['"]([^#]+?)['"]/i).map do |m|
26
+ arg = m[1]
27
+ if arg != '.'
28
+ arg[0] == '.' ? "#{locale}.#{context}#{arg}" : "#{locale}.#{arg}"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "missing_translations"
8
- s.version = "0.2.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrey Chernih"]
12
- s.date = "2012-12-02"
12
+ s.date = "2012-12-04"
13
13
  s.email = "andrey.chernih@gmail.com"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -28,9 +28,13 @@ Gem::Specification.new do |s|
28
28
  "lib/missing_translations.rb",
29
29
  "lib/railtie.rb",
30
30
  "lib/tasks/missing_translations.rb",
31
+ "lib/templates_parser.rb",
31
32
  "missing_translations.gemspec",
33
+ "spec/fixtures/template.erb",
34
+ "spec/fixtures/template.haml",
32
35
  "spec/lib/hash_keys_dumper_spec.rb",
33
- "spec/spec_helper.rb"
36
+ "spec/spec_helper.rb",
37
+ "spec/templates_parser_spec.rb"
34
38
  ]
35
39
  s.homepage = "http://github.com/AndreyChernyh/missing_translations"
36
40
  s.licenses = ["MIT"]
@@ -0,0 +1,4 @@
1
+ <h1>Testing</h1
2
+
3
+ <%= t('.testing') %>
4
+ <%= t('.erb_translation') %>
@@ -0,0 +1,13 @@
1
+ %h1 Testing
2
+
3
+ = t('.testing')
4
+ #whatever = t('.whatever')
5
+
6
+ = t("with #{another} interpolation")
7
+
8
+ = t(".with_double_quotes")
9
+ = t('global_scoped')
10
+
11
+ = translate('long_helper_name')
12
+
13
+ = #{t('multiple_occurences')} #{t('on_the_same_string')}
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'templates_parser'
3
+
4
+ describe TemplatesParser do
5
+ let(:templates) { ['spec/fixtures/template.erb', 'spec/fixtures/template.haml'] }
6
+
7
+ subject { described_class.new templates }
8
+
9
+ its(:keys) { should include 'en.fixtures.template.testing' }
10
+ its(:keys) { should include 'en.fixtures.template.erb_translation' }
11
+ its(:keys) { should include 'en.fixtures.template.whatever' }
12
+ its(:keys) { should include 'en.fixtures.template.with_double_quotes' }
13
+ its(:keys) { should include 'en.global_scoped' }
14
+ its(:keys) { should include 'en.long_helper_name' }
15
+ its(:keys) { should include 'en.multiple_occurences' }
16
+ its(:keys) { should include 'en.on_the_same_string' }
17
+
18
+ it 'does not includes keys with string interpolation' do
19
+ subject.keys.each { |key| key.should_not include 'interpolation' }
20
+ end
21
+ end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: missing_translations
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrey Chernih
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-02 00:00:00.000000000 Z
12
+ date: 2012-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  prerelease: false
@@ -95,9 +95,13 @@ files:
95
95
  - lib/missing_translations.rb
96
96
  - lib/railtie.rb
97
97
  - lib/tasks/missing_translations.rb
98
+ - lib/templates_parser.rb
98
99
  - missing_translations.gemspec
100
+ - spec/fixtures/template.erb
101
+ - spec/fixtures/template.haml
99
102
  - spec/lib/hash_keys_dumper_spec.rb
100
103
  - spec/spec_helper.rb
104
+ - spec/templates_parser_spec.rb
101
105
  homepage: http://github.com/AndreyChernyh/missing_translations
102
106
  licenses:
103
107
  - MIT
@@ -112,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
116
  version: '0'
113
117
  segments:
114
118
  - 0
115
- hash: -1209027482231938804
119
+ hash: -513714428489032317
116
120
  none: false
117
121
  required_rubygems_version: !ruby/object:Gem::Requirement
118
122
  requirements: