i18n-missing_translations 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ require 'i18n'
2
+ require 'i18n/exceptions'
3
+
4
+ module I18n
5
+ class << self
6
+ attr_writer :missing_translations
7
+
8
+ def missing_translations
9
+ @missing_translations ||= MissingTranslations::Log.new
10
+ end
11
+ end
12
+
13
+ class MissingTranslations
14
+ autoload :Log, 'i18n/missing_translations/log'
15
+ autoload :Handler, 'i18n/missing_translations/handler'
16
+
17
+ attr_reader :app, :filename
18
+
19
+ def initialize(app, filename = nil)
20
+ @app = app
21
+ @filename = filename || "#{locale_dir}/missing_translations.yml"
22
+ end
23
+
24
+ def call(*args)
25
+ log.read(filename)
26
+ app.call(*args).tap { log.write(filename) }
27
+ end
28
+
29
+ def log
30
+ I18n.missing_translations
31
+ end
32
+
33
+ def locale_dir
34
+ File.directory?("#{Dir.pwd}/config/locales") ? "#{Dir.pwd}/config/locales" : Dir.pwd
35
+ end
36
+ end
37
+
38
+ ExceptionHandler.send(:include, MissingTranslations::Handler)
39
+ end
@@ -0,0 +1,10 @@
1
+ module I18n
2
+ class MissingTranslations
3
+ module Handler
4
+ def call(exception, locale, key, options)
5
+ I18n.missing_translations.log(exception.keys) if MissingTranslationData === exception
6
+ super
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ require 'yaml'
2
+
3
+ module I18n
4
+ class MissingTranslations
5
+ class Log < Hash
6
+ def log(keys)
7
+ keys = keys.dup
8
+ key = keys.pop.to_s
9
+ log = keys.inject(self) { |log, k| log.key?(k.to_s) ? log[k.to_s] : log[k.to_s] = {} }
10
+ log[key] = key.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
11
+ end
12
+
13
+ def dump(out = $stdout)
14
+ out.puts(to_yml) unless empty?
15
+ end
16
+
17
+ def read(filename)
18
+ self.replace(YAML.load_file(filename)) rescue nil
19
+ end
20
+
21
+ def write(filename)
22
+ File.open(filename, 'w+') { |f| f.write(to_yml) } unless empty?
23
+ end
24
+
25
+ def to_yml
26
+ YAML.dump(Hash[*to_a.flatten]).split("\n").map(&:rstrip).join("\n")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module I18n
2
+ class MissingTranslations
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-missing_translations
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sven Fuchs
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-06 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: test_declarative
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Find missing translations in your code more easily.
36
+ email: svenfuchs@artweb-design.de
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/i18n/missing_translations.rb
45
+ - lib/i18n/missing_translations/handler.rb
46
+ - lib/i18n/missing_translations/log.rb
47
+ - lib/i18n/missing_translations/version.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/svenfuchs/i18n-missing_translations
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project: "[none]"
78
+ rubygems_version: 1.3.7
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Find missing translations in your code more easily
82
+ test_files: []
83
+