i18n-tasks 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/i18n/tasks/fill_tasks.rb +1 -1
- data/lib/i18n/tasks/missing_keys.rb +4 -4
- data/lib/i18n/tasks/reports/terminal.rb +1 -2
- data/lib/i18n/tasks/untranslated_keys.rb +34 -10
- data/lib/i18n/tasks/version.rb +1 -1
- data/lib/i18n/tasks.rb +3 -2
- data/lib/tasks/i18n-tasks.rake +19 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31bf9c531249255541d82c38054138c02805bdad
|
4
|
+
data.tar.gz: d58609500eff53d8ed0ddd5b5f6abb94ead03085
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b18557d8e748c7fe574f60ddda988703929b32a865fe33eb96523a33c83c92c7e2ec99191f9b5653ce8c114ebebedbbe24cccbfc3d3ebf6f928d82b542debfd
|
7
|
+
data.tar.gz: 1c584404ba07c8ec32465cc5719709d2aa41dbff76218c3cda010b5a72ea4db42824de5af66209a0c83b2f926b2b727d9a4f1095b129c34185ac5bea16536917
|
data/README.md
CHANGED
@@ -73,7 +73,7 @@ For more examples see [the tests](/spec/i18n_tasks_spec.rb).
|
|
73
73
|
Simply add to Gemfile:
|
74
74
|
|
75
75
|
```ruby
|
76
|
-
gem 'i18n-tasks', '~> 0.2.
|
76
|
+
gem 'i18n-tasks', '~> 0.2.10'
|
77
77
|
```
|
78
78
|
|
79
79
|
If you do not use Rails, you will also need to require the tasks in your Rakefile:
|
@@ -46,7 +46,7 @@ module I18n::Tasks::FillTasks
|
|
46
46
|
blank_keys = traverse_map_if(data[base_locale]) { |key, value|
|
47
47
|
key if !key_value?(key, locale) && !ignore_key?(key, :missing)
|
48
48
|
}
|
49
|
-
blank_keys +=
|
49
|
+
blank_keys += keys_not_in_base if include_missing
|
50
50
|
|
51
51
|
list = blank_keys.uniq.zip fill_with.call(blank_keys)
|
52
52
|
data[locale] = data[locale].deep_merge(list_to_tree(list))
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module I18n::Tasks::MissingKeys
|
2
2
|
# @return Array missing keys, i.e. key that are in the code but are not in the base locale data
|
3
|
-
def
|
3
|
+
def keys_not_in_base
|
4
4
|
find_source_keys.reject { |key|
|
5
5
|
key_value?(key, base_locale) || pattern_key?(key) || ignore_key?(key, :missing)
|
6
6
|
}
|
7
7
|
end
|
8
8
|
|
9
|
-
# @return Array keys missing
|
10
|
-
def
|
9
|
+
# @return Array keys missing (nil or blank?) in locale but present in base
|
10
|
+
def keys_blank_in_locale(locale)
|
11
11
|
traverse_map_if data[base_locale] do |key, base_value|
|
12
12
|
key if !ignore_key?(key, :missing) && !key_value?(key, locale) && !key_value?(depluralize_key(key), locale)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
# @return Array keys missing value (but present in base)
|
17
|
-
def
|
17
|
+
def keys_eq_base(locale)
|
18
18
|
traverse_map_if data[base_locale] do |key, base_value|
|
19
19
|
key if base_value == t(locale, key) && !ignore_key?(key, :eq_base, locale)
|
20
20
|
end
|
@@ -7,8 +7,7 @@ module I18n
|
|
7
7
|
class Terminal < Base
|
8
8
|
include Term::ANSIColor
|
9
9
|
|
10
|
-
def missing_translations(
|
11
|
-
recs = task.untranslated_keys(locales)
|
10
|
+
def missing_translations(recs = task.untranslated_keys)
|
12
11
|
print_title missing_title(recs)
|
13
12
|
if recs.present?
|
14
13
|
|
@@ -4,23 +4,47 @@ module I18n::Tasks::UntranslatedKeys
|
|
4
4
|
# :key
|
5
5
|
# :type — :blank, :missing, or :eq_base
|
6
6
|
# :base_value — translation value in base locale if one is present
|
7
|
+
# @param [Array] locales - locales for which to return missing keys
|
7
8
|
# @return [Array<Hash{Symbol => String,Symbol,nil}>]
|
8
9
|
def untranslated_keys(locales = nil)
|
9
|
-
locales
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
locales ||= self.locales
|
11
|
+
sort_key_infos(keys_not_in_base_info + keys_eq_base_info(locales) + keys_blank_in_locale_info(locales))
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Array<Hash{Symbol => String,Symbol,nil}>]
|
15
|
+
def keys_not_in_base_info
|
16
|
+
sort_key_infos keys_to_info(keys_not_in_base, locale: base_locale, type: :none)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Array<Hash{Symbol => String,Symbol,nil}>]
|
20
|
+
def keys_eq_base_info(locales = nil)
|
21
|
+
locales ||= non_base_locales
|
22
|
+
sort_key_infos (locales - [base_locale]).inject([]) { |result, locale|
|
23
|
+
result + keys_to_info(keys_eq_base(locale), locale: locale, type: :eq_base)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Array<Hash{Symbol => String,Symbol,nil}>]
|
28
|
+
def keys_blank_in_locale_info(locales = nil)
|
29
|
+
locales ||= self.locales
|
30
|
+
sort_key_infos locales.inject([]) { |result, locale|
|
31
|
+
result + keys_to_info(keys_blank_in_locale(locale), locale: locale, type: :blank)
|
32
|
+
}
|
17
33
|
end
|
18
34
|
|
19
35
|
# sort first by locale, then by type
|
20
36
|
# @return Array{Hash}
|
21
|
-
def
|
37
|
+
def sort_key_infos(keys)
|
22
38
|
keys.sort { |a, b|
|
23
|
-
|
39
|
+
by = [:locale, :type, :key].detect { |by| a[by] != b[by] }
|
40
|
+
a[by] <=> b[by]
|
24
41
|
}
|
25
42
|
end
|
43
|
+
|
44
|
+
protected
|
45
|
+
|
46
|
+
# convert the keys to a list of hashes with {key, base_value, *info}
|
47
|
+
def keys_to_info(keys, info = {})
|
48
|
+
keys.map { |key| {key: key, base_value: t(base_locale, key)}.merge(info) }
|
49
|
+
end
|
26
50
|
end
|
data/lib/i18n/tasks/version.rb
CHANGED
data/lib/i18n/tasks.rb
CHANGED
@@ -3,6 +3,7 @@ require 'active_support/core_ext/hash'
|
|
3
3
|
require 'active_support/core_ext/string'
|
4
4
|
require 'active_support/core_ext/module/delegation'
|
5
5
|
require 'active_support/core_ext/object/try'
|
6
|
+
require 'active_support/core_ext/object/blank'
|
6
7
|
require 'term/ansicolor'
|
7
8
|
require 'erubis'
|
8
9
|
require 'i18n/tasks/railtie' if defined?(Rails)
|
@@ -16,8 +17,8 @@ module I18n
|
|
16
17
|
class << self
|
17
18
|
def config
|
18
19
|
@config ||= begin
|
19
|
-
file =
|
20
|
-
file = YAML.load(Erubis::Eruby.new(file).result) if file
|
20
|
+
file = CONFIG_FILES.detect { |f| File.exists?(f) }
|
21
|
+
file = YAML.load(Erubis::Eruby.new(File.read(file)).result) if file
|
21
22
|
HashWithIndifferentAccess.new.merge(file.presence || {})
|
22
23
|
end
|
23
24
|
end
|
data/lib/tasks/i18n-tasks.rake
CHANGED
@@ -11,7 +11,24 @@ namespace :i18n do
|
|
11
11
|
|
12
12
|
desc 'show missing translations'
|
13
13
|
task :missing, [:locales] => 'i18n:setup' do |t, args|
|
14
|
-
i18n_report.missing_translations i18n_parse_locales args[:locales]
|
14
|
+
i18n_report.missing_translations i18n_tasks.untranslated_keys(i18n_parse_locales args[:locales])
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :missing do
|
18
|
+
desc 'keys present in code but not existing in base locale data'
|
19
|
+
task :not_in_base => 'i18n:setup' do
|
20
|
+
i18n_report.missing_translations i18n_tasks.keys_not_in_base_info
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'keys present but with value same as in base locale'
|
24
|
+
task :eq_base, [:locales] => 'i18n:setup' do
|
25
|
+
i18n_report.missing_translations i18n_tasks.keys_eq_base_info(i18n_parse_locales args[:locales])
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'keys that exist in base locale but are blank in passed locales'
|
29
|
+
task :blank, [:locales] => 'i18n:setup' do
|
30
|
+
i18n_report.missing_translations i18n_tasks.keys_eq_base_info(i18n_parse_locales args[:locales])
|
31
|
+
end
|
15
32
|
end
|
16
33
|
|
17
34
|
desc 'show unused translations'
|
@@ -79,7 +96,7 @@ namespace :i18n do
|
|
79
96
|
end
|
80
97
|
|
81
98
|
def i18n_parse_locales(arg = nil)
|
82
|
-
arg.try(:strip).try(:split, /\s*\+\s*/).try(:compact)
|
99
|
+
arg.try(:strip).try(:split, /\s*\+\s*/).try(:compact).try(:presence)
|
83
100
|
end
|
84
101
|
end
|
85
102
|
include ::I18n::Tasks::RakeHelpers
|
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.2.
|
4
|
+
version: 0.2.10
|
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-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|