i18n-tasks 0.2.9 → 0.2.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1264889059f8de7a6a8c40a6dfb00416c3ee2286
4
- data.tar.gz: 26e908eddb28eed053d793d5dfb855ce22233b5d
3
+ metadata.gz: 31bf9c531249255541d82c38054138c02805bdad
4
+ data.tar.gz: d58609500eff53d8ed0ddd5b5f6abb94ead03085
5
5
  SHA512:
6
- metadata.gz: fc33b2dd662033c1add64d55a02c337d917d4a3c1eb205480fc035ba92990ff593afca1117810f25eee75843a7bb873b5cdc124f9114cb8dc5f53978828af43a
7
- data.tar.gz: 671318d2d1e6a615960ea71890f20a5ce2999c3b4b5a393420e4a65f08f94cfe6e39059885aae5358ddf7e4fa3bebab174defb0fde164efc06ac878cbd17bb8d
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.9'
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 += keys_missing_from_base if include_missing
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 keys_missing_from_base
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 value (but present in base)
10
- def keys_missing_value(locale)
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 keys_where_value_eq_base(locale)
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(locales = nil)
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 = self.non_base_locales if !locales || locales.empty?
10
- keys = keys_missing_from_base.map { |key| {locale: base_locale, key: key, type: :none} } +
11
- locales.map { |locale|
12
- keys_missing_value(locale).map { |key| {locale: locale, key: key, type: :blank, base_value: t(base_locale, key)}} + keys_where_value_eq_base(locale).map { |key|
13
- {locale: locale, key: key, type: :eq_base, base_value: t(base_locale, key)}
14
- }
15
- }.flatten
16
- sort_keys keys
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 sort_keys(keys)
37
+ def sort_key_infos(keys)
22
38
  keys.sort { |a, b|
23
- (l = a[:locale] <=> b[:locale]).zero? ? a[:type] <=> b[:type] : l
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
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Tasks
3
- VERSION = '0.2.9'
3
+ VERSION = '0.2.10'
4
4
  end
5
5
  end
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 = File.read(CONFIG_FILES.detect { |f| File.exists?(f) })
20
- file = YAML.load(Erubis::Eruby.new(file).result) if file.present?
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
@@ -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.9
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-29 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake