helloh 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +3 -0
  2. data/README.mkd +31 -0
  3. data/bin/helloh +28 -0
  4. data/lib/helloh.rb +48 -0
  5. metadata +67 -0
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright 2011 Rémi Prévost.
2
+ You may use this work without restrictions, as long as this notice is included.
3
+ The work is provided "as is" without warranty of any kind, neither express nor implied.
@@ -0,0 +1,31 @@
1
+ # Helloh
2
+
3
+ Helloh compares Rails localization files and looks for missing keys.
4
+
5
+ ## Installation
6
+
7
+ You can install the gem as a standalone utility:
8
+
9
+ $ gem install helloh
10
+
11
+ or include it in your `Gemfile`:
12
+
13
+ gem "helloh"
14
+
15
+ ## Usage
16
+
17
+ If used without arguments, Helloh will look for files in a relative `./config/locales` directory.
18
+
19
+ $ helloh
20
+
21
+ However, you can also use a path (where the localization files are) as the first argument:
22
+
23
+ $ helloh /path/to/my/rails/project/config/locales
24
+
25
+ ## Features
26
+
27
+ It is still missing a lot of useful features. Like colored output. But its biggest feature would be to scan every file in a Rails project and check if every translation is defined in each localization file. That’s coming too.
28
+
29
+ ## License
30
+
31
+ Helloh is © 2011 Rémi Prévost and may be freely distributed under the [LITL license](http://litl.info/). See the `LICENSE` file.
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ def bail(msg)
4
+ puts msg
5
+ exit(1)
6
+ end
7
+
8
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
9
+
10
+ require "helloh"
11
+
12
+ directory = ARGV[0] || "./config/locales"
13
+
14
+ helloh = Helloh.new
15
+ helloh.files = Dir.glob(File.join(directory, "*.yml"))
16
+ helloh.compare!
17
+
18
+ status_code = 0
19
+
20
+ helloh.results.each_pair do |file, errors|
21
+ if errors[:missing].any?
22
+ status_code = 1
23
+ puts "\nMissing keys in #{file}"
24
+ puts errors[:missing].map{ |key| "- #{key}" }
25
+ end
26
+ end
27
+
28
+ exit status_code
@@ -0,0 +1,48 @@
1
+ require "yaml"
2
+
3
+ class Helloh
4
+ attr_accessor :files
5
+ attr_reader :results
6
+
7
+ def initialize # {{{
8
+ @results = {}
9
+ @files = []
10
+ end # }}}
11
+
12
+ def compare! # {{{
13
+ files.each do |file|
14
+ @file = File.basename(file)
15
+
16
+ files.each do |other_file|
17
+ next if file == other_file
18
+ @other_file = File.basename(other_file)
19
+ @results[@other_file] ||= { :missing => [] }
20
+ compare_yaml_hash(YAML.load_file(file)[Helloh.lang_from_filename(file)], YAML.load_file(other_file)[Helloh.lang_from_filename(other_file)])
21
+ end
22
+
23
+ end
24
+ end # }}}
25
+
26
+ private
27
+
28
+ def compare_yaml_hash(content1, content2, context = []) # {{{
29
+ content1.each do |key, value|
30
+
31
+ path = "#{(context+[key]).join(".")}"
32
+ unless content2.include?(key)
33
+ @results[@other_file][:missing] << path unless @results[@other_file][:missing].include?(path)
34
+ next
35
+ end
36
+
37
+ if value.is_a?(Hash)
38
+ compare_yaml_hash(value, content2[key], (context.dup << key))
39
+ next
40
+ end
41
+ end
42
+ end # }}}
43
+
44
+ def self.lang_from_filename(file) # {{{
45
+ file.match(/([^\/]+)\.yml$/)[1]
46
+ end # }}}
47
+
48
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: helloh
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - "R\xC3\xA9mi Pr\xC3\xA9vost"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-09-03 00:00:00 Z
18
+ dependencies: []
19
+
20
+ description: Helloh compares Rails localization files and looks for missing keys.
21
+ email: remi@exomel.com
22
+ executables:
23
+ - helloh
24
+ extensions: []
25
+
26
+ extra_rdoc_files: []
27
+
28
+ files:
29
+ - lib/helloh.rb
30
+ - README.mkd
31
+ - LICENSE
32
+ - bin/helloh
33
+ homepage: http://github.com/remiprev/helloh
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.6
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Helloh compares Rails l10n files
66
+ test_files: []
67
+