simple_po_parser 1.1.3 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitattributes +1 -0
- data/CHANGELOG.md +25 -5
- data/Rakefile +4 -4
- data/lib/simple_po_parser/parser.rb +10 -8
- data/lib/simple_po_parser/tokenizer.rb +9 -1
- data/lib/simple_po_parser/version.rb +1 -1
- data/spec/simple_po_parser/fixtures/crlf_encoded.po +51 -0
- data/spec/simple_po_parser/fixtures/multiline.po +10 -0
- data/spec/simple_po_parser/parser_spec.rb +10 -0
- data/spec/simple_po_parser/simple_po_parser_spec.rb +4 -0
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7b32bc4f19bd4e4967e9395bb2869e377e75f63bac97a0820ced810d03191b73
|
4
|
+
data.tar.gz: 24bb37816cc545d65b2840ad96628bc17b4f7c994eeabe8d0cb43307302c89d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7469e3b963f89d2f35a29cef3d3c7f4fe3bb0e78e9cbbad9fd6e8f9a800a44b804c1193abfefa2685027d773fdf0c86faaa6abab1d0d84df35ca068e6b0eb209
|
7
|
+
data.tar.gz: 1283c455623d2e8c387e8b57d963dffd11a244dfdd4c4049f10444c4cf1fffa3adc5c9c59b83c8c463ac0167c1bd410741a1c17bd06b70f50e7822d8e8fb3bf2
|
data/.gitattributes
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
spec/simple_po_parser/fixtures/crlf_encoded.po binary
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,35 @@
|
|
1
|
-
|
1
|
+
Changelog
|
2
2
|
=============
|
3
3
|
|
4
|
+
## Version 1.1.6
|
5
|
+
* fixes parsing of multiline strings that have content on the first line. Fixes issue #3, added via PR #4 by @mgruner
|
6
|
+
|
7
|
+
## Version 1.1.5
|
8
|
+
* added support for windows CRLF line endings. Fixes issue #2
|
9
|
+
* Note: CRLF support is enabled if the first line ends in a CRLF and reduces performance by about 50%. Performance for files only using \n is not affected. Files not using \r\n in the first line but somewhere else in the file might trigger errors.
|
10
|
+
|
11
|
+
## Version 1.1.4
|
12
|
+
* see 1.1.5. **Shouldn't be used**.
|
13
|
+
|
14
|
+
## Version 1.1.3
|
15
|
+
|
16
|
+
* merged PR#1 from @christopherstat for UTF-8 support of legacy ruby versions
|
17
|
+
|
18
|
+
## Version 1.1.2
|
19
|
+
* Made the parser thread-safe
|
20
|
+
|
21
|
+
## Version 1.1.2
|
22
|
+
* Made the parser thread-safe
|
23
|
+
|
24
|
+
## Version 1.1.0
|
25
|
+
|
4
26
|
* for line types only parsed once the parser returns a string instead of an array with one string
|
5
27
|
|
6
|
-
Version 1.0.1
|
7
|
-
=============
|
28
|
+
## Version 1.0.1
|
8
29
|
|
9
30
|
* added specs
|
10
31
|
* fixed minor parser errors
|
11
32
|
|
12
|
-
Version 1.0.0
|
13
|
-
=============
|
33
|
+
## Version 1.0.0
|
14
34
|
|
15
35
|
* initial release
|
data/Rakefile
CHANGED
@@ -20,15 +20,15 @@ namespace :parser do
|
|
20
20
|
require 'benchmark'
|
21
21
|
require 'simple_po_parser'
|
22
22
|
|
23
|
-
desc "Benchmark of
|
23
|
+
desc "Benchmark of 1000 full PoParser runs of test/benchmark.po"
|
24
24
|
task "benchmark" do
|
25
25
|
pofile = File.expand_path("test/benchmark.po", __dir__)
|
26
26
|
Benchmark.bmbm do |x|
|
27
|
-
x.report("Parser:") {
|
27
|
+
x.report("Parser:") {1000.times { SimplePoParser.parse(pofile) }}
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
desc "Generate 5 random PO files with
|
31
|
+
desc "Generate 5 random PO files with 1000 to 5000 messages and benchmark each full PoParser run"
|
32
32
|
task 'five_random_po_full' do
|
33
33
|
include Benchmark
|
34
34
|
require_relative 'spec/utils/random_pofile_generator'
|
@@ -37,7 +37,7 @@ namespace :parser do
|
|
37
37
|
total = nil
|
38
38
|
total_length = 0
|
39
39
|
for i in 0..5 do
|
40
|
-
length = (Random.new.rand *
|
40
|
+
length = (Random.new.rand * 4000.0 + 1000).to_i
|
41
41
|
total_length += length
|
42
42
|
puts "Benchmarking file of length #{length}"
|
43
43
|
SimplePoParser::RandomPoFileGenerator.generate_file(pofile, length)
|
@@ -109,7 +109,7 @@ module SimplePoParser
|
|
109
109
|
skip_whitespace
|
110
110
|
text = message_line
|
111
111
|
add_result(:msgctxt, text)
|
112
|
-
message_multiline(:msgctxt) if
|
112
|
+
message_multiline(:msgctxt) if @scanner.peek(1) == '"'
|
113
113
|
end
|
114
114
|
msgid
|
115
115
|
rescue PoSyntaxError => pe
|
@@ -127,7 +127,7 @@ module SimplePoParser
|
|
127
127
|
skip_whitespace
|
128
128
|
text = message_line
|
129
129
|
add_result(:msgid, text)
|
130
|
-
message_multiline(:msgid) if
|
130
|
+
message_multiline(:msgid) if @scanner.peek(1) == '"'
|
131
131
|
if msgid_plural
|
132
132
|
msgstr_plural
|
133
133
|
else
|
@@ -155,7 +155,7 @@ module SimplePoParser
|
|
155
155
|
skip_whitespace
|
156
156
|
text = message_line
|
157
157
|
add_result(:msgid_plural, text)
|
158
|
-
message_multiline(:msgid_plural) if
|
158
|
+
message_multiline(:msgid_plural) if @scanner.peek(1) == '"'
|
159
159
|
true
|
160
160
|
else
|
161
161
|
false
|
@@ -174,7 +174,7 @@ module SimplePoParser
|
|
174
174
|
skip_whitespace
|
175
175
|
text = message_line
|
176
176
|
add_result(:msgstr, text)
|
177
|
-
message_multiline(:msgstr) if
|
177
|
+
message_multiline(:msgstr) if @scanner.peek(1) == '"'
|
178
178
|
skip_whitespace
|
179
179
|
raise PoSyntaxError, "Unexpected content after expected message end #{@scanner.peek(10).inspect}" unless @scanner.eos?
|
180
180
|
else
|
@@ -202,7 +202,7 @@ module SimplePoParser
|
|
202
202
|
skip_whitespace
|
203
203
|
text = message_line
|
204
204
|
add_result(msgstr_key, text)
|
205
|
-
message_multiline(msgstr_key) if
|
205
|
+
message_multiline(msgstr_key) if @scanner.peek(1) == '"'
|
206
206
|
msgstr_plural(num+1)
|
207
207
|
elsif num == 0 # and msgstr_key was false
|
208
208
|
raise PoSyntaxError, "Plural message without msgstr[0] is not allowed. Line started unexpectedly with #{@scanner.peek(10).inspect}."
|
@@ -238,7 +238,7 @@ module SimplePoParser
|
|
238
238
|
skip_whitespace
|
239
239
|
text = message_line
|
240
240
|
add_result(key, text)
|
241
|
-
previous_multiline(key) if
|
241
|
+
previous_multiline(key) if @scanner.match?(/#\|\p{Blank}*"/)
|
242
242
|
else
|
243
243
|
raise PoSyntaxError, "Previous comments must start with '#| msg'. #{@scanner.peek(10).inspect} unknown."
|
244
244
|
end
|
@@ -265,8 +265,10 @@ module SimplePoParser
|
|
265
265
|
|
266
266
|
# parses a multiline message
|
267
267
|
#
|
268
|
-
#
|
269
|
-
# starting with the double quote character
|
268
|
+
# Multiline messages are usually indicated by an empty string as the first line,
|
269
|
+
# followed by more lines starting with the double quote character.
|
270
|
+
#
|
271
|
+
# However, according to the PO file standard, the first line can also contain content.
|
270
272
|
def message_multiline(key)
|
271
273
|
begin
|
272
274
|
skip_whitespace
|
@@ -8,7 +8,15 @@ module SimplePoParser
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def parse_file(path)
|
11
|
-
File.open(path,
|
11
|
+
file = File.open(path, "r")
|
12
|
+
if(file.gets =~ /\r$/)
|
13
|
+
# detected windows line ending
|
14
|
+
file.close
|
15
|
+
file = File.open(path, "rt")
|
16
|
+
else
|
17
|
+
file.rewind
|
18
|
+
end
|
19
|
+
file.each_line("\n\n") do |block|
|
12
20
|
block.strip! # dont parse empty blocks
|
13
21
|
@messages << parse_block(block) if block != ''
|
14
22
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# PO Header entry
|
2
|
+
#
|
3
|
+
#, fuzzy
|
4
|
+
msgid ""
|
5
|
+
msgstr ""
|
6
|
+
"Project-Id-Version: simple_po_parser 1\n"
|
7
|
+
"Report-Msgid-Bugs-To: me\n"
|
8
|
+
"POT-Creation-Date: 2012-05-04 12:56+0000\n"
|
9
|
+
"PO-Revision-Date: 2014-05-15 22:24+0330\n"
|
10
|
+
"Last-Translator: Dennis-Florian Herr <dennis.herr@experteer.com>\n"
|
11
|
+
"Language-Team: English\n"
|
12
|
+
"MIME-Version: 1.0\n"
|
13
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
14
|
+
"Content-Transfer-Encoding: 8bit\n"
|
15
|
+
"Plural-Forms: nplurals=1; plural=0;\n"
|
16
|
+
|
17
|
+
# translator-comment
|
18
|
+
#. extract
|
19
|
+
#: reference1
|
20
|
+
msgctxt "Context"
|
21
|
+
msgid "msgid"
|
22
|
+
msgstr "translated"
|
23
|
+
|
24
|
+
# translator-comment
|
25
|
+
#
|
26
|
+
#. extract
|
27
|
+
#: reference1
|
28
|
+
#: reference2
|
29
|
+
#, flag
|
30
|
+
#| msgctxt "previous context"
|
31
|
+
#| msgid ""
|
32
|
+
#| "multiline\n"
|
33
|
+
#|"previous messageid"
|
34
|
+
#| msgid_plural "previous msgid_plural"
|
35
|
+
msgctxt "Context"
|
36
|
+
msgid "msgid"
|
37
|
+
msgid_plural ""
|
38
|
+
"multiline msgid_plural\n"
|
39
|
+
""
|
40
|
+
msgstr[0] "msgstr 0"
|
41
|
+
msgstr[1] ""
|
42
|
+
"msgstr 1 multiline 1\n"
|
43
|
+
"msgstr 1 line 2\n"
|
44
|
+
msgstr[2] "msgstr 2"
|
45
|
+
|
46
|
+
# translator-comment
|
47
|
+
#. extract
|
48
|
+
#: reference1
|
49
|
+
#~ msgctxt "Context"
|
50
|
+
#~ msgid "msgid"
|
51
|
+
#~ msgstr "translated"
|
@@ -4,6 +4,7 @@ describe SimplePoParser::Parser do
|
|
4
4
|
let (:po_header) { File.read(File.expand_path("fixtures/header.po", __dir__))}
|
5
5
|
let(:po_complex_message) { File.read(File.expand_path("fixtures/complex_entry.po", __dir__))}
|
6
6
|
let(:po_simple_message) { File.read(File.expand_path("fixtures/simple_entry.po", __dir__))}
|
7
|
+
let(:po_multiline_message) { File.read(File.expand_path("fixtures/multiline.po", __dir__))}
|
7
8
|
|
8
9
|
it "parses the PO header" do
|
9
10
|
expected_result = {
|
@@ -27,6 +28,15 @@ describe SimplePoParser::Parser do
|
|
27
28
|
expect(SimplePoParser::Parser.new.parse(po_simple_message)).to eq(expected_result)
|
28
29
|
end
|
29
30
|
|
31
|
+
it "parses the multiline entry as expected" do
|
32
|
+
expected_result = {
|
33
|
+
:msgid => ["", "multiline string ", "with empty first line ", "and trailing spaces"],
|
34
|
+
:msgstr => ["multiline string", "with non-empty first line", "and no trailing spaces"],
|
35
|
+
:previous_msgid => ["multiline\\n", "previous messageid", "with non-empty first line"],
|
36
|
+
}
|
37
|
+
expect(SimplePoParser::Parser.new.parse(po_multiline_message)).to eq(expected_result)
|
38
|
+
end
|
39
|
+
|
30
40
|
it "parses the complex entry as expected" do
|
31
41
|
expected_result = {
|
32
42
|
:translator_comment => ["translator-comment", ""],
|
@@ -2,12 +2,16 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe SimplePoParser do
|
4
4
|
let(:po_file) { Pathname.new('spec/simple_po_parser/fixtures/complete_file.po').realpath }
|
5
|
+
let(:crlf_file) { Pathname.new('spec/simple_po_parser/fixtures/crlf_encoded.po').realpath }
|
5
6
|
let(:non_ascii_file) { Pathname.new('spec/simple_po_parser/fixtures/non_ascii_file.po').realpath }
|
6
7
|
let(:po_complex_message) { File.read(File.expand_path("fixtures/complex_entry.po", __dir__))}
|
7
8
|
|
8
9
|
it "parses a po file" do
|
9
10
|
expect(SimplePoParser.parse(po_file)).to be_a_kind_of Array
|
10
11
|
end
|
12
|
+
it "parses crlf encoded files" do
|
13
|
+
expect(SimplePoParser.parse(crlf_file)).to be_a_kind_of Array
|
14
|
+
end
|
11
15
|
|
12
16
|
it "parses a non ascii po file" do
|
13
17
|
expect(SimplePoParser.parse(non_ascii_file)).to be_a_kind_of Array
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_po_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis-Florian Herr
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,6 +46,7 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- ".gitattributes"
|
49
50
|
- ".gitignore"
|
50
51
|
- ".rspec"
|
51
52
|
- ".travis.yml"
|
@@ -62,7 +63,9 @@ files:
|
|
62
63
|
- simple_po_parser.gemspec
|
63
64
|
- spec/simple_po_parser/fixtures/complete_file.po
|
64
65
|
- spec/simple_po_parser/fixtures/complex_entry.po
|
66
|
+
- spec/simple_po_parser/fixtures/crlf_encoded.po
|
65
67
|
- spec/simple_po_parser/fixtures/header.po
|
68
|
+
- spec/simple_po_parser/fixtures/multiline.po
|
66
69
|
- spec/simple_po_parser/fixtures/non_ascii_file.po
|
67
70
|
- spec/simple_po_parser/fixtures/simple_entry.po
|
68
71
|
- spec/simple_po_parser/parser_spec.rb
|
@@ -74,7 +77,7 @@ homepage: http://github.com/experteer/simple_po_parser
|
|
74
77
|
licenses:
|
75
78
|
- MIT
|
76
79
|
metadata: {}
|
77
|
-
post_install_message:
|
80
|
+
post_install_message:
|
78
81
|
rdoc_options: []
|
79
82
|
require_paths:
|
80
83
|
- lib
|
@@ -89,15 +92,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
92
|
- !ruby/object:Gem::Version
|
90
93
|
version: '0'
|
91
94
|
requirements: []
|
92
|
-
|
93
|
-
|
94
|
-
signing_key:
|
95
|
+
rubygems_version: 3.2.15
|
96
|
+
signing_key:
|
95
97
|
specification_version: 4
|
96
98
|
summary: A simple PO file to ruby hash parser
|
97
99
|
test_files:
|
98
100
|
- spec/simple_po_parser/fixtures/complete_file.po
|
99
101
|
- spec/simple_po_parser/fixtures/complex_entry.po
|
102
|
+
- spec/simple_po_parser/fixtures/crlf_encoded.po
|
100
103
|
- spec/simple_po_parser/fixtures/header.po
|
104
|
+
- spec/simple_po_parser/fixtures/multiline.po
|
101
105
|
- spec/simple_po_parser/fixtures/non_ascii_file.po
|
102
106
|
- spec/simple_po_parser/fixtures/simple_entry.po
|
103
107
|
- spec/simple_po_parser/parser_spec.rb
|