i18n_missing_keys 0.1.14

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/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Jakob Skjerning
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,13 @@
1
+ = i18n_missing_keys
2
+
3
+
4
+ == Contributing to i18n_missing_keys
5
+
6
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
7
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
8
+ * Fork the project.
9
+ * Start a feature/bugfix branch.
10
+ * Commit and push until you are happy with your contribution.
11
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
12
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
13
+
@@ -0,0 +1,116 @@
1
+ namespace :i18n do
2
+ desc "Find and list translation keys that do not exist in all locales"
3
+ task :missing_keys => :environment do
4
+ finder = MissingKeysFinder.new(I18n.backend)
5
+ finder.find_missing_keys
6
+ end
7
+ end
8
+
9
+
10
+ class MissingKeysFinder
11
+
12
+ def initialize(backend)
13
+ @backend = backend
14
+ self.load_config
15
+ self.load_translations
16
+ end
17
+
18
+ # Returns an array with all keys from all locales
19
+ def all_keys
20
+ I18n.backend.send(:translations).collect do |check_locale, translations|
21
+ collect_keys([], translations).sort
22
+ end.flatten.uniq
23
+ end
24
+
25
+ def find_missing_keys
26
+ output_available_locales
27
+ output_unique_key_stats(all_keys)
28
+
29
+ missing_keys = {}
30
+ all_keys.each do |key|
31
+
32
+ I18n.available_locales.each do |locale|
33
+
34
+ skip = false
35
+ ls = locale.to_s
36
+ if !@yaml[ls].nil?
37
+ @yaml[ls].each do |re|
38
+ if key.match(re)
39
+ skip = true
40
+ break
41
+ end
42
+ end
43
+ end
44
+
45
+ if !key_exists?(key, locale) && skip == false
46
+ if missing_keys[key]
47
+ missing_keys[key] << locale
48
+ else
49
+ missing_keys[key] = [locale]
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ output_missing_keys(missing_keys)
56
+ return missing_keys
57
+ end
58
+
59
+ def output_available_locales
60
+ puts "#{I18n.available_locales.size} #{I18n.available_locales.size == 1 ? 'locale' : 'locales'} available: #{I18n.available_locales.join(', ')}"
61
+ end
62
+
63
+ def output_missing_keys(missing_keys)
64
+ puts "#{missing_keys.size} #{missing_keys.size == 1 ? 'key is missing' : 'keys are missing'} from one or more locales:"
65
+ missing_keys.keys.sort.each do |key|
66
+ puts "'#{key}': Missing from #{missing_keys[key].collect(&:inspect).join(', ')}"
67
+ end
68
+ end
69
+
70
+ def output_unique_key_stats(keys)
71
+ number_of_keys = keys.size
72
+ puts "#{number_of_keys} #{number_of_keys == 1 ? 'unique key' : 'unique keys'} found."
73
+ end
74
+
75
+ def collect_keys(scope, translations)
76
+ full_keys = []
77
+ translations.to_a.each do |key, translations|
78
+ next if translations.nil?
79
+
80
+ new_scope = scope.dup << key
81
+ if translations.is_a?(Hash)
82
+ full_keys += collect_keys(new_scope, translations)
83
+ else
84
+ full_keys << new_scope.join('.')
85
+ end
86
+ end
87
+ return full_keys
88
+ end
89
+
90
+ # Returns true if key exists in the given locale
91
+ def key_exists?(key, locale)
92
+ I18n.locale = locale
93
+ I18n.translate(key, :raise => true)
94
+ return true
95
+ rescue I18n::MissingInterpolationArgument
96
+ return true
97
+ rescue I18n::MissingTranslationData
98
+ return false
99
+ end
100
+
101
+ def load_translations
102
+ # Make sure we’ve loaded the translations
103
+ I18n.backend.send(:init_translations)
104
+ end
105
+
106
+ def load_config
107
+ @yaml = {}
108
+ begin
109
+ @yaml = YAML.load_file(File.join(Rails.root, 'config', 'ignore_missing_keys.yml'))
110
+ rescue => e
111
+ STDERR.puts "No ignore_missing_keys.yml config file."
112
+ end
113
+
114
+ end
115
+
116
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n_missing_keys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.14
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ideadapt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.4
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.4
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: activesupport
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Rake task to find localization keys missing from different locales in
111
+ a Rails application using the I18n::Simple backend.
112
+ email: ueli.kunz@renuo.ch
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.rdoc
118
+ files:
119
+ - lib/tasks/i18n_missing_keys.rake
120
+ - LICENSE.txt
121
+ - README.rdoc
122
+ homepage: http://github.com/renuo/i18n_missing_keys
123
+ licenses:
124
+ - MIT
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ segments:
136
+ - 0
137
+ hash: -3477762623039069136
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.24
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: Rake task to find localization keys missing from different locales.
150
+ test_files: []