polint 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/polint/parser.rb +7 -2
- data/lib/polint/transform.rb +5 -3
- data/lib/polint/version.rb +1 -1
- data/lib/polint.rb +2 -2
- data/spec/data/en-valid.po +6 -0
- data/spec/lib/polint/parser_spec.rb +41 -0
- data/spec/lib/polint/transform_spec.rb +10 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 230c13623db8e5c272c96404b565e76d1149e11b
|
4
|
+
data.tar.gz: 8d70271797b9a0342001833308874f11e8b24ed7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7d72c3db3edbcc9d4bf52a18bcb316206361f0e28f0e8fcdd80e0f5d2e24ff5c59a48bb0e50546dc56218715d7c2c76a09cb6f5bf182c83ea1995fd78ff9f4f
|
7
|
+
data.tar.gz: 279c37ba16b2dfb3ba1eea26645c9a44a05002c10ba2f1ae9e628351c617e19413a04065f14302f026e21eac43fca42e0e26841c81c17fd5b9d468b510274a7c
|
data/Gemfile.lock
CHANGED
data/lib/polint/parser.rb
CHANGED
@@ -33,7 +33,8 @@ module Polint
|
|
33
33
|
rule(:flag) { str(',') >> lwsp >> match(/[a-z\-]/).repeat(1).as(:flag) >> lwsp }
|
34
34
|
rule(:flag_comment) { start_comment >> flag.repeat(1).as(:flags) >> endl }
|
35
35
|
rule(:reference_comment) { start_comment >> str(':') >> lwsp >> match(/[^\n]/).repeat.as(:reference) >> endl }
|
36
|
-
rule(:
|
36
|
+
rule(:unparsed_comment) { start_comment >> (match(/[^~]/) >> lwsp >> match(/[^\n]/).repeat).as(:comment) >> endl }
|
37
|
+
rule(:comment) { flag_comment | reference_comment | unparsed_comment }
|
37
38
|
rule(:comments) { comment.repeat }
|
38
39
|
|
39
40
|
rule(:msgid) { str('msgid') >> lwsp >> quoted_strings.as(:msgid) }
|
@@ -45,7 +46,11 @@ module Polint
|
|
45
46
|
rule(:translation) { (comments >> msgid >> msgid_plural.maybe >> msgstr.repeat(1)).as(:translation) >> blank_line }
|
46
47
|
rule(:translations) { translation.repeat }
|
47
48
|
|
48
|
-
rule(:
|
49
|
+
rule(:obsolete_line) { start_comment >> str('~') >> lwsp >> match(/[^\n]/).repeat >> endl }
|
50
|
+
rule(:obsolete_translation) { obsolete_line.repeat(1).as(:obsolete_translation) >> blank_line }
|
51
|
+
rule(:obsolete_translations) { obsolete_translation.repeat }
|
52
|
+
|
53
|
+
rule(:file) { (headers >> translations >> obsolete_translations).as(:file) }
|
49
54
|
root(:file)
|
50
55
|
|
51
56
|
end
|
data/lib/polint/transform.rb
CHANGED
@@ -16,12 +16,12 @@ module Polint
|
|
16
16
|
{ headers: items.to_h }
|
17
17
|
end
|
18
18
|
|
19
|
-
rule(msgid: sequence(:items)) { { msgid: { text: items.join
|
20
|
-
rule(msgid_plural: sequence(:items)) { { msgid_plural: { text: items.join
|
19
|
+
rule(msgid: sequence(:items)) { { msgid: { text: items.join } } }
|
20
|
+
rule(msgid_plural: sequence(:items)) { { msgid_plural: { text: items.join } } }
|
21
21
|
rule(msgstr: subtree(:items)) do
|
22
22
|
msgstr = {}
|
23
23
|
msgstr[:index] = items.shift[:index].to_i if items.first.is_a?(Hash)
|
24
|
-
msgstr[:text] = items.join
|
24
|
+
msgstr[:text] = items.join
|
25
25
|
{ msgstr: msgstr }
|
26
26
|
end
|
27
27
|
|
@@ -29,6 +29,7 @@ module Polint
|
|
29
29
|
translation = {
|
30
30
|
flags: [],
|
31
31
|
references: [],
|
32
|
+
comments: [],
|
32
33
|
msgid: {},
|
33
34
|
msgid_plural: {},
|
34
35
|
msgstrs: []
|
@@ -38,6 +39,7 @@ module Polint
|
|
38
39
|
case k
|
39
40
|
when :flags then translation[:flags] |= v
|
40
41
|
when :reference then translation[:references] << v
|
42
|
+
when :comment then translation[:comments] << v
|
41
43
|
when :msgid, :msgid_plural then translation[k] = v
|
42
44
|
when :msgstr then translation[:msgstrs] << v
|
43
45
|
end
|
data/lib/polint/version.rb
CHANGED
data/lib/polint.rb
CHANGED
@@ -120,7 +120,7 @@ module Polint
|
|
120
120
|
tree = Polint::Parser.new.parse(data)
|
121
121
|
tree = Polint::Transform.new.apply(tree)
|
122
122
|
|
123
|
-
die '
|
123
|
+
die "The PO file '#{@pofile}' has no Plural-Forms header, aborting." unless tree[:headers].key?('Plural-Forms')
|
124
124
|
nplurals = tree[:headers]['Plural-Forms'][:nplurals]
|
125
125
|
|
126
126
|
tree[:translations].each do |translation|
|
@@ -150,7 +150,7 @@ module Polint
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
rescue Parslet::ParseFailed => e
|
153
|
-
die e.cause.ascii_tree
|
153
|
+
die "The PO file '#{@pofile}' cannot be parsed, aborting.\n\n#{e.cause.ascii_tree}"
|
154
154
|
end
|
155
155
|
|
156
156
|
# Check for errors in a key/translation pair.
|
data/spec/data/en-valid.po
CHANGED
@@ -16,3 +16,9 @@ msgid "Hello World Plural"
|
|
16
16
|
msgid_plural "Hello %{n} Worlds Plural"
|
17
17
|
msgstr[0] "Hello World Plural"
|
18
18
|
msgstr[1] "Hello %{n} Worlds Plural"
|
19
|
+
|
20
|
+
#~ msgid "Obsolete Translation"
|
21
|
+
#~ msgstr "Obsolete Translation"
|
22
|
+
|
23
|
+
#~ msgid "Another Obsolete Translation"
|
24
|
+
#~ msgstr "Another Obsolete Translation"
|
@@ -89,6 +89,30 @@ RSpec.describe Polint::Parser do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
describe 'rule(:unparsed_comment)' do
|
93
|
+
let(:rule) { :unparsed_comment }
|
94
|
+
|
95
|
+
context 'when matching a translator comment' do
|
96
|
+
let(:line) { '# no semantics here' }
|
97
|
+
it { expect(tree).to eq comment: ' no semantics here' }
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when matching an extracted comment' do
|
101
|
+
let(:line) { '#. no semantics here' }
|
102
|
+
it { expect(tree).to eq comment: '. no semantics here' }
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'when matching a previous translation comment' do
|
106
|
+
let(:line) { '#| no semantics here' }
|
107
|
+
it { expect(tree).to eq comment: '| no semantics here' }
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when matching an obsolete translation' do
|
111
|
+
let(:line) { '#~ obsolete things go here' }
|
112
|
+
it { expect{ tree }.to raise_error Parslet::ParseFailed }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
92
116
|
describe 'rule(:msgid)' do
|
93
117
|
let(:rule) { :msgid }
|
94
118
|
|
@@ -255,4 +279,21 @@ RSpec.describe Polint::Parser do
|
|
255
279
|
end
|
256
280
|
end
|
257
281
|
|
282
|
+
describe 'rule(:obsolete_translation)' do
|
283
|
+
let(:rule) { :obsolete_translation }
|
284
|
+
let(:line) { lines.join("\n") }
|
285
|
+
|
286
|
+
context 'when matching a singular single-line msgstr with comments' do
|
287
|
+
let(:lines) {
|
288
|
+
[
|
289
|
+
'#~ msgid "Hello World"',
|
290
|
+
'#~ msgstr "Hello World"'
|
291
|
+
]
|
292
|
+
}
|
293
|
+
it {
|
294
|
+
expect(tree).to eq obsolete_translation: line
|
295
|
+
}
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
258
299
|
end
|
@@ -37,10 +37,11 @@ RSpec.describe Polint::Transform do
|
|
37
37
|
{ flags: [{ flag: 'fuzzy' }] },
|
38
38
|
{ reference: '../../some_file.rb:34' },
|
39
39
|
{ reference: '../../some_other_file.rb:283' },
|
40
|
-
{
|
41
|
-
{
|
42
|
-
{
|
43
|
-
{ msgstr: [{ index: '
|
40
|
+
{ comment: 'arbitrary text' },
|
41
|
+
{ msgid: [{ quoted_string: [] }, { quoted_string: 'Hello World\\n' }, { quoted_string: 'Hello Again'}] },
|
42
|
+
{ msgid_plural: [{ quoted_string: [] }, { quoted_string: 'Hello %{n} Worlds\\n' }, { quoted_string: 'Hello Again'}] },
|
43
|
+
{ msgstr: [{ index: '0' }, { quoted_string: [] }, { quoted_string: 'Hello World\\n' }, { quoted_string: 'Hello Again'}] },
|
44
|
+
{ msgstr: [{ index: '1' }, { quoted_string: [] }, { quoted_string: 'Hello %{n} Worlds\\n' }, { quoted_string: 'Hello Again'}] }
|
44
45
|
]
|
45
46
|
}
|
46
47
|
}
|
@@ -48,11 +49,12 @@ RSpec.describe Polint::Transform do
|
|
48
49
|
expect(output).to eq translation: {
|
49
50
|
flags: [:fuzzy],
|
50
51
|
references: ['../../some_file.rb:34', '../../some_other_file.rb:283'],
|
51
|
-
|
52
|
-
|
52
|
+
comments: ['arbitrary text'],
|
53
|
+
msgid: { text: 'Hello World\\nHello Again' },
|
54
|
+
msgid_plural: { text: 'Hello %{n} Worlds\\nHello Again' },
|
53
55
|
msgstrs: [
|
54
|
-
{ index: 0, text:
|
55
|
-
{ index: 1, text:
|
56
|
+
{ index: 0, text: 'Hello World\\nHello Again' },
|
57
|
+
{ index: 1, text: 'Hello %{n} Worlds\\nHello Again' }
|
56
58
|
]
|
57
59
|
}
|
58
60
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Letessier
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.4.8
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: A linter for Uniforum PO files.
|