i18n-spec 0.1.0 → 0.1.1
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.
- data/README.md +19 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/i18n-spec.gemspec +3 -3
- data/lib/i18n-spec/tasks.rb +76 -0
- metadata +12 -12
- data/lib/i18n-spec/tasks/checker.rb +0 -55
data/README.md
CHANGED
@@ -46,10 +46,27 @@ If you need to test that all translations have been completed :
|
|
46
46
|
|
47
47
|
## Rake tasks
|
48
48
|
|
49
|
+
Include the tasks in your Rakefile with :
|
50
|
+
|
51
|
+
require 'i18n-spec/tasks'
|
52
|
+
|
53
|
+
### Validating locale files
|
54
|
+
|
49
55
|
You can check a locale file with the following task :
|
50
56
|
|
51
|
-
rake i18n:
|
57
|
+
rake i18n-spec:validate FILEPATH
|
52
58
|
|
53
59
|
or check a whole directory :
|
54
60
|
|
55
|
-
rake i18n:
|
61
|
+
rake i18n-spec:validate DIRECTORY
|
62
|
+
|
63
|
+
### Checking for translation completeness
|
64
|
+
|
65
|
+
|
66
|
+
You can check a locale file with the following taks :
|
67
|
+
|
68
|
+
rake i18n-spec:completeness SOURCE_FILEPATH TRANSLATED_FILEPATH
|
69
|
+
|
70
|
+
or again, check a whole directory :
|
71
|
+
|
72
|
+
rake i18n-spec:completeness SOURCE_FILEPATH DIRECTORY
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/i18n-spec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{i18n-spec}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Christopher Dell}]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2012-01-14}
|
13
13
|
s.description = %q{Includes a number of rspec matchers to make specing your locale files easy peasy.}
|
14
14
|
s.email = %q{chris@tigrish.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
"lib/i18n-spec/matchers/have_valid_pluralization_keys_matcher.rb",
|
39
39
|
"lib/i18n-spec/models/locale_file.rb",
|
40
40
|
"lib/i18n-spec/shared_examples/valid_locale_file.rb",
|
41
|
-
"lib/i18n-spec/tasks
|
41
|
+
"lib/i18n-spec/tasks.rb",
|
42
42
|
"spec/fixtures/en.yml",
|
43
43
|
"spec/fixtures/es.yml",
|
44
44
|
"spec/fixtures/fr.yml",
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'i18n-spec'
|
2
|
+
|
3
|
+
I18nSpec::LOG_DETAIL_PREDICATE = " - "
|
4
|
+
|
5
|
+
namespace :'i18n-spec' do
|
6
|
+
desc "Checks the validity of a locale file"
|
7
|
+
task :validate do
|
8
|
+
if ARGV[1].nil?
|
9
|
+
puts "You must specifiy a file path or a folder path"
|
10
|
+
return
|
11
|
+
elsif File.directory?(ARGV[1])
|
12
|
+
filepaths = Dir.glob("#{ARGV[1]}/*.yml")
|
13
|
+
else
|
14
|
+
filepaths = [ARGV[1]]
|
15
|
+
end
|
16
|
+
|
17
|
+
filepaths.each do |filepath|
|
18
|
+
heading filepath
|
19
|
+
fatals, errors, warnings = [0, 0, 0]
|
20
|
+
locale_file = I18nSpec::LocaleFile.new(filepath)
|
21
|
+
unless locale_file.is_parseable?
|
22
|
+
log :fatal, 'could not be parsed', format_str(locale_file.errors[:unparseable])
|
23
|
+
fatals += 1
|
24
|
+
break
|
25
|
+
end
|
26
|
+
|
27
|
+
unless locale_file.invalid_pluralization_keys.empty?
|
28
|
+
log :error, 'invalid pluralization keys', format_array(locale_file.errors[:invalid_pluralization_keys])
|
29
|
+
errors += 1
|
30
|
+
end
|
31
|
+
|
32
|
+
log :ok if fatals + errors + warnings == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Checks for missing translations between the default and the translated locale file"
|
37
|
+
task :completeness do
|
38
|
+
if ARGV[1].nil? || ARGV[2].nil?
|
39
|
+
puts "You must specify a default locale file and translated file or a folder of translated files"
|
40
|
+
elsif File.directory?(ARGV[2])
|
41
|
+
translated_filepaths = Dir.glob("#{ARGV[2]}/*.yml")
|
42
|
+
else
|
43
|
+
translated_filepaths = [ARGV[2]]
|
44
|
+
end
|
45
|
+
default_locale = I18nSpec::LocaleFile.new(ARGV[1])
|
46
|
+
translated_filepaths.each do |translated_filepath|
|
47
|
+
heading translated_filepath
|
48
|
+
locale_file = I18nSpec::LocaleFile.new(translated_filepath)
|
49
|
+
misses = default_locale.flattened_translations.keys.reject do |key|
|
50
|
+
locale_file.flattened_translations.keys.include?(key)
|
51
|
+
end
|
52
|
+
if misses.empty?
|
53
|
+
log :complete
|
54
|
+
else
|
55
|
+
misses.each { |miss| log :missing, miss }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def log(level, msg='', detail=nil)
|
61
|
+
puts "- *" << level.to_s.upcase << '* ' << msg
|
62
|
+
puts detail if detail
|
63
|
+
end
|
64
|
+
|
65
|
+
def heading(str='')
|
66
|
+
puts "\n### " << str << "\n\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
def format_array(array)
|
70
|
+
[I18nSpec::LOG_DETAIL_PREDICATE, array.join(I18nSpec::LOG_DETAIL_PREDICATE)].join
|
71
|
+
end
|
72
|
+
|
73
|
+
def format_str(str)
|
74
|
+
[I18nSpec::LOG_DETAIL_PREDICATE, str].join
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-14 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70301793011300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.3.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70301793011300
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70301793010720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.10
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70301793010720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70301793010200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70301793010200
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &70301793009660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70301793009660
|
58
58
|
description: Includes a number of rspec matchers to make specing your locale files
|
59
59
|
easy peasy.
|
60
60
|
email: chris@tigrish.com
|
@@ -85,7 +85,7 @@ files:
|
|
85
85
|
- lib/i18n-spec/matchers/have_valid_pluralization_keys_matcher.rb
|
86
86
|
- lib/i18n-spec/models/locale_file.rb
|
87
87
|
- lib/i18n-spec/shared_examples/valid_locale_file.rb
|
88
|
-
- lib/i18n-spec/tasks
|
88
|
+
- lib/i18n-spec/tasks.rb
|
89
89
|
- spec/fixtures/en.yml
|
90
90
|
- spec/fixtures/es.yml
|
91
91
|
- spec/fixtures/fr.yml
|
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
segments:
|
114
114
|
- 0
|
115
|
-
hash:
|
115
|
+
hash: 3454305248462324191
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'i18n-spec'
|
2
|
-
|
3
|
-
I18nSpec::LOG_DETAIL_PREDICATE = " | - "
|
4
|
-
|
5
|
-
namespace :i18n do
|
6
|
-
desc "Checks the validity of a locale file"
|
7
|
-
task :check do
|
8
|
-
|
9
|
-
|
10
|
-
if ARGV[1].nil?
|
11
|
-
puts "You must specifiy a file path or a folder path"
|
12
|
-
return
|
13
|
-
elsif File.directory?(ARGV[1])
|
14
|
-
filepaths = Dir.glob("#{ARGV[1]}/*.yml")
|
15
|
-
else
|
16
|
-
filepaths = [ARGV[1]]
|
17
|
-
end
|
18
|
-
|
19
|
-
filepaths.each do |filepath|
|
20
|
-
puts "-"*80
|
21
|
-
puts filepath
|
22
|
-
|
23
|
-
fatals, errors, warnings = [0, 0, 0]
|
24
|
-
locale_file = I18nSpec::LocaleFile.new(filepath)
|
25
|
-
|
26
|
-
unless locale_file.is_parseable?
|
27
|
-
log :fatal, 'could not be parsed', format_str(locale_file.errors[:unparseable])
|
28
|
-
fatals += 1
|
29
|
-
break
|
30
|
-
end
|
31
|
-
|
32
|
-
unless locale_file.invalid_pluralization_keys.empty?
|
33
|
-
log :error, 'invalid pluralization keys', format_array(locale_file.errors[:invalid_pluralization_keys])
|
34
|
-
errors += 1
|
35
|
-
end
|
36
|
-
|
37
|
-
puts '[OK]' if fatals + errors + warnings == 0
|
38
|
-
end
|
39
|
-
|
40
|
-
puts "="*80
|
41
|
-
end
|
42
|
-
|
43
|
-
def log(level, msg, detail=nil)
|
44
|
-
puts " - [" << level.to_s.upcase << '] ' << msg
|
45
|
-
puts detail if detail
|
46
|
-
end
|
47
|
-
|
48
|
-
def format_array(array)
|
49
|
-
[I18nSpec::LOG_DETAIL_PREDICATE, array.join(I18nSpec::LOG_DETAIL_PREDICATE)].join
|
50
|
-
end
|
51
|
-
|
52
|
-
def format_str(str)
|
53
|
-
[I18nSpec::LOG_DETAIL_PREDICATE, str].join
|
54
|
-
end
|
55
|
-
end
|