i18n-tasks 0.0.6 → 0.0.7

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: 44720a334107603e5ebb7fc2c579dedaf2187b12
4
- data.tar.gz: 544cc1eac74d0e503bfc4251b8de2f6349013ec9
3
+ metadata.gz: 249e36d0665a2fda7758aede212244f485083b54
4
+ data.tar.gz: 149073894264064e8972f43833fdffb4df4d2e18
5
5
  SHA512:
6
- metadata.gz: 1c7c8c3304432ef68a539bea0ec9bddc5c1cd5674c7113f31cbbc5c263b291af69aa79e1621307c69707fd7bbadf98d95cb4add710dd476e88b864d2ee0af4c9
7
- data.tar.gz: 0af4770fb9a6345f8b3859731d39ce73346a3f0d0ae4421f9b900a4baf16926171865504eb54a23c1eda151a1eefce72ef73e47e160b1aa539990e620ebf21ed
6
+ metadata.gz: 772c68ce93f166f9c41886a3de694088031efb5433dd58cb8f3da032c91a3a5be3b55027d460a29f63ee2a41c7f9ad7d033a5d1abe4bb8693ea3cb175b409c3b
7
+ data.tar.gz: 354dd75548fc81da5eb335be15472dcf96fcd269e8c6ff077ec1c44833a10011e2aea69aecd79a8e1b93cde6a9b478ba56e6a8ca38eca89f6f431dcd202a44f9
data/README.md CHANGED
@@ -16,11 +16,12 @@ Use `rake -T i18n` to get the list of tasks with descriptions. There are 3 tasks
16
16
  t 'category.' + category.key # 'category.arts_and_crafts' considered used
17
17
  t "category.#{category.key}" # also works
18
18
 
19
- `i18n:missing` may incorrectly show framework i18n keys as missing, to work around this use `.i18nignore` file in project root:
19
+ Relative keys (`t '.title'`) are supported too.
20
20
 
21
- devise.errors.unauthorized # ignore this key
22
- pagination.views. # ignore the whole pattern (note the .)
21
+ `i18n:missing` may incorrectly show framework i18n keys as missing, to work around this use `.i18nignore` file in project root:
23
22
 
23
+ devise.errors.unauthorized # ignore this key
24
+ pagination.views. # ignore the whole pattern (note the .)
24
25
 
25
26
  For more examples see [the tests](https://github.com/glebm/i18n-tasks/blob/master/spec/i18n_tasks_spec.rb#L43-L59).
26
27
 
@@ -29,7 +30,7 @@ Installation
29
30
 
30
31
  Simply add to Gemfile:
31
32
 
32
- gem 'i18n-tasks', '~> 0.0.5'
33
+ gem 'i18n-tasks', '~> 0.0.7'
33
34
 
34
35
  Configuration
35
36
  -------------
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'open3'
2
3
  require 'term/ansicolor'
3
4
 
@@ -22,11 +23,24 @@ module I18n
22
23
  "config/locales/#{locale}.yml"
23
24
  end
24
25
 
25
- # find all keys in the source
26
+ # find all keys in the source (relative keys are returned in absolutized)
26
27
  def find_source_keys
27
28
  @source_keys ||= begin
28
- grep_out = run_command 'grep', '-horI', %q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, 'app/'
29
- used_keys = grep_out.split("\n").map { |r| r.match(/['"](.*?)['"]/)[1] }.uniq.to_set
29
+ grep_out = run_command 'grep', '-HorI', %q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, 'app/'
30
+ used_keys = grep_out.split("\n").map { |r|
31
+ key = r.match(/['"](.*?)['"]/)[1]
32
+ # absolutize relative key:
33
+ if key.start_with?('.')
34
+ path = r.split(':')[0]
35
+ # normalized path
36
+ path = Pathname.new(File.expand_path path).relative_path_from(Pathname.new(Dir.pwd)).to_s
37
+ # key prefix based on path
38
+ prefix = path.gsub(%r(app/views/|(\.[^/]+)*$), '').tr('/', '.')
39
+ "#{prefix}#{key}"
40
+ else
41
+ key
42
+ end
43
+ }.uniq.to_set
30
44
  used_keys = used_keys.reject { |k| k !~ /^[\w.\#{}]+$/ }
31
45
  exclude_patterns used_keys, ignore_patterns
32
46
  end
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Tasks
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  end
@@ -33,40 +33,44 @@ describe 'rake i18n' do
33
33
  'unused' => {'a' => v},
34
34
  'missing_in_es' => {'a' => v},
35
35
  'same_in_es' => {'a' => v},
36
- 'blank_in_es' => {'a' => v}
36
+ 'blank_in_es' => {'a' => v},
37
+ 'relative' => {'index' => {'title' => v}}
37
38
  }
38
39
  }
39
40
 
40
- en_data = gen_data.('EN_TEXT')
41
- es_data = gen_data.('ES_TEXT').except('missing_in_es')
42
- es_data['same_in_es']['a'] = 'EN_TEXT'
43
- es_data['blank_in_es']['a'] = ''
41
+ en_data = gen_data.('EN_TEXT')
42
+ es_data = gen_data.('ES_TEXT').except('missing_in_es')
43
+ es_data['same_in_es']['a'] = 'EN_TEXT'
44
+ es_data['blank_in_es']['a'] = ''
44
45
 
45
46
  fs = {
46
- 'config/locales/en.yml' => {'en' => en_data}.to_yaml,
47
- 'config/locales/es.yml' => {'es' => es_data}.to_yaml,
48
- '.i18nignore' => <<-TEXT,
49
- ignored_missing_key.a # one key to ignore
47
+ 'config/locales/en.yml' => {'en' => en_data}.to_yaml,
48
+ 'config/locales/es.yml' => {'es' => es_data}.to_yaml,
49
+ '.i18nignore' => <<-TEXT,
50
+ ignored_missing_key.a # one key to ignore
50
51
 
51
- ignored_pattern. # ignore the whole pattern
52
+ ignored_pattern. # ignore the whole pattern
52
53
  TEXT
53
54
  'app/views/index.html.slim' => <<-SLIM,
54
55
  p \#{t('ca.a')} \#{t 'ca.b'} \#{t "ca.c"}
55
- p \#{t 'ca.d'} \#{t 'ca.f', i: 'world'} \#{t 'ca.e', i: 'world'}
56
- p \#{t 'missing_in_es.a'} \#{t 'same_in_es.a'} \#{t 'blank_in_es.a'}
57
- p = t 'used_but_missing.a'
58
- p = t 'ignored_missing_key.a'
59
- p = t 'ignored_pattern.some_key'
56
+ p \#{t 'ca.d'} \#{t 'ca.f', i: 'world'} \#{t 'ca.e', i: 'world'}
57
+ p \#{t 'missing_in_es.a'} \#{t 'same_in_es.a'} \#{t 'blank_in_es.a'}
58
+ p = t 'used_but_missing.a'
59
+ p = t 'ignored_missing_key.a'
60
+ p = t 'ignored_pattern.some_key'
61
+ SLIM
62
+ 'app/views/relative/index.html.slim' => <<-SLIM,
63
+ p = t '.title'
60
64
  SLIM
61
65
  'app/controllers/events_controller.slim' => <<-RUBY,
62
66
  class EventsController < ApplicationController
63
- def show
64
- redirect_to :edit, notice: I18n.t('cb.a')
65
- I18n.t("cb.b", i: "Hello")
66
- I18n.t("hash_pattern.\#{some_value}", i: "Hello")
67
- I18n.t("hash_pattern2." + some_value, i: "Hello")
68
- end
69
- end
67
+ def show
68
+ redirect_to :edit, notice: I18n.t('cb.a')
69
+ I18n.t("cb.b", i: "Hello")
70
+ I18n.t("hash_pattern.\#{some_value}", i: "Hello")
71
+ I18n.t("hash_pattern2." + some_value, i: "Hello")
72
+ end
73
+ end
70
74
  RUBY
71
75
  }
72
76
  TestCodebase.setup fs
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.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-10 00:00:00.000000000 Z
11
+ date: 2013-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails