i18n-tasks 0.1.4 → 0.1.5
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 +4 -4
- data/CHANGES.md +3 -0
- data/README.md +14 -16
- data/i18n-tasks.gemspec +1 -1
- data/lib/i18n/tasks.rb +2 -5
- data/lib/i18n/tasks/base_task.rb +22 -9
- data/lib/i18n/tasks/data/yaml.rb +22 -0
- data/lib/i18n/tasks/missing.rb +1 -1
- data/lib/i18n/tasks/prefill.rb +1 -1
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/fixtures/config/i18n-tasks.yml +8 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f197d49c3a8d79992339e4ba4a23e1b9f7df23ff
|
4
|
+
data.tar.gz: 5f08596a492cfec055aab5425353dc8ec2fda1f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caedad036795f4861f8bdc1fff7309af8c1682f8e3d61779cd8aca8ab681cad1d62b922b57a8ec51eb84608d72572873bc49b5f90ee62340fb6b3e2bd53010a9
|
7
|
+
data.tar.gz: 4a185853088b92aa109b392f18cd940fb30c1aeafd98e083633034886d5a411a69c3a97f834ce7bacfa4358c00e74dd8dfa052d3b7553e031cb0efea6a19e9e1
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -59,35 +59,29 @@ ignore_unused:
|
|
59
59
|
ignore:
|
60
60
|
- kaminari.
|
61
61
|
|
62
|
-
# grep
|
62
|
+
# search configuration (grep arguments)
|
63
63
|
grep:
|
64
64
|
# search these directories (relative to your Rails.root directory, default: 'app/')
|
65
65
|
paths:
|
66
66
|
- 'app/'
|
67
|
-
- 'vendor/'
|
68
67
|
# include only files matching this glob pattern (default: blank = include all files)
|
69
68
|
include:
|
70
69
|
- '*.rb'
|
71
70
|
- '*.html*'
|
72
71
|
# explicitly exclude files (default: blank = exclude no files)
|
73
72
|
exclude: '*.js'
|
74
|
-
```
|
75
|
-
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
hash
|
86
|
-
}
|
87
|
-
}
|
74
|
+
# where to read locale data from
|
75
|
+
data:
|
76
|
+
# file patterns for a given %{locale} (supports globs)
|
77
|
+
paths:
|
78
|
+
# default:
|
79
|
+
- 'config/locales/%{locale}.yml'
|
80
|
+
# you can also implement a custom loader, use the default as an example
|
81
|
+
class: I18n::Tasks::Data::Yaml
|
88
82
|
```
|
89
83
|
|
90
|
-
##
|
84
|
+
## HTML report
|
91
85
|
|
92
86
|
While i18n-tasks does not provide an HTML version of the report, it's easy to roll your own, see [the example](https://gist.github.com/glebm/6887030).
|
93
87
|
|
@@ -95,3 +89,7 @@ While i18n-tasks does not provide an HTML version of the report, it's easy to ro
|
|
95
89
|
|
96
90
|
This was originally developed for [Zuigo](http://zuigo.com/), a platform to organize and discover events.
|
97
91
|
|
92
|
+
|
93
|
+
|
94
|
+
[](https://bitdeli.com/free "Bitdeli Badge")
|
95
|
+
|
data/i18n-tasks.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = I18n::Tasks::VERSION
|
9
9
|
spec.authors = ['glebm']
|
10
10
|
spec.email = ['glex.spb@gmail.com']
|
11
|
-
spec.summary = %q{
|
11
|
+
spec.summary = %q{Find all the missing and unused translations!}
|
12
12
|
spec.description = %q{Rails I18n tasks to find missing / unused translations and more}
|
13
13
|
spec.homepage = 'https://github.com/glebm/i18n-tasks'
|
14
14
|
spec.license = 'MIT'
|
data/lib/i18n/tasks.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
require 'i18n/tasks/version'
|
2
2
|
require 'i18n/tasks/railtie'
|
3
|
+
require 'i18n/tasks/data/yaml'
|
3
4
|
require 'active_support/hash_with_indifferent_access'
|
5
|
+
require 'active_support/core_ext/string/access'
|
4
6
|
|
5
7
|
module I18n
|
6
8
|
module Tasks
|
7
|
-
mattr_accessor :get_locale_data
|
8
|
-
self.get_locale_data = lambda { |locale|
|
9
|
-
YAML.load_file("config/locales/#{locale}.yml")
|
10
|
-
}
|
11
|
-
|
12
9
|
CONFIG_FILE = 'config/i18n-tasks.yml'
|
13
10
|
class << self
|
14
11
|
def config
|
data/lib/i18n/tasks/base_task.rb
CHANGED
@@ -9,8 +9,21 @@ module I18n
|
|
9
9
|
|
10
10
|
# locale data hash, with locale name as root
|
11
11
|
# @return [Hash{String => String,Hash}] locale data in nested hash format
|
12
|
-
def
|
13
|
-
|
12
|
+
def locale_data(locale)
|
13
|
+
locale = locale.to_s
|
14
|
+
(@locale_data ||= {})[locale] ||= data_source.get(locale)
|
15
|
+
end
|
16
|
+
|
17
|
+
def data_source
|
18
|
+
return @source if @source
|
19
|
+
conf = config[:data] || {}
|
20
|
+
@source = if conf[:class]
|
21
|
+
conf[:class].constantize.new(conf.except(:class))
|
22
|
+
else
|
23
|
+
I18n::Tasks::Data::Yaml.new(
|
24
|
+
paths: Array(conf[:paths].presence || ['config/locales/%{locale}.yml'])
|
25
|
+
)
|
26
|
+
end
|
14
27
|
end
|
15
28
|
|
16
29
|
# main locale file path (for writing to)
|
@@ -64,7 +77,7 @@ module I18n
|
|
64
77
|
|
65
78
|
# whether the value for key exists in locale (defaults: base_locale)
|
66
79
|
def key_has_value?(key, locale = base_locale)
|
67
|
-
t(
|
80
|
+
t(locale_data(locale)[locale], key).present?
|
68
81
|
end
|
69
82
|
|
70
83
|
# traverse hash, yielding with full key and value
|
@@ -72,11 +85,11 @@ module I18n
|
|
72
85
|
# @yield [full_key, value] yields full key and value for every translation in #hash
|
73
86
|
# @return [nil]
|
74
87
|
def traverse(path = '', hash)
|
75
|
-
q = [
|
88
|
+
q = [[path, hash]]
|
76
89
|
until q.empty?
|
77
90
|
path, value = q.pop
|
78
91
|
if value.is_a?(Hash)
|
79
|
-
value.each { |k,v| q << ["#{path}.#{k}", v] }
|
92
|
+
value.each { |k, v| q << ["#{path}.#{k}", v] }
|
80
93
|
else
|
81
94
|
yield path[1..-1], value
|
82
95
|
end
|
@@ -86,7 +99,7 @@ module I18n
|
|
86
99
|
# translation of the key found in the passed hash or nil
|
87
100
|
# @return [String,nil]
|
88
101
|
def t(hash, key)
|
89
|
-
key.split('.').inject(hash) { |r,seg| r[seg] if r }
|
102
|
+
key.split('.').inject(hash) { |r, seg| r[seg] if r }
|
90
103
|
end
|
91
104
|
|
92
105
|
# @param key [String] relative i18n key (starts with a .)
|
@@ -94,7 +107,7 @@ module I18n
|
|
94
107
|
# @return [String] absolute version of the key
|
95
108
|
def absolutize_key(key, path)
|
96
109
|
# normalized path
|
97
|
-
path
|
110
|
+
path = Pathname.new(File.expand_path path).relative_path_from(Pathname.new(Dir.pwd)).to_s
|
98
111
|
# key prefix based on path
|
99
112
|
prefix = path.gsub(%r(app/views/|(\.[^/]+)*$), '').tr('/', '.').gsub(%r(\._), '.')
|
100
113
|
"#{prefix}#{key}"
|
@@ -124,7 +137,7 @@ module I18n
|
|
124
137
|
|
125
138
|
# @return [Hash{String => String,Hash}] default i18n locale data
|
126
139
|
def base_locale_data
|
127
|
-
|
140
|
+
locale_data(base_locale)[base_locale]
|
128
141
|
end
|
129
142
|
|
130
143
|
# Run grep searching for source keys and return grep output
|
@@ -135,7 +148,7 @@ module I18n
|
|
135
148
|
next unless (val = grep_config[opt]).present?
|
136
149
|
args += Array(val).map { |v| "--#{opt}=#{v}" }
|
137
150
|
end
|
138
|
-
args += [
|
151
|
+
args += [%q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, *grep_config[:paths]]
|
139
152
|
args.compact!
|
140
153
|
run_command *args
|
141
154
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module I18n::Tasks
|
2
|
+
module Data
|
3
|
+
class Yaml
|
4
|
+
attr_reader :paths
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@paths = options[:paths]
|
8
|
+
end
|
9
|
+
|
10
|
+
def get(locale)
|
11
|
+
paths.map do |path|
|
12
|
+
Dir.glob path % { locale: locale }
|
13
|
+
end.flatten.map do |locale_file|
|
14
|
+
YAML.load_file locale_file
|
15
|
+
end.inject({}) do |hash, locale_data|
|
16
|
+
hash.deep_merge! locale_data
|
17
|
+
hash
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/i18n/tasks/missing.rb
CHANGED
@@ -29,7 +29,7 @@ module I18n
|
|
29
29
|
# present in base locale, but untranslated in another locale
|
30
30
|
# @return Array{Hash}
|
31
31
|
def keys_missing_translation(locale)
|
32
|
-
trn =
|
32
|
+
trn = locale_data(locale)[locale]
|
33
33
|
r = []
|
34
34
|
traverse base_locale_data do |key, base_value|
|
35
35
|
value_in_locale = t(trn, key)
|
data/lib/i18n/tasks/prefill.rb
CHANGED
@@ -6,7 +6,7 @@ module I18n
|
|
6
6
|
def perform
|
7
7
|
# Will also rewrite en, good for ordering
|
8
8
|
I18n.available_locales.map(&:to_s).each do |target_locale|
|
9
|
-
trn =
|
9
|
+
trn = locale_data(target_locale)
|
10
10
|
prefilled = { target_locale => base_locale_data }.deep_merge(trn)
|
11
11
|
File.open(locale_file_path(target_locale), 'w'){ |f| f.write prefilled.to_yaml }
|
12
12
|
end
|
data/lib/i18n/tasks/version.rb
CHANGED
@@ -31,3 +31,11 @@ grep:
|
|
31
31
|
- '*.file'
|
32
32
|
# explicitly exclude files (default: blank = exclude no files)
|
33
33
|
exclude: '*.js'
|
34
|
+
|
35
|
+
# how to get the locale data
|
36
|
+
data:
|
37
|
+
paths:
|
38
|
+
# files for a given %{locale}
|
39
|
+
- 'config/locales/%{locale}.yml'
|
40
|
+
- 'config/locales/*.%{locale}.yml'
|
41
|
+
class: I18n::Tasks::Data::Yaml
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- i18n-tasks.gemspec
|
128
128
|
- lib/i18n/tasks.rb
|
129
129
|
- lib/i18n/tasks/base_task.rb
|
130
|
+
- lib/i18n/tasks/data/yaml.rb
|
130
131
|
- lib/i18n/tasks/missing.rb
|
131
132
|
- lib/i18n/tasks/output/terminal.rb
|
132
133
|
- lib/i18n/tasks/prefill.rb
|
@@ -166,10 +167,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
167
|
version: '0'
|
167
168
|
requirements: []
|
168
169
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.1.10
|
170
171
|
signing_key:
|
171
172
|
specification_version: 4
|
172
|
-
summary:
|
173
|
+
summary: Find all the missing and unused translations!
|
173
174
|
test_files:
|
174
175
|
- spec/fixtures/app/assets/javascripts/application.js
|
175
176
|
- spec/fixtures/app/controllers/events_controller.rb
|