i18n-tasks 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 548b6c0914a87c8129d182758dfce8fd3e296f4c
4
+ data.tar.gz: afb9f738e869ca9250569559482b6abef7a729a7
5
+ SHA512:
6
+ metadata.gz: eacb09e1ed32e1e3023cc4484f3c907cfacb27e3ca58d938eb19411e3fdfdacdb7e4451bab2e4e677db577b64b0f6ec64751766cc520dd1b73e675a0ebe03aa4
7
+ data.tar.gz: 42867a547082972542fae5bfe92e6793a88c5b6bfb321485395d5e8b6ee010f015c66f0c3e4df81756554e0854ce3f1ac9a7488825a7a44096e08a89de9179f5
data/.gitignore ADDED
@@ -0,0 +1,33 @@
1
+ *.rbc
2
+ *.sassc
3
+ .sass-cache
4
+ capybara-*.html
5
+ .rspec
6
+ /.bundle
7
+ /vendor/bundle
8
+ /log/*
9
+ /tmp/*
10
+ /db/*.sqlite3
11
+ /public/system/*
12
+ /coverage/
13
+ /spec/tmp/*
14
+ **.orig
15
+ rerun.txt
16
+ pickle-email-*.html
17
+ *.gem
18
+ *.rbc
19
+ .bundle
20
+ .config
21
+ .yardoc
22
+ Gemfile.lock
23
+ InstalledFiles
24
+ _yardoc
25
+ coverage
26
+ doc/
27
+ lib/bundler/man
28
+ pkg
29
+ rdoc
30
+ spec/reports
31
+ test/tmp
32
+ test/version_tmp
33
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ i18n-tasks
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p195
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in i18n-tasks.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Gleb Mazovetskiy
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ i18n-tasks
2
+ ==========
3
+
4
+ I18n tasks to find missing / unused translations and more
5
+
6
+ There are 3 tasks available to manage translations.
7
+
8
+ $ rake -T i18n
9
+ rake i18n:missing # show keys with translation values identical to base
10
+ rake i18n:prefill # add keys from base locale to others
11
+ rake i18n:unused # find potentially unused translations
12
+
13
+ * `i18n:missing` task shows all the keys that have not been translated yet
14
+ * `i18n:prefill` task adds missing keys to locale files, prefilling with base locale (en) value by default
15
+ * `i18n:unused` task shows potentially unused translations (it may give false positives)
16
+
17
+ Installation
18
+ ============
19
+
20
+ Simply add to Gemfile:
21
+
22
+ gem 'i18n-tasks', '~> 0.0.1'
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'i18n/tasks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'i18n-tasks'
8
+ spec.version = I18n::Tasks::VERSION
9
+ spec.authors = ['glebm']
10
+ spec.email = ['glex.spb@gmail.com']
11
+ spec.summary = %q{Rails I18n tasks to find missing / unused translations and more}
12
+ spec.description = %q{Rails I18n tasks to find missing / unused translations and more}
13
+ spec.homepage = 'https://github.com/glebm/i18n-tasks'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
data/lib/i18n/tasks.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'i18n/tasks/version'
2
+ require 'i18n/tasks/railtie'
3
+
4
+ module I18n
5
+ module Tasks
6
+
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails'
2
+ module I18n
3
+ module Tasks
4
+ class Railtie < ::Rails::Railtie
5
+ rake_tasks {
6
+ load "tasks/i18n-tasks.rake"
7
+ }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module I18n
2
+ module Tasks
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,65 @@
1
+ require 'set'
2
+ require 'open3'
3
+
4
+ namespace :i18n do
5
+ desc 'add keys from base locale to others'
6
+ task :prefill => :environment do
7
+ # Will also rewrite en, good for ordering
8
+ I18n.available_locales.map(&:to_s).each do |target_locale|
9
+ trn = YAML.load_file trn_path(target_locale)
10
+ prefilled = { target_locale => base[base_locale] }.deep_merge(trn)
11
+ File.open(trn_path(target_locale), 'w'){ |f| f.write prefilled.to_yaml }
12
+ end
13
+ end
14
+
15
+ desc 'show keys with translation values identical to base'
16
+ task :missing => :environment do
17
+ (I18n.available_locales.map(&:to_s) - [base_locale]).each do |locale|
18
+ trn = YAML.load_file(trn_path(locale))[locale]
19
+ traverse base[base_locale] do |key, base_value|
20
+ translated = t(trn, key)
21
+ if translated.blank? || translated == base_value
22
+ puts "#{locale}.#{key}: #{base_value}"
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ desc 'find potentially unused translations'
29
+ task :unused => :environment do
30
+ _in, out, _err = Open3.popen3 'grep', '-horI', %q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, 'app/'
31
+ used_keys = out.gets(nil).split("\n").map { |r| r.match(/['"](.*?)['"]/)[1] }.uniq.to_set
32
+ pattern_prefixes = used_keys.select { |key| key =~ /\#{.*?}/ || key.ends_with?('.') }.map { |key| key.split(/\.?#/)[0] }
33
+ traverse base[base_locale] do |key, value|
34
+ if !used_keys.include?(key) && !pattern_prefixes.any? { |pp| key.start_with?(pp) }
35
+ puts "#{key}: #{value}"
36
+ end
37
+ end
38
+ end
39
+
40
+ define_method :trn_path do |locale|
41
+ "config/locales/#{locale}.yml"
42
+ end
43
+
44
+ define_method :traverse do |path = '', hash, &block|
45
+ hash.each do |k, v|
46
+ if v.is_a?(Hash)
47
+ traverse("#{path}.#{k}", v, &block)
48
+ else
49
+ block.call("#{path}.#{k}"[1..-1], v)
50
+ end
51
+ end
52
+ end
53
+
54
+ define_method :t do |hash, key|
55
+ key.split('.').inject(hash) { |r, seg| r.try(:[], seg) }
56
+ end
57
+
58
+ define_method :base_locale do
59
+ I18n.default_locale.to_s
60
+ end
61
+
62
+ define_method :base do
63
+ @base ||= YAML.load_file trn_path(base_locale)
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - glebm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Rails I18n tasks to find missing / unused translations and more
42
+ email:
43
+ - glex.spb@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .ruby-gemset
50
+ - .ruby-version
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - i18n-tasks.gemspec
56
+ - lib/i18n/tasks.rb
57
+ - lib/i18n/tasks/railtie.rb
58
+ - lib/i18n/tasks/version.rb
59
+ - lib/tasks/i18n-tasks.rake
60
+ homepage: https://github.com/glebm/i18n-tasks
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Rails I18n tasks to find missing / unused translations and more
84
+ test_files: []