i18n-tasks 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3695a5c801e3826fc8ec81bdf35d1ce830dae4f4
4
- data.tar.gz: 3f0dceded74c9f668ae316dfd72ba1c1154d713b
3
+ metadata.gz: f116de755ba0474543cb353a777bf20e7eeab5ac
4
+ data.tar.gz: 2850693394e00b2c1aad7421695aa4d42d4c4f45
5
5
  SHA512:
6
- metadata.gz: 8f93118329d8599262d2b2443a5631b6cd6bb4adb1395b8f2e467fb70432939ffafe577b943f04eef2be6304ff274facc0454e4229becceda3b07087f55c96a0
7
- data.tar.gz: 75f103be804ab756261c00dc318ea7669a3f20d92e7f4a9cb5223ba6ae60cf3af6d0b1d5d5dfc4fe8f8d9ddf05e41321f1d0e05ef3c711f24ad7af057e46b379
6
+ metadata.gz: 85aa544fd0af018aade6cf796efbfbd20028a0f296b06f48e4f4c9941fa1c79862ecd5a31c9f8aa34d0abc9908d3dd6c1a56a696557e99a10d55866a4c3d4363
7
+ data.tar.gz: cc88b01eb13bbe1c00e3d3ef89f2ec239f4b673a124cb436dc612ced9c318bd977baa32bc8daf50ae62fcfe4b7161afa686bc4225484a4598f380e7f4fded9bf
data/README.md CHANGED
@@ -13,8 +13,10 @@ Use `rake -T i18n` to get the list of tasks with descriptions. There are 3 tasks
13
13
 
14
14
  `i18n:unused` will detect pattern translations and not report them, e.g.:
15
15
 
16
- t 'category.' + category.key # 'category.arts_and_crafts' considered used
17
- t "category.#{category.key}" # also works
16
+ ```ruby
17
+ t 'category.' + category.key # 'category.arts_and_crafts' considered used
18
+ t "category.#{category.key}" # also works
19
+ ```
18
20
 
19
21
  Relative keys (`t '.title'`) are supported too.
20
22
 
@@ -25,7 +27,11 @@ Installation
25
27
 
26
28
  Simply add to Gemfile:
27
29
 
28
- gem 'i18n-tasks', '~> 0.1.0'
30
+ ```ruby
31
+ gem 'i18n-tasks', '~> 0.1.0'
32
+ ```
33
+
34
+ `grep` is required. You likely have it already on Linux / Mac / BSD, Windows users will need to [install](http://gnuwin32.sourceforge.net/packages/grep.htm) and make sure it's available in `PATH`.
29
35
 
30
36
  Configuration
31
37
  -------------
@@ -33,36 +39,44 @@ Configuration
33
39
 
34
40
  Tasks may incorrectly report framework i18n keys as missing. You can add `config/i18n-tasks.yml` to work around this:
35
41
 
36
- # do not report these keys as missing (both on blank value and no key)
37
- ignore_missing:
38
- - devise.errors.unauthorized # ignore this key
39
- - pagination.views. # ignore the whole pattern (note the .)
42
+ ```yaml
43
+ # do not report these keys as missing (both on blank value and no key)
44
+ ignore_missing:
45
+ - devise.errors.unauthorized # ignore this key
46
+ - pagination.views. # ignore the whole pattern (note the .)
40
47
 
41
- # do not report these keys when they have the same value as the base locale version
42
- ignore_eq_base:
43
- all:
44
- - common.ok
45
- es,fr:
46
- - common.brand
48
+ # do not report these keys when they have the same value as the base locale version
49
+ ignore_eq_base:
50
+ all:
51
+ - common.ok
52
+ es,fr:
53
+ - common.brand
47
54
 
48
- # do not report these keys as unused
49
- ignore_unused:
50
- - category.
55
+ # do not report these keys as unused
56
+ ignore_unused:
57
+ - category.
51
58
 
52
- # do not report these keys ever
53
- ignore:
54
- - kaminari.
59
+ # do not report these keys ever
60
+ ignore:
61
+ - kaminari.
62
+ ```
55
63
 
56
64
 
57
65
  By default reports I18n reads locale data from `config/locales/{locale_code}.yml`.
58
66
  You can customize this, e.g.:
59
67
 
60
- # load all config/locales/*.locale.yml and config/locales/locale.yml:
61
- I18n::Tasks.get_locale_data = ->(locale) {
62
- (["config/locales/#{locale}.yml"] + Dir["config/locales/*.#{locale}.yml"]).inject({}) { |hash, path|
63
- hash.deep_merge! YAML.load_file(path)
64
- hash
65
- }
66
- }
68
+ ```ruby
69
+ # load all config/locales/*.locale.yml and config/locales/locale.yml:
70
+ I18n::Tasks.get_locale_data = ->(locale) {
71
+ (["config/locales/#{locale}.yml"] + Dir["config/locales/*.#{locale}.yml"]).inject({}) { |hash, path|
72
+ hash.deep_merge! YAML.load_file(path)
73
+ hash
74
+ }
75
+ }
76
+ ```
77
+
78
+ ---
79
+
80
+ This was originally developed for [Zuigo](http://zuigo.com/), a platform to organize and discover events.
67
81
 
68
82
  [i18n-missing-screenshot]: https://raw.github.com/glebm/i18n-tasks/master/doc/img/i18n-missing.png "rake i18n:missing output screenshot"
@@ -22,21 +22,25 @@ module I18n
22
22
  def find_source_keys
23
23
  @source_keys ||= begin
24
24
  grep_out = run_command 'grep', '-HorI', %q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, 'app/'
25
- used_keys = grep_out.split("\n").map { |r|
26
- key = r.match(/['"](.*?)['"]/)[1]
27
- # absolutize relative key:
28
- if key.start_with? '.'
29
- path = r.split(':')[0]
30
- # normalized path
31
- path = Pathname.new(File.expand_path path).relative_path_from(Pathname.new(Dir.pwd)).to_s
32
- # key prefix based on path
33
- prefix = path.gsub(%r(app/views/|(\.[^/]+)*$), '').tr('/', '.')
34
- "#{prefix}#{key}"
35
- else
36
- key
37
- end
38
- }.uniq
39
- used_keys.reject { |k| k !~ /^[\w.\#{}]+$/ }
25
+ if grep_out
26
+ used_keys = grep_out.split("\n").map { |r|
27
+ key = r.match(/['"](.*?)['"]/)[1]
28
+ # absolutize relative key:
29
+ if key.start_with? '.'
30
+ path = r.split(':')[0]
31
+ # normalized path
32
+ path = Pathname.new(File.expand_path path).relative_path_from(Pathname.new(Dir.pwd)).to_s
33
+ # key prefix based on path
34
+ prefix = path.gsub(%r(app/views/|(\.[^/]+)*$), '').tr('/', '.')
35
+ "#{prefix}#{key}"
36
+ else
37
+ key
38
+ end
39
+ }.uniq
40
+ used_keys.reject { |k| k !~ /^[\w.\#{}]+$/ }
41
+ else
42
+ []
43
+ end
40
44
  end
41
45
  end
42
46
 
@@ -17,7 +17,7 @@ module I18n
17
17
  eq_base: yellow(bold "=".ljust(6))
18
18
  }
19
19
 
20
- missing.sort_by { |m| m[:type] }.reverse_each do |m|
20
+ missing.sort { |a, b| (l = a[:locale] <=> b[:locale]).zero? ? a[:type] <=> b[:type] : l }.each do |m|
21
21
  locale, key, base_value = m[:locale], m[:key], m[:base_value]
22
22
  status_text = ' ' + status_texts[m[:type]]
23
23
  case m[:type]
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Tasks
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-29 00:00:00.000000000 Z
11
+ date: 2013-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails