i18n-extra_translations 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
require 'i18n/exceptions'
|
3
|
+
|
4
|
+
module I18n
|
5
|
+
class ExtraTranslations
|
6
|
+
autoload :Store, 'i18n/extra_translations/store.rb'
|
7
|
+
autoload :SimpleExtension, 'i18n/extra_translations/simple_extension.rb'
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_writer :extra_translations
|
11
|
+
def extra_translations
|
12
|
+
@extra_translations ||= ExtraTranslations::Store.new
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_writer :locale
|
16
|
+
def locale
|
17
|
+
@locale ||= I18n.default_locale
|
18
|
+
end
|
19
|
+
|
20
|
+
def unused_translations(filenames=nil)
|
21
|
+
filenames ||= ["./config/locales/#{locale}.yml"]
|
22
|
+
filenames.inject({}) do |memo, filename|
|
23
|
+
data = YAML.load_file(filename)
|
24
|
+
keys = all_keys_from(data, [])
|
25
|
+
memo[filename] = keys.select{|keys| !extra_translations.used?(keys)}
|
26
|
+
memo[filename].map!{|keys| keys.join('.')}
|
27
|
+
memo
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def missing_translations
|
32
|
+
keys = all_keys_from(extra_translations, [], []) do |keys, _|
|
33
|
+
!extra_translations.used?(keys)
|
34
|
+
end
|
35
|
+
keys.map{ |keys| keys.join('.') }
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def all_keys_from(data, memo, stack=[], &filter)
|
41
|
+
if data.kind_of? Hash
|
42
|
+
keys = data.inject([]) do |m, (k, v)|
|
43
|
+
m + all_keys_from(v, [], stack.dup << k, &filter)
|
44
|
+
end
|
45
|
+
memo + keys
|
46
|
+
elsif filter.nil? || filter.call(stack, data)
|
47
|
+
memo << stack
|
48
|
+
else
|
49
|
+
memo
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
Backend::Simple.include ExtraTranslations::SimpleExtension
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module I18n
|
2
|
+
class ExtraTranslations
|
3
|
+
module SimpleExtension
|
4
|
+
def translate(locale, key, options = {})
|
5
|
+
if locale == I18n::ExtraTranslations.locale
|
6
|
+
result = catch :exception do
|
7
|
+
_val = super
|
8
|
+
I18n::ExtraTranslations.extra_translations.use(locale, key, options)
|
9
|
+
_val
|
10
|
+
end
|
11
|
+
if result.kind_of? I18n::MissingTranslation
|
12
|
+
I18n::ExtraTranslations.extra_translations.miss(locale, key, options)
|
13
|
+
throw :exception, result
|
14
|
+
else
|
15
|
+
result
|
16
|
+
end
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module I18n
|
2
|
+
class ExtraTranslations
|
3
|
+
class Store < Hash
|
4
|
+
def use(l, k, o) ; add_key(l, k , o, :used) end
|
5
|
+
def miss(l, k, o) ; add_key(l, k, o, :missing) end
|
6
|
+
|
7
|
+
def used?(keys)
|
8
|
+
keys.inject(self){ |h, k| h.kind_of?(Hash) ? h[k] : (break h[k]) } == :used rescue false
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def add_key(l, k, o, value)
|
14
|
+
keys = I18n.normalize_keys(l, k, o[:scope]).dup
|
15
|
+
l = keys.pop.to_s
|
16
|
+
h = keys.inject(self) { |h, k| h.key?(k.to_s) ? h[k.to_s] : (h[k.to_s] = {}) }
|
17
|
+
h[l] = value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n-extra_translations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nicolas ZERMATI
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: i18n
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.4
|
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.6.4
|
30
|
+
description: Find missing and extra translations in Rails application.
|
31
|
+
email:
|
32
|
+
- nicoolas25@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/i18n/extra_translations.rb
|
38
|
+
- lib/i18n/extra_translations/simple_extension.rb
|
39
|
+
- lib/i18n/extra_translations/store.rb
|
40
|
+
homepage: https://github.com/nicoolas25/i18n-extra_translations
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.23
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Find missing and extra translations in Rails application.
|
64
|
+
test_files: []
|