i18n-spec 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -1
- data/VERSION +1 -1
- data/i18n-spec.gemspec +4 -2
- data/lib/i18n-spec/matchers/have_a_valid_locale_matcher.rb +1 -1
- data/lib/i18n-spec/matchers/have_missing_pluralization_keys_matcher.rb +18 -0
- data/lib/i18n-spec/models/locale_file.rb +20 -5
- data/lib/i18n-spec/shared_examples/valid_locale_file.rb +1 -0
- data/spec/fixtures/missing_pluralization_keys.yml +4 -0
- data/spec/lib/i18n-spec/matchers_spec.rb +1 -0
- data/spec/lib/i18n-spec/models/locale_file_spec.rb +83 -1
- metadata +15 -13
data/README.md
CHANGED
@@ -11,9 +11,11 @@ There are a few matchers available; the subject of the spec is always a path to
|
|
11
11
|
describe "config/locales/en.yml" do
|
12
12
|
it { should be_parseable }
|
13
13
|
it { should have_valid_pluralization_keys }
|
14
|
+
it { should_not have_missing_pluralization_keys }
|
14
15
|
it { should have_one_top_level_namespace }
|
15
16
|
it { should be_named_like_top_level_namespace }
|
16
17
|
it { should_not have_legacy_interpolations }
|
18
|
+
it { should have_a_valid_locale }
|
17
19
|
end
|
18
20
|
|
19
21
|
All of these tests can be ran in one line with a shared example :
|
@@ -69,4 +71,4 @@ You can check a locale file with the following taks :
|
|
69
71
|
|
70
72
|
or again, check a whole directory :
|
71
73
|
|
72
|
-
rake i18n-spec:completeness SOURCE_FILEPATH DIRECTORY
|
74
|
+
rake i18n-spec:completeness SOURCE_FILEPATH DIRECTORY
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
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.
|
8
|
+
s.version = "0.3.0"
|
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{2012-09-
|
12
|
+
s.date = %q{2012-09-16}
|
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 = [
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/i18n-spec/matchers/be_parseable_matcher.rb",
|
35
35
|
"lib/i18n-spec/matchers/have_a_valid_locale_matcher.rb",
|
36
36
|
"lib/i18n-spec/matchers/have_legacy_interpolations.rb",
|
37
|
+
"lib/i18n-spec/matchers/have_missing_pluralization_keys_matcher.rb",
|
37
38
|
"lib/i18n-spec/matchers/have_one_top_level_namespace_matcher.rb",
|
38
39
|
"lib/i18n-spec/matchers/have_valid_pluralization_keys_matcher.rb",
|
39
40
|
"lib/i18n-spec/models/locale_file.rb",
|
@@ -45,6 +46,7 @@ Gem::Specification.new do |s|
|
|
45
46
|
"spec/fixtures/invalid_locale.yml",
|
46
47
|
"spec/fixtures/invalid_pluralization_keys.yml",
|
47
48
|
"spec/fixtures/legacy_interpolations.yml",
|
49
|
+
"spec/fixtures/missing_pluralization_keys.yml",
|
48
50
|
"spec/fixtures/multiple_top_levels.yml",
|
49
51
|
"spec/fixtures/not_subset.yml",
|
50
52
|
"spec/fixtures/unparseable.yml",
|
@@ -0,0 +1,18 @@
|
|
1
|
+
RSpec::Matchers.define :have_missing_pluralization_keys do
|
2
|
+
match do |actual|
|
3
|
+
@locale_file = I18nSpec::LocaleFile.new(actual)
|
4
|
+
@locale_file.missing_pluralization_keys.any?
|
5
|
+
end
|
6
|
+
|
7
|
+
failure_message_for_should_not do |filepath|
|
8
|
+
flattened_keys = []
|
9
|
+
|
10
|
+
@locale_file.errors[:missing_pluralization_keys].each do |parent, subkeys|
|
11
|
+
subkeys.each do |subkey|
|
12
|
+
flattened_keys << [parent, subkey].join('.')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
"expected #{filepath} to contain the following pluralization keys :\n- " << flattened_keys.join("\n- ")
|
17
|
+
end
|
18
|
+
end
|
@@ -22,6 +22,14 @@ module I18nSpec
|
|
22
22
|
@flattened_translations ||= flatten_tree(translations.values.first)
|
23
23
|
end
|
24
24
|
|
25
|
+
def locale
|
26
|
+
@locale ||= ISO::Tag.new(locale_code)
|
27
|
+
end
|
28
|
+
|
29
|
+
def locale_code
|
30
|
+
translations.keys.first
|
31
|
+
end
|
32
|
+
|
25
33
|
def pluralizations
|
26
34
|
result = flatten_tree(translations).select do |key, value|
|
27
35
|
value.is_a?(Hash)
|
@@ -45,6 +53,17 @@ module I18nSpec
|
|
45
53
|
invalid
|
46
54
|
end
|
47
55
|
|
56
|
+
def missing_pluralization_keys
|
57
|
+
return_data = {}
|
58
|
+
rule_names = locale.language.plural_rule_names
|
59
|
+
pluralizations.each do |parent, pluralization|
|
60
|
+
missing_keys = rule_names - pluralization.keys
|
61
|
+
return_data[parent] = missing_keys if missing_keys.any?
|
62
|
+
end
|
63
|
+
@errors[:missing_pluralization_keys] = return_data if return_data.any?
|
64
|
+
return_data
|
65
|
+
end
|
66
|
+
|
48
67
|
def is_parseable?
|
49
68
|
begin
|
50
69
|
yaml_load_content
|
@@ -63,11 +82,7 @@ module I18nSpec
|
|
63
82
|
end
|
64
83
|
|
65
84
|
def is_named_like_top_level_namespace?
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
def has_a_valid_locale?
|
70
|
-
ISO::Tag.new(translations.keys.first).valid?
|
85
|
+
locale_code == File.basename(@filepath, File.extname(@filepath))
|
71
86
|
end
|
72
87
|
|
73
88
|
protected
|
@@ -2,6 +2,7 @@ shared_examples_for "a valid locale file" do |locale_file|
|
|
2
2
|
describe locale_file do
|
3
3
|
it { should be_parseable }
|
4
4
|
it { should have_valid_pluralization_keys }
|
5
|
+
it { should_not have_missing_pluralization_keys }
|
5
6
|
it { should have_one_top_level_namespace }
|
6
7
|
it { should be_named_like_top_level_namespace }
|
7
8
|
it { should_not have_legacy_interpolations }
|
@@ -12,6 +12,7 @@ describe "Invalid files" do
|
|
12
12
|
it { 'spec/fixtures/legacy_interpolations.yml'.should have_legacy_interpolations }
|
13
13
|
it { 'spec/fixtures/invalid_locale.yml'.should_not have_a_valid_locale }
|
14
14
|
it { 'spec/fixtures/not_subset.yml'.should_not be_a_subset_of 'spec/fixtures/en.yml' }
|
15
|
+
it { 'spec/fixtures/missing_pluralization_keys.yml'.should have_missing_pluralization_keys }
|
15
16
|
end
|
16
17
|
|
17
18
|
describe "Translated files" do
|
@@ -11,9 +11,25 @@ end
|
|
11
11
|
describe I18nSpec::LocaleFile do
|
12
12
|
include LocaleFileHelper
|
13
13
|
|
14
|
+
describe "#locale_code" do
|
15
|
+
it "returns the first key of the file" do
|
16
|
+
locale_file = locale_file_with_content("pt-BR:\n hello: world")
|
17
|
+
locale_file.locale_code.should == 'pt-BR'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#locale" do
|
22
|
+
it "returns an ISO::Tag based on the locale_code" do
|
23
|
+
locale_file = locale_file_with_content("pt-BR:\n hello: world")
|
24
|
+
locale_file.locale.should be_a(ISO::Tag)
|
25
|
+
locale_file.locale.language.code.should == 'pt'
|
26
|
+
locale_file.locale.region.code.should == 'BR'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
14
30
|
describe "#is_parseable?" do
|
15
31
|
context "when YAML is parseable" do
|
16
|
-
let(:locale_file) {
|
32
|
+
let(:locale_file) { locale_file_with_content("en:\n hello: world") }
|
17
33
|
|
18
34
|
it "returns true" do
|
19
35
|
locale_file.is_parseable?.should == true
|
@@ -88,4 +104,70 @@ describe I18nSpec::LocaleFile do
|
|
88
104
|
locale_file.invalid_pluralization_keys.should_not be_include 'en.birds'
|
89
105
|
end
|
90
106
|
end
|
107
|
+
|
108
|
+
describe "#missing_pluralization_keys" do
|
109
|
+
it "returns the parents that containts missing pluralizations in with the english rules" do
|
110
|
+
content = "en:
|
111
|
+
cats:
|
112
|
+
one: one
|
113
|
+
dogs:
|
114
|
+
other: other
|
115
|
+
birds:
|
116
|
+
one: one
|
117
|
+
other: other"
|
118
|
+
locale_file = locale_file_with_content(content)
|
119
|
+
locale_file.missing_pluralization_keys.should == {
|
120
|
+
'en.cats' => %w(other),
|
121
|
+
'en.dogs' => %w(one)
|
122
|
+
}
|
123
|
+
locale_file.errors[:missing_pluralization_keys].should_not be_nil
|
124
|
+
end
|
125
|
+
|
126
|
+
it "returns the parents that containts missing pluralizations in with the russian rules" do
|
127
|
+
content = "ru:
|
128
|
+
cats:
|
129
|
+
one: one
|
130
|
+
few: few
|
131
|
+
many: many
|
132
|
+
other: other
|
133
|
+
dogs:
|
134
|
+
one: one
|
135
|
+
other: some
|
136
|
+
birds:
|
137
|
+
zero: zero
|
138
|
+
one: one
|
139
|
+
few: few
|
140
|
+
other: other"
|
141
|
+
locale_file = locale_file_with_content(content)
|
142
|
+
locale_file.missing_pluralization_keys.should == {
|
143
|
+
'ru.dogs' => %w(few many),
|
144
|
+
'ru.birds' => %w(many)
|
145
|
+
}
|
146
|
+
locale_file.errors[:missing_pluralization_keys].should_not be_nil
|
147
|
+
end
|
148
|
+
|
149
|
+
it "returns the parents that containts missing pluralizations in with the japanese rules" do
|
150
|
+
content = "ja:
|
151
|
+
cats:
|
152
|
+
one: one
|
153
|
+
dogs:
|
154
|
+
other: some
|
155
|
+
birds: not really a pluralization"
|
156
|
+
locale_file = locale_file_with_content(content)
|
157
|
+
locale_file.missing_pluralization_keys.should == { 'ja.cats' => %w(other) }
|
158
|
+
locale_file.errors[:missing_pluralization_keys].should_not be_nil
|
159
|
+
end
|
160
|
+
|
161
|
+
it "returns an empty hash when all pluralizations are complete" do
|
162
|
+
content = "ja:
|
163
|
+
cats:
|
164
|
+
other: one
|
165
|
+
dogs:
|
166
|
+
other: some
|
167
|
+
birds: not really a pluralization"
|
168
|
+
locale_file = locale_file_with_content(content)
|
169
|
+
locale_file.missing_pluralization_keys.should == {}
|
170
|
+
locale_file.errors[:missing_pluralization_keys].should be_nil
|
171
|
+
end
|
172
|
+
end
|
91
173
|
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.
|
4
|
+
version: 0.3.0
|
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: 2012-09-
|
12
|
+
date: 2012-09-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: iso
|
16
|
-
requirement: &
|
16
|
+
requirement: &70263477376200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70263477376200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70263477996860 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.4.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70263477996860
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70263477996380 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.1.3
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70263477996380
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70263477995900 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.6.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70263477995900
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rdoc
|
60
|
-
requirement: &
|
60
|
+
requirement: &70263477995420 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70263477995420
|
69
69
|
description: Includes a number of rspec matchers to make specing your locale files
|
70
70
|
easy peasy.
|
71
71
|
email: chris@tigrish.com
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/i18n-spec/matchers/be_parseable_matcher.rb
|
93
93
|
- lib/i18n-spec/matchers/have_a_valid_locale_matcher.rb
|
94
94
|
- lib/i18n-spec/matchers/have_legacy_interpolations.rb
|
95
|
+
- lib/i18n-spec/matchers/have_missing_pluralization_keys_matcher.rb
|
95
96
|
- lib/i18n-spec/matchers/have_one_top_level_namespace_matcher.rb
|
96
97
|
- lib/i18n-spec/matchers/have_valid_pluralization_keys_matcher.rb
|
97
98
|
- lib/i18n-spec/models/locale_file.rb
|
@@ -103,6 +104,7 @@ files:
|
|
103
104
|
- spec/fixtures/invalid_locale.yml
|
104
105
|
- spec/fixtures/invalid_pluralization_keys.yml
|
105
106
|
- spec/fixtures/legacy_interpolations.yml
|
107
|
+
- spec/fixtures/missing_pluralization_keys.yml
|
106
108
|
- spec/fixtures/multiple_top_levels.yml
|
107
109
|
- spec/fixtures/not_subset.yml
|
108
110
|
- spec/fixtures/unparseable.yml
|
@@ -124,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
126
|
version: '0'
|
125
127
|
segments:
|
126
128
|
- 0
|
127
|
-
hash:
|
129
|
+
hash: 3033916515147713516
|
128
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
131
|
none: false
|
130
132
|
requirements:
|