i18n_checker 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.editorconfig +7 -0
- data/.gitignore +52 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +65 -0
- data/LICENSE +21 -0
- data/README.md +36 -0
- data/Rakefile +12 -0
- data/i18n-checker.gemspec +29 -0
- data/lib/i18n_checker.rb +18 -0
- data/lib/i18n_checker/detector/detected_result.rb +11 -0
- data/lib/i18n_checker/detector/locale_text_not_found.rb +27 -0
- data/lib/i18n_checker/detector/locale_text_result.rb +26 -0
- data/lib/i18n_checker/haml.rb +21 -0
- data/lib/i18n_checker/haml/locale_text.rb +13 -0
- data/lib/i18n_checker/haml/locale_text_collector.rb +44 -0
- data/lib/i18n_checker/haml/locale_texts.rb +32 -0
- data/lib/i18n_checker/locale.rb +15 -0
- data/lib/i18n_checker/locale/key_path.rb +27 -0
- data/lib/i18n_checker/locale/locale_file.rb +44 -0
- data/lib/i18n_checker/locale/locale_files.rb +23 -0
- data/lib/i18n_checker/locale_text_not_found_checker.rb +18 -0
- data/lib/i18n_checker/rake_task.rb +46 -0
- data/lib/i18n_checker/reporter.rb +7 -0
- data/lib/i18n_checker/reporter/default_reporter.rb +15 -0
- data/lib/i18n_checker/reporter/detect_result_reporter.rb +15 -0
- data/lib/i18n_checker/version.rb +4 -0
- data/screenshot.png +0 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eeadfe2648e8307a91723cd864028358d61d7166
|
4
|
+
data.tar.gz: 3a3bcdca253193a73eb1f52d1a7430cd1a431a9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d75dfdb71467504c5849acae023c2f589ba6b97ca33587ad445c39c54f4ce4b2f13249f59b91afcc66e3e21280b6499c914121a9ce482e4ec15c79e42d49efe2
|
7
|
+
data.tar.gz: efa70b08c82e011c7637f48ec48b960fd3c51ffbea3bf0f6dec83d03f6d03c51e5356fef996a7ee83f04d15da910be3bcf5e57468fede1c248723239e45804a6
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
51
|
+
|
52
|
+
.DS_Store
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
language: ruby
|
2
|
+
env:
|
3
|
+
secure: vP9dkxMYLlLK+d/Km4bp7LJC29yiTV+LOHDoHrkFRfIxlqEaUwSUmSaX0B2WGhyZDQk6x2wAvpnnvtIF9C5VdRq8Tow8Dc0kq2OfiVYp4pu0ObHytkED2trLU3kdn1FSSAL0a/OWVsnp4M1pbZVryfzh8DGTpb+5yUNtK1A91GB8A80M5GK3XZTxgZeM5ghUHGEx5DB8iLvPHiTplsq6VB7L1GbRD3eNlZpiyoWBPNDAXBgAJSFTe7TBfvQyQX3DB/DXbZ5u0uz4QV2g7Af37aFfDfdyu1ZcLP7tUpuCp2qP5GER9Sz27hhbLIWj/lZmJtmGo/QZB8m11h1r7/7kqcIITWuzzctv2vvuhfoBjCsH68p3AvejzFWlxSwT6tiUOvH2oQYoo5aT0YHV2BmrkrbLBdcTxpAIWVX5Z1ByM/uOO1GtLrLSeRip9V1M5rJU6kSvxLDMy65JVtg0Ma+6WIkVM2JJgTDL4hmmt6CXiqVDZicBwU6bePsc8OXr1Khb1wb3Q48U7IC5iIOB6JaTj1OR63iFGwgzIDpOiXV+bxgNFPmKN3MgAh4CbeETjrR7W66ncblldq2AHqWH/U3FO9EaSIKZH8lWX0ocOkq3YzpceechmPZGIrrO1+5VyMrw556AeKPkrXzrAWsEs2fvxrlDKaTw6VguK1glYOG8+9M=
|
4
|
+
rvm:
|
5
|
+
- 2.1
|
6
|
+
- 2.2
|
7
|
+
- 2.3.0
|
8
|
+
- 2.4.0
|
9
|
+
cache: bundler
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
i18n_checker (0.1.0)
|
5
|
+
colorator (~> 1.1.0)
|
6
|
+
haml_parser (~> 0.4)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ansi (1.5.0)
|
12
|
+
colorator (1.1.0)
|
13
|
+
coveralls (0.8.19)
|
14
|
+
json (>= 1.8, < 3)
|
15
|
+
simplecov (~> 0.12.0)
|
16
|
+
term-ansicolor (~> 1.3)
|
17
|
+
thor (~> 0.19.1)
|
18
|
+
tins (~> 1.6)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
docile (1.1.5)
|
21
|
+
haml_parser (0.4.1)
|
22
|
+
hirb (0.7.3)
|
23
|
+
json (2.0.3)
|
24
|
+
rake (10.5.0)
|
25
|
+
rspec (3.5.0)
|
26
|
+
rspec-core (~> 3.5.0)
|
27
|
+
rspec-expectations (~> 3.5.0)
|
28
|
+
rspec-mocks (~> 3.5.0)
|
29
|
+
rspec-core (3.5.4)
|
30
|
+
rspec-support (~> 3.5.0)
|
31
|
+
rspec-expectations (3.5.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.5.0)
|
34
|
+
rspec-mocks (3.5.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.5.0)
|
37
|
+
rspec-support (3.5.0)
|
38
|
+
simplecov (0.12.0)
|
39
|
+
docile (~> 1.1.0)
|
40
|
+
json (>= 1.8, < 3)
|
41
|
+
simplecov-html (~> 0.10.0)
|
42
|
+
simplecov-console (0.4.1)
|
43
|
+
ansi
|
44
|
+
hirb
|
45
|
+
simplecov
|
46
|
+
simplecov-html (0.10.0)
|
47
|
+
term-ansicolor (1.4.0)
|
48
|
+
tins (~> 1.0)
|
49
|
+
thor (0.19.4)
|
50
|
+
tins (1.13.2)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
bundler (~> 1.14)
|
57
|
+
coveralls
|
58
|
+
i18n_checker!
|
59
|
+
rake (~> 10.0)
|
60
|
+
rspec
|
61
|
+
simplecov
|
62
|
+
simplecov-console
|
63
|
+
|
64
|
+
BUNDLED WITH
|
65
|
+
1.14.6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Noritaka Horio
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# i18n-checker
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/holyshared/i18n-checker.svg?branch=master)](https://travis-ci.org/holyshared/i18n-checker)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/holyshared/i18n-checker/badge.svg?branch=master)](https://coveralls.io/github/holyshared/i18n-checker?branch=master)
|
5
|
+
|
6
|
+
![Screen shot](https://github.com/holyshared/i18n-checker/blob/master/screenshot.png?raw=true)
|
7
|
+
|
8
|
+
This gem provides a **Rake task** to check translation file mistakes and translated text references from template files etc.
|
9
|
+
|
10
|
+
In the current version you can check the translation text reference from Haml's template file.
|
11
|
+
|
12
|
+
## Basic usage
|
13
|
+
|
14
|
+
Add the following tasks to your **Rakefile**.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require 'i18n_checker/rake_task'
|
18
|
+
|
19
|
+
I18nChecker::RakeTask.new do |task|
|
20
|
+
task.locale_file_paths = FileList['spec/fixtures/locales/**'] # locale file paths
|
21
|
+
task.haml_template_paths = FileList['spec/fixtures/*'] # haml template paths
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
After that we just execute the task.
|
26
|
+
|
27
|
+
```shell
|
28
|
+
bundle exec rake locale_check
|
29
|
+
```
|
30
|
+
|
31
|
+
## Run the test
|
32
|
+
|
33
|
+
```shell
|
34
|
+
bundle install
|
35
|
+
bundle exec rake spec
|
36
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'i18n_checker/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
I18nChecker::RakeTask.new do |task|
|
8
|
+
task.locale_file_paths = FileList['spec/fixtures/locales/**']
|
9
|
+
task.haml_template_paths = FileList['spec/fixtures/*']
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :spec
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'i18n_checker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "i18n_checker"
|
8
|
+
spec.version = I18nChecker::VERSION
|
9
|
+
spec.authors = ["holyshared"]
|
10
|
+
spec.email = ["holy.shared.design@gmail.com"]
|
11
|
+
spec.summary = "i18n checker for haml"
|
12
|
+
spec.description = "It parses the haml template and checks the validity of the language file"
|
13
|
+
spec.homepage = "https://github.com/holyshared/i18n-checker"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.add_dependency 'haml_parser', '~> 0.4'
|
22
|
+
spec.add_dependency 'colorator', '~> 1.1.0'
|
23
|
+
spec.add_development_dependency 'bundler','~> 1.14'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'simplecov'
|
27
|
+
spec.add_development_dependency 'simplecov-console'
|
28
|
+
spec.add_development_dependency 'coveralls'
|
29
|
+
end
|
data/lib/i18n_checker.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "i18n_checker/version"
|
2
|
+
require "i18n_checker/rake_task"
|
3
|
+
require "i18n_checker/haml/locale_text"
|
4
|
+
require "i18n_checker/haml/locale_texts"
|
5
|
+
require "i18n_checker/haml/locale_text_collector"
|
6
|
+
require "i18n_checker/locale"
|
7
|
+
require "i18n_checker/locale/key_path"
|
8
|
+
require "i18n_checker/locale/locale_file"
|
9
|
+
require "i18n_checker/locale/locale_files"
|
10
|
+
require "i18n_checker/detector/locale_text_not_found"
|
11
|
+
require "i18n_checker/detector/locale_text_result"
|
12
|
+
require "i18n_checker/detector/detected_result"
|
13
|
+
require "i18n_checker/reporter/detect_result_reporter"
|
14
|
+
require "i18n_checker/reporter/default_reporter"
|
15
|
+
require "i18n_checker/locale_text_not_found_checker"
|
16
|
+
|
17
|
+
module I18nChecker
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module I18nChecker
|
2
|
+
module Detector
|
3
|
+
class LocaleTextNotFound
|
4
|
+
def initialize(locale_files)
|
5
|
+
@locale_files = locale_files
|
6
|
+
end
|
7
|
+
|
8
|
+
def detect(locale_texts)
|
9
|
+
results = locale_texts.map { |local_text| detect_not_found(local_text) }
|
10
|
+
DetectedResult.new(results.compact.flatten)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def detect_not_found(locale_text)
|
16
|
+
locale_files = @locale_files.dup
|
17
|
+
locale_files.delete_if { |locale_file| locale_file.include?(locale_text) }
|
18
|
+
locale_files.map do |locale_file|
|
19
|
+
LocaleTextResult.new(
|
20
|
+
locale_text: locale_text,
|
21
|
+
locale_file: locale_file
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module I18nChecker
|
2
|
+
module Detector
|
3
|
+
class LocaleTextResult
|
4
|
+
def initialize(locale_file:, locale_text:)
|
5
|
+
@locale_text = locale_text
|
6
|
+
@locale_file = locale_file
|
7
|
+
end
|
8
|
+
|
9
|
+
def file_name
|
10
|
+
@locale_text.file
|
11
|
+
end
|
12
|
+
|
13
|
+
def lang
|
14
|
+
@locale_file.lang
|
15
|
+
end
|
16
|
+
|
17
|
+
def line
|
18
|
+
@locale_text.line
|
19
|
+
end
|
20
|
+
|
21
|
+
def text
|
22
|
+
@locale_text.text
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "i18n_checker/haml/locale_text"
|
2
|
+
require "i18n_checker/haml/locale_texts"
|
3
|
+
require "i18n_checker/haml/locale_text_collector"
|
4
|
+
|
5
|
+
module I18nChecker
|
6
|
+
module Haml
|
7
|
+
module Methods
|
8
|
+
def collect_locale_text_of(files)
|
9
|
+
collector = I18nChecker::Haml::LocaleTextCollector.new
|
10
|
+
locale_texts = I18nChecker::Haml::LocaleTexts.new
|
11
|
+
|
12
|
+
haml_files = files.delete_if { |file| File.directory?(file) }.to_a
|
13
|
+
haml_files.each do |haml_file|
|
14
|
+
locale_texts.concat(collector.collect(haml_file))
|
15
|
+
end
|
16
|
+
locale_texts
|
17
|
+
end
|
18
|
+
end
|
19
|
+
extend Methods
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'haml_parser'
|
2
|
+
require 'haml_parser/parser'
|
3
|
+
|
4
|
+
module I18nChecker
|
5
|
+
module Haml
|
6
|
+
class LocaleTextCollector
|
7
|
+
def collect(template_file)
|
8
|
+
template = read_template_file(template_file)
|
9
|
+
parser = HamlParser::Parser.new(filename: template_file)
|
10
|
+
LocaleTexts.new(collect_locale_texts(parser.call(template)))
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def read_template_file(template_file)
|
16
|
+
File.open(template_file, &:read)
|
17
|
+
end
|
18
|
+
|
19
|
+
def collect_locale_texts(ast)
|
20
|
+
locale_texts = []
|
21
|
+
locale_texts << collect_locale_text(ast)
|
22
|
+
return unless ast.respond_to?(:children)
|
23
|
+
locale_texts << ast.children.map { |child| collect_locale_texts(child) }
|
24
|
+
locale_texts.flatten.compact
|
25
|
+
end
|
26
|
+
|
27
|
+
def collect_locale_text(ast)
|
28
|
+
return locale_text_from_script(ast) if ast.kind_of?(HamlParser::Ast::Script)
|
29
|
+
return unless ast.respond_to?(:oneline_child)
|
30
|
+
return unless ast.oneline_child.kind_of?(HamlParser::Ast::Script)
|
31
|
+
locale_text_from_script(ast.oneline_child)
|
32
|
+
end
|
33
|
+
|
34
|
+
def locale_text_from_script(script_node)
|
35
|
+
return unless translate_script = script_node.script.match(/^t\(\'+(.+)\'+\)$/)
|
36
|
+
I18nChecker::Haml::LocaleText.new(
|
37
|
+
file: script_node.filename,
|
38
|
+
line: script_node.lineno,
|
39
|
+
text: translate_script[1]
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module I18nChecker
|
2
|
+
module Haml
|
3
|
+
class LocaleTexts
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize(texts = [])
|
7
|
+
@texts = texts
|
8
|
+
end
|
9
|
+
|
10
|
+
def each(&block)
|
11
|
+
texts.each(&block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def concat(texts)
|
15
|
+
@texts.concat(texts.to_a)
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
@texts == other.to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
def detect(detector)
|
24
|
+
detector.detect(texts)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :texts
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "i18n_checker/locale/key_path"
|
2
|
+
require "i18n_checker/locale/locale_file"
|
3
|
+
require "i18n_checker/locale/locale_files"
|
4
|
+
|
5
|
+
module I18nChecker
|
6
|
+
module Locale
|
7
|
+
module Methods
|
8
|
+
def load_of(locale_files)
|
9
|
+
loaded_locale_files = locale_files.map { |locale_file| I18nChecker::Locale::LocaleFile.load_yaml_file(locale_file) }
|
10
|
+
LocaleFiles.new(loaded_locale_files)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
extend Methods
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module I18nChecker
|
2
|
+
module Locale
|
3
|
+
class KeyPath
|
4
|
+
attr_reader :keys
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@keys = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def move_to(key)
|
11
|
+
@keys.push(key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def leave
|
15
|
+
@keys.pop
|
16
|
+
end
|
17
|
+
|
18
|
+
def current
|
19
|
+
@keys.join('.')
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
current
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module I18nChecker
|
4
|
+
module Locale
|
5
|
+
class LocaleFile
|
6
|
+
attr_reader :lang, :locale_texts
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def load_yaml(s)
|
10
|
+
new(YAML.load(s))
|
11
|
+
end
|
12
|
+
def load_yaml_file(yaml_file)
|
13
|
+
load_yaml(File.open(yaml_file, &:read))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(locale_texts = {})
|
18
|
+
lang = locale_texts.keys.first
|
19
|
+
@lang = lang.to_sym
|
20
|
+
@locale_texts = compact_of(locale_texts[lang] || {})
|
21
|
+
end
|
22
|
+
|
23
|
+
def include?(locale_text)
|
24
|
+
@locale_texts.key?(locale_text.text)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def compact_of(values={}, path=KeyPath.new)
|
30
|
+
result = {}
|
31
|
+
values.each_with_index do |(i, v)|
|
32
|
+
path.move_to(i)
|
33
|
+
if v.is_a?(Hash)
|
34
|
+
result.merge!(compact_of(v, path))
|
35
|
+
else
|
36
|
+
result[path.to_s] = v
|
37
|
+
end
|
38
|
+
path.leave
|
39
|
+
end
|
40
|
+
result
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module I18nChecker
|
2
|
+
module Locale
|
3
|
+
class LocaleFiles
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize(locale_files = [])
|
7
|
+
@locale_files = locale_files
|
8
|
+
end
|
9
|
+
|
10
|
+
def each(&block)
|
11
|
+
locale_files.each(&block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def delete_if(&block)
|
15
|
+
locale_files.delete_if(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :locale_files
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "i18n_checker/detector/locale_text_not_found"
|
2
|
+
require "i18n_checker/detector/locale_text_result"
|
3
|
+
require "i18n_checker/detector/detected_result"
|
4
|
+
|
5
|
+
module I18nChecker
|
6
|
+
class LocaleTextNotFoundChecker
|
7
|
+
def initialize(locale_texts: [], reporter:)
|
8
|
+
@reporter = reporter
|
9
|
+
@locale_texts = locale_texts
|
10
|
+
end
|
11
|
+
|
12
|
+
def check(locale_files = [])
|
13
|
+
not_found_detector = I18nChecker::Detector::LocaleTextNotFound.new(locale_files)
|
14
|
+
not_found_result = @locale_texts.detect(not_found_detector)
|
15
|
+
@reporter.report not_found_result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
require 'i18n_checker/locale'
|
4
|
+
require 'i18n_checker/haml'
|
5
|
+
require 'i18n_checker/reporter'
|
6
|
+
require "i18n_checker/locale_text_not_found_checker"
|
7
|
+
|
8
|
+
module I18nChecker
|
9
|
+
class RakeTask < ::Rake::TaskLib
|
10
|
+
attr_accessor :name
|
11
|
+
attr_accessor :locale_file_paths
|
12
|
+
attr_accessor :haml_template_paths
|
13
|
+
attr_accessor :logger
|
14
|
+
|
15
|
+
def initialize(name = :locale_check)
|
16
|
+
@name = name
|
17
|
+
@haml_template_paths = FileList['./app/views/*']
|
18
|
+
@locale_file_paths = FileList['./locales/*']
|
19
|
+
@logger = Logger.new(STDOUT)
|
20
|
+
@logger.formatter = proc {|severity, datetime, progname, message|
|
21
|
+
"#{message}\n"
|
22
|
+
}
|
23
|
+
yield self if block_given?
|
24
|
+
define
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def define
|
30
|
+
desc 'Check language files and templates.'
|
31
|
+
task(name) { run_task }
|
32
|
+
end
|
33
|
+
|
34
|
+
def run_task
|
35
|
+
reporter = I18nChecker::Reporter::DefaultReporter.new(logger: logger)
|
36
|
+
locale_files = I18nChecker::Locale.load_of(locale_file_paths)
|
37
|
+
locale_texts = I18nChecker::Haml.collect_locale_text_of(haml_template_paths)
|
38
|
+
|
39
|
+
checker = I18nChecker::LocaleTextNotFoundChecker.new(
|
40
|
+
reporter: reporter,
|
41
|
+
locale_texts: locale_texts
|
42
|
+
)
|
43
|
+
checker.check(locale_files)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'colorator'
|
2
|
+
|
3
|
+
module I18nChecker
|
4
|
+
module Reporter
|
5
|
+
class DefaultReporter < DetectResultReporter
|
6
|
+
def report(result)
|
7
|
+
logger.info 'There are settings where translated text can not be found'.red
|
8
|
+
result.locale_texts.each do |locale_text|
|
9
|
+
logger.info " #{locale_text.file_name.cyan}"
|
10
|
+
logger.info " line: #{locale_text.line} - #{locale_text.lang}.#{locale_text.text}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/screenshot.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n_checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- holyshared
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: haml_parser
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorator
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov-console
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: coveralls
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: It parses the haml template and checks the validity of the language file
|
126
|
+
email:
|
127
|
+
- holy.shared.design@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".coveralls.yml"
|
133
|
+
- ".editorconfig"
|
134
|
+
- ".gitignore"
|
135
|
+
- ".rspec"
|
136
|
+
- ".travis.yml"
|
137
|
+
- Gemfile
|
138
|
+
- Gemfile.lock
|
139
|
+
- LICENSE
|
140
|
+
- README.md
|
141
|
+
- Rakefile
|
142
|
+
- i18n-checker.gemspec
|
143
|
+
- lib/.DS_Store
|
144
|
+
- lib/i18n_checker.rb
|
145
|
+
- lib/i18n_checker/.DS_Store
|
146
|
+
- lib/i18n_checker/detector/detected_result.rb
|
147
|
+
- lib/i18n_checker/detector/locale_text_not_found.rb
|
148
|
+
- lib/i18n_checker/detector/locale_text_result.rb
|
149
|
+
- lib/i18n_checker/haml.rb
|
150
|
+
- lib/i18n_checker/haml/locale_text.rb
|
151
|
+
- lib/i18n_checker/haml/locale_text_collector.rb
|
152
|
+
- lib/i18n_checker/haml/locale_texts.rb
|
153
|
+
- lib/i18n_checker/locale.rb
|
154
|
+
- lib/i18n_checker/locale/key_path.rb
|
155
|
+
- lib/i18n_checker/locale/locale_file.rb
|
156
|
+
- lib/i18n_checker/locale/locale_files.rb
|
157
|
+
- lib/i18n_checker/locale_text_not_found_checker.rb
|
158
|
+
- lib/i18n_checker/rake_task.rb
|
159
|
+
- lib/i18n_checker/reporter.rb
|
160
|
+
- lib/i18n_checker/reporter/default_reporter.rb
|
161
|
+
- lib/i18n_checker/reporter/detect_result_reporter.rb
|
162
|
+
- lib/i18n_checker/version.rb
|
163
|
+
- screenshot.png
|
164
|
+
homepage: https://github.com/holyshared/i18n-checker
|
165
|
+
licenses: []
|
166
|
+
metadata: {}
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 2.5.2
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: i18n checker for haml
|
187
|
+
test_files: []
|