i18n-tasks 0.2.19 → 0.2.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +5 -1
  3. data/LICENSE.txt +1 -1
  4. data/README.md +51 -39
  5. data/doc/img/i18n-usages.png +0 -0
  6. data/i18n-tasks.gemspec +1 -1
  7. data/lib/i18n/tasks.rb +7 -2
  8. data/lib/i18n/tasks/base_task.rb +2 -4
  9. data/lib/i18n/tasks/configuration.rb +2 -4
  10. data/lib/i18n/tasks/data/adapter/json_adapter.rb +22 -0
  11. data/lib/i18n/tasks/data/adapter/yaml_adapter.rb +21 -0
  12. data/lib/i18n/tasks/data/file_system.rb +13 -0
  13. data/lib/i18n/tasks/data/storage/file_storage.rb +105 -0
  14. data/lib/i18n/tasks/data/yaml.rb +6 -65
  15. data/lib/i18n/tasks/data_traversal.rb +2 -2
  16. data/lib/i18n/tasks/fill_tasks.rb +2 -11
  17. data/lib/i18n/tasks/ignore_keys.rb +3 -1
  18. data/lib/i18n/tasks/key.rb +60 -0
  19. data/lib/i18n/tasks/key_group.rb +65 -0
  20. data/lib/i18n/tasks/missing_keys.rb +51 -18
  21. data/lib/i18n/tasks/reports/base.rb +8 -4
  22. data/lib/i18n/tasks/reports/spreadsheet.rb +8 -8
  23. data/lib/i18n/tasks/reports/terminal.rb +39 -16
  24. data/lib/i18n/tasks/scanners/base_scanner.rb +36 -2
  25. data/lib/i18n/tasks/scanners/pattern_scanner.rb +9 -7
  26. data/lib/i18n/tasks/translation_data.rb +4 -1
  27. data/lib/i18n/tasks/unused_keys.rb +9 -7
  28. data/lib/i18n/tasks/{source_keys.rb → used_keys.rb} +5 -6
  29. data/lib/i18n/tasks/version.rb +1 -1
  30. data/lib/tasks/i18n-tasks.rake +24 -20
  31. data/spec/file_system_data_spec.rb +68 -0
  32. data/spec/fixtures/config/i18n-tasks.yml +2 -2
  33. data/spec/i18n_tasks_spec.rb +5 -5
  34. data/spec/key_group_spec.rb +48 -0
  35. data/spec/used_keys_spec.rb +22 -0
  36. metadata +17 -7
  37. data/lib/i18n/tasks/untranslated_keys.rb +0 -50
  38. data/spec/yaml_adapter_spec.rb +0 -33
@@ -1,50 +0,0 @@
1
- module I18n::Tasks::UntranslatedKeys
2
- # Get all the missing translations as an array of missing keys as hashes with the following options:
3
- # :locale
4
- # :key
5
- # :type — :blank, :missing, or :eq_base
6
- # :base_value — translation value in base locale if one is present
7
- # @param [Array] locales - locales for which to return missing keys
8
- # @return [Array<Hash{Symbol => String,Symbol,nil}>]
9
- def untranslated_keys(locales = nil)
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
- }
33
- end
34
-
35
- # sort first by locale, then by type
36
- # @return Array{Hash}
37
- def sort_key_infos(keys)
38
- keys.sort { |a, b|
39
- by = [:locale, :type, :key].detect { |by| a[by] != b[by] }
40
- a[by] <=> b[by]
41
- }
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
50
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'YAML adapter' do
4
- describe 'options' do
5
- let!(:data) { I18n::Tasks::Data::Yaml.new }
6
- after { TestCodebase.teardown }
7
-
8
- it 'reads' do
9
- data.config = {read: ['a.yml', '{b,c}.yml']}
10
- TestCodebase.setup(
11
- 'a.yml' => {en: {a: 1}}.stringify_keys.to_yaml,
12
- 'b.yml' => {en: {b: 1}}.stringify_keys.to_yaml,
13
- 'c.yml' => {en: {c: 1}}.stringify_keys.to_yaml
14
- )
15
- TestCodebase.in_test_app_dir {
16
- data[:en].should == {a: 1, b: 1, c: 1}
17
- }
18
- end
19
-
20
- it 'writes' do
21
- data.config = {read: 'a.yml', write: [['{:}.*', '\1.%{locale}.yml']]}
22
- keys = {'a' => {'b' => 'c'}, 'x' => 'y'}
23
- locale_data = {'pizza' => keys, 'sushi' => keys}
24
- TestCodebase.setup
25
- TestCodebase.in_test_app_dir {
26
- data[:en] = locale_data
27
- files = %w(pizza.en.yml sushi.en.yml)
28
- Dir['*.yml'].sort.should == files.sort
29
- files.each { |f| YAML.load_file(f)['en'].should == {File.basename(f, '.en.yml') => keys} }
30
- }
31
- end
32
- end
33
- end