find_t 1.0.0
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 +7 -0
- data/.gitignore +14 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/bin/find_t +7 -0
- data/find_t.gemspec +23 -0
- data/lib/find_t/cli.rb +34 -0
- data/lib/find_t/file_scanner.rb +66 -0
- data/lib/find_t/printer.rb +61 -0
- data/lib/find_t/scanner.rb +46 -0
- data/lib/find_t/version.rb +9 -0
- data/lib/find_t.rb +8 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5f634c5325b35e7168f26c2f2d9dd4f767670a01
|
4
|
+
data.tar.gz: bab008073471ca2fa9b8e308ac133f3f3ea0dd46
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e0993bfddb22efd91d58ec5ad2646785eacf46958b22e275c3ae4d1457c727af4815dd3d5a7c7ab865dc6bd5d2d0b17f586b02c2a0d3c8199315e3fad91cfc0
|
7
|
+
data.tar.gz: 1c7ef5d47d06850bb41819322b57aa8e5e40230f6312f2d2a79bbb237519a5d1b59175f1fc283b79f912befab0e1b30bc4b1c051977c2cabea319c701d333da1
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.0
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Yuki Iwanaga
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
find_t
|
2
|
+
======
|
3
|
+
|
4
|
+
**Find locale files of where translation for the key is defined.**
|
5
|
+
|
6
|
+
- Lookup all defined translations through languages
|
7
|
+
- Detect conflicts for the same translation key across files
|
8
|
+
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
|
13
|
+
```sh
|
14
|
+
$ gem install find_t
|
15
|
+
```
|
16
|
+
|
17
|
+
Or add the gem to your Gemfile.
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'find_t'
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
Synopsis
|
25
|
+
--------
|
26
|
+
|
27
|
+
```
|
28
|
+
find_t [--rails] {key}
|
29
|
+
```
|
30
|
+
|
31
|
+
| Option | Description |
|
32
|
+
| --------- | --------------------------------------------- |
|
33
|
+
| `--rails` | Include full locale files in Rails' load path |
|
34
|
+
| `{key}` | A translation key to search for |
|
35
|
+
|
36
|
+
|
37
|
+
Sample
|
38
|
+
------
|
39
|
+
|
40
|
+
```sh
|
41
|
+
$ ./bin/find_t 'exception.projectshow'
|
42
|
+
Scanning...
|
43
|
+
|
44
|
+
== en
|
45
|
+
|
46
|
+
- config/locales/99_naka/en.yml:23
|
47
|
+
"Sorry, you have to sign up to view this page!"
|
48
|
+
|
49
|
+
== ja
|
50
|
+
|
51
|
+
- config/locales/01_model/ja.yml:3
|
52
|
+
"この募集は、現在非公開です"
|
53
|
+
- config/locales/99_naka/ja.yml:23 [CONFLICTED]
|
54
|
+
"この募集は、現在非公開です"
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
License
|
59
|
+
-------
|
60
|
+
|
61
|
+
This project is copyright by [Creasty](http://www.creasty.com), released under the MIT lisence.
|
62
|
+
See `LICENSE` file for details.
|
data/Rakefile
ADDED
data/bin/find_t
ADDED
data/find_t.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'find_t/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'find_t'
|
8
|
+
spec.version = FindT::VERSION
|
9
|
+
spec.authors = ['Yuki Iwanaga']
|
10
|
+
spec.email = ['yuki@creasty.com']
|
11
|
+
spec.summary = %q{Find locale files of where translation for the key is defined}
|
12
|
+
spec.description = %q{Find locale files of where translation for the key is defined}
|
13
|
+
spec.homepage = 'https://github.com/creasty/find_t'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
end
|
data/lib/find_t/cli.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require_relative 'scanner'
|
3
|
+
require_relative 'printer'
|
4
|
+
|
5
|
+
|
6
|
+
module FindT
|
7
|
+
class CLI
|
8
|
+
|
9
|
+
def initialize(args, root_path)
|
10
|
+
@root_path = root_path
|
11
|
+
|
12
|
+
parse_options! args
|
13
|
+
|
14
|
+
@scanner = Scanner.new(
|
15
|
+
root_path: @root_path,
|
16
|
+
rails: @options['rails'],
|
17
|
+
)
|
18
|
+
|
19
|
+
run
|
20
|
+
end
|
21
|
+
|
22
|
+
private def parse_options!(args)
|
23
|
+
@options = args.getopts 'rails'
|
24
|
+
@name = args[0]
|
25
|
+
end
|
26
|
+
|
27
|
+
private def run
|
28
|
+
founds = @scanner.scan @name
|
29
|
+
printer = Printer.new @root_path
|
30
|
+
printer.print @name, founds
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module FindT
|
2
|
+
class FileScanner
|
3
|
+
|
4
|
+
YAML_HASH_PATTERN = /\A([ ]*)(["']|)(\w+)\2:\s*(.*)\s*\z/
|
5
|
+
|
6
|
+
def initialize(file)
|
7
|
+
@file = file
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(scopes)
|
11
|
+
@scopes = scopes
|
12
|
+
@size = @scopes.size - 1
|
13
|
+
|
14
|
+
@current_level = 0
|
15
|
+
@current_locale = nil
|
16
|
+
@founds = []
|
17
|
+
|
18
|
+
File.open(@file) do |f|
|
19
|
+
f.each_line.with_index do |line, n|
|
20
|
+
scan_line line, n
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@founds
|
25
|
+
end
|
26
|
+
|
27
|
+
def scan_line(line, n)
|
28
|
+
return unless line =~ YAML_HASH_PATTERN
|
29
|
+
|
30
|
+
indent, scope, text = $1, $3, $4
|
31
|
+
level = indent.size >> 1
|
32
|
+
|
33
|
+
if level == 0 && text == ''
|
34
|
+
self.locale = scope
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
if level == @current_level
|
39
|
+
if scope == current_scope
|
40
|
+
if level == @size
|
41
|
+
@founds << {
|
42
|
+
locale: @current_locale,
|
43
|
+
file: @file,
|
44
|
+
line: n + 1,
|
45
|
+
text: text,
|
46
|
+
}
|
47
|
+
elsif '' == text
|
48
|
+
@current_level = level + 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
elsif level < @current_level
|
52
|
+
@current_level = level
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private def current_scope
|
57
|
+
@scopes[@current_level]
|
58
|
+
end
|
59
|
+
|
60
|
+
private def locale=(locale)
|
61
|
+
@current_locale = locale
|
62
|
+
@current_level = 1
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
|
4
|
+
module FindT
|
5
|
+
class Printer
|
6
|
+
|
7
|
+
def initialize(root_path)
|
8
|
+
@root_path = Pathname.new root_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def print(name, founds)
|
12
|
+
unless founds.any?
|
13
|
+
print_empty name
|
14
|
+
return
|
15
|
+
end
|
16
|
+
|
17
|
+
founds
|
18
|
+
.reverse
|
19
|
+
.group_by { |f| f[:locale] }
|
20
|
+
.sort_by { |f| f[0] }
|
21
|
+
.each do |(locale, locale_founds)|
|
22
|
+
print_title locale
|
23
|
+
|
24
|
+
locale_founds.each.with_index do |found, i|
|
25
|
+
print_translation found, i.zero?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private def print_empty(name)
|
31
|
+
puts
|
32
|
+
puts "Can't find '%s'" % name
|
33
|
+
end
|
34
|
+
|
35
|
+
private def print_title(title)
|
36
|
+
puts
|
37
|
+
puts '== %s' % title
|
38
|
+
puts
|
39
|
+
end
|
40
|
+
|
41
|
+
private def print_translation(found, conflicted)
|
42
|
+
text = printable_text found[:text]
|
43
|
+
file = relative_path found[:file]
|
44
|
+
|
45
|
+
puts <<-EOS
|
46
|
+
- #{file}:#{found[:line]}#{conflicted ? '' : ' [CONFLICTED]'}
|
47
|
+
#{text}
|
48
|
+
EOS
|
49
|
+
end
|
50
|
+
|
51
|
+
private def printable_text(text)
|
52
|
+
(text == '') ? '{ ... }' : text
|
53
|
+
end
|
54
|
+
|
55
|
+
private def relative_path(file)
|
56
|
+
return file unless @root_path
|
57
|
+
Pathname.new(file).relative_path_from(@root_path).to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require_relative 'file_scanner'
|
3
|
+
|
4
|
+
|
5
|
+
module FindT
|
6
|
+
class Scanner
|
7
|
+
|
8
|
+
def initialize(root_path:, rails: false)
|
9
|
+
@root_path, @rails = Pathname.new(root_path), rails
|
10
|
+
end
|
11
|
+
|
12
|
+
def files
|
13
|
+
return @files if @files
|
14
|
+
|
15
|
+
if @rails
|
16
|
+
rails_env_file = File.expand_path @root_path.join('config', 'environment')
|
17
|
+
|
18
|
+
if File.exists? rails_env_file
|
19
|
+
require rails_env_file
|
20
|
+
else
|
21
|
+
raise RailsNotFoundError.new('Cannot find rails environment file')
|
22
|
+
end
|
23
|
+
|
24
|
+
@files = I18n.load_path
|
25
|
+
else
|
26
|
+
@files = Dir.glob @root_path.join('config', 'locales', '**', '*.{yaml,yml}')
|
27
|
+
end
|
28
|
+
|
29
|
+
@files
|
30
|
+
end
|
31
|
+
|
32
|
+
def scan(key)
|
33
|
+
return if !key || '' == key
|
34
|
+
|
35
|
+
scopes = key.split('.').unshift nil
|
36
|
+
founds = []
|
37
|
+
|
38
|
+
files.reverse.each do |file|
|
39
|
+
founds += FileScanner.new(file).find scopes
|
40
|
+
end
|
41
|
+
|
42
|
+
founds
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/find_t.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: find_t
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuki Iwanaga
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Find locale files of where translation for the key is defined
|
42
|
+
email:
|
43
|
+
- yuki@creasty.com
|
44
|
+
executables:
|
45
|
+
- find_t
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".ruby-version"
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/find_t
|
56
|
+
- find_t.gemspec
|
57
|
+
- lib/find_t.rb
|
58
|
+
- lib/find_t/cli.rb
|
59
|
+
- lib/find_t/file_scanner.rb
|
60
|
+
- lib/find_t/printer.rb
|
61
|
+
- lib/find_t/scanner.rb
|
62
|
+
- lib/find_t/version.rb
|
63
|
+
homepage: https://github.com/creasty/find_t
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.5
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Find locale files of where translation for the key is defined
|
87
|
+
test_files: []
|