simple_po_parser 1.0.0 → 1.0.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/README.md +4 -0
- data/lib/simple_po_parser/parser.rb +7 -6
- data/lib/simple_po_parser/version.rb +1 -1
- data/spec/simple_po_parser/fixtures/complete_file.po +51 -0
- data/spec/simple_po_parser/fixtures/non_ascii_file.po +51 -0
- data/spec/simple_po_parser/parser_spec.rb +91 -0
- data/spec/simple_po_parser/simple_po_parser_spec.rb +20 -0
- data/spec/spec_helper.rb +12 -2
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e68d02e65b414ab6bf84fd752597af39f47f423
|
4
|
+
data.tar.gz: 94bac50f87a8a05c17cf8a368f2f2c02eca168f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91e548c9bbf1221c759d767cd7da8df876b41eb1d1f865dbf87c7175a3b955af8e58ceb314ffc31c82d4d5431ef7eea74c6a8fb4f33bd3737c26ac4583e489a2
|
7
|
+
data.tar.gz: 5f2dd9534520dcbc3cc12b5f6119c8a89147a43dd21f1538d9270e02a803807c97e52bb31d61da4c95cf7f40bc77487e4ab50ca52885c55f7181df4f3f4288a6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Simple Po Parser
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/experteer/simple_po_parser.svg?branch=master)](https://travis-ci.org/experteer/simple_po_parser)
|
4
|
+
[![Coverage Status](https://img.shields.io/coveralls/experteer/simple_po_parser.svg)](https://coveralls.io/github/experteer/simple_po_parser)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/simple_po_parser.svg)](https://badge.fury.io/rb/simple_po_parser)
|
6
|
+
|
3
7
|
This is a simple PO file to ruby hash parser, which complies with [GNU PO file specification](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html). Tested with the msgcat (GNU gettext-tools) 0.18.3 tool.
|
4
8
|
|
5
9
|
## Hash format
|
@@ -23,11 +23,12 @@ module SimplePoParser
|
|
23
23
|
begin
|
24
24
|
lines
|
25
25
|
rescue ParserError => pe
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
error_msg = "SimplePoParser::ParserError"
|
27
|
+
error_msg += pe.message
|
28
|
+
error_msg += "\nParseing result before error: '#{@result}'"
|
29
|
+
error_msg += "\nSimplePoParser filtered backtrace: SimplePoParser::ParserError"
|
30
|
+
backtrace = "#{pe.backtrace.select{|i| i =~ /lib\/simple_po_parser/}.join("\n\tfrom ")}"
|
31
|
+
raise ParserError, error_msg, backtrace
|
31
32
|
end
|
32
33
|
@result
|
33
34
|
end
|
@@ -274,7 +275,7 @@ module SimplePoParser
|
|
274
275
|
skip_whitespace
|
275
276
|
unless end_of_line
|
276
277
|
err_msg = "There should be only whitespace until the end of line"
|
277
|
-
err_msg += "after the double quote character of a message text."
|
278
|
+
err_msg += " after the double quote character of a message text."
|
278
279
|
raise PoSyntaxError.new(err_msg)
|
279
280
|
end
|
280
281
|
text
|
@@ -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"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Persian translation for damned-lies.
|
2
|
+
# Copyright (C) 2012 damned-lies's COPYRIGHT HOLDER
|
3
|
+
# This file is distributed under the same license as the damned-lies package.
|
4
|
+
# Arash Mousavi <mousavi.arash@gmail.com>, 2014.
|
5
|
+
#
|
6
|
+
msgid ""
|
7
|
+
msgstr ""
|
8
|
+
"Project-Id-Version: damned-lies master\n"
|
9
|
+
"Report-Msgid-Bugs-To: \n"
|
10
|
+
"POT-Creation-Date: 2012-05-04 12:56+0000\n"
|
11
|
+
"PO-Revision-Date: 2014-05-15 22:24+0330\n"
|
12
|
+
"Last-Translator: Arash Mousavi <mousavi.arash@gmail.com>\n"
|
13
|
+
"Language-Team: Persian <fa@li.org>\n"
|
14
|
+
"MIME-Version: 1.0\n"
|
15
|
+
"Content-Type: text/plain; charset=UTF-8\n"
|
16
|
+
"Content-Transfer-Encoding: 8bit\n"
|
17
|
+
"Plural-Forms: nplurals=1; plural=0;\n"
|
18
|
+
"X-Generator: Poedit 1.6.4\n"
|
19
|
+
|
20
|
+
#: database-content.py:1 database-content.py:129 settings.py:52
|
21
|
+
msgid "Afrikaans"
|
22
|
+
msgstr "آفریقایی"
|
23
|
+
|
24
|
+
#: templates/vertimus/vertimus_detail.html:105
|
25
|
+
#, python-format
|
26
|
+
msgid " including <a href=\"%(img_url)s\">%(stats)s image</a>"
|
27
|
+
msgid_plural " including <a href=\"%(img_url)s\">%(stats)s images</a>"
|
28
|
+
msgstr[0] ""
|
29
|
+
msgstr[1] ""
|
30
|
+
|
31
|
+
#: templates/vertimus/vertimus_detail.html:136 vertimus/forms.py:79
|
32
|
+
msgid "Invalid action. Someone probably posted another action just before you."
|
33
|
+
msgstr ""
|
34
|
+
"فعالیت نامعتبر. شاید یک نفر دیگر دقیقا قبل از شما یک فعالیت دیگر ارسال کرده "
|
35
|
+
"است."
|
36
|
+
|
37
|
+
#: vertimus/models.py:470
|
38
|
+
#, python-format
|
39
|
+
#| msgid ""
|
40
|
+
#| "Hello,\n"
|
41
|
+
#| "\n"
|
42
|
+
#| "The new state of %(module)s - %(branch)s - %(domain)s (%(language)s) is "
|
43
|
+
#| "now '%(new_state)s'.\n"
|
44
|
+
#| "%(url)s\n"
|
45
|
+
#| "\n"
|
46
|
+
msgid ""
|
47
|
+
"The new state of %(module)s - %(branch)s - %(domain)s (%(language)s) is now "
|
48
|
+
"'%(new_state)s'."
|
49
|
+
msgstr ""
|
50
|
+
"وضعیت جدید %(module)s - %(branch)s - %(domain)s (%(language)s) هماکنون "
|
51
|
+
"«%(new_state)s» است."
|
@@ -46,4 +46,95 @@ describe SimplePoParser::Parser do
|
|
46
46
|
expect(SimplePoParser::Parser.parse(po_complex_message)).to eq(expected_result)
|
47
47
|
end
|
48
48
|
|
49
|
+
context "Errors" do
|
50
|
+
it "errors cascade to ParserError" do
|
51
|
+
message = "invalid message"
|
52
|
+
expect{ SimplePoParser::Parser.parse(message) }.to raise_error(SimplePoParser::ParserError)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "raises an error if there is no msgid" do
|
56
|
+
message = "# comment\nmsgctxt \"ctxt\"\nmsgstr \"translation\""
|
57
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
58
|
+
to raise_error(SimplePoParser::ParserError, /Message without msgid is not allowed/)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "raises an error if there is no msgstr in singular message" do
|
62
|
+
message = "# comment\nmsgctxt \"ctxt\"\nmsgid \"msg\""
|
63
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
64
|
+
to raise_error(SimplePoParser::ParserError,
|
65
|
+
/Singular message without msgstr is not allowed/)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "raises an error if there is no msgstr[0] in plural message" do
|
69
|
+
message = "# comment\nmsgid \"id\"\nmsgid_plural \"msg plural\""
|
70
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
71
|
+
to raise_error(SimplePoParser::ParserError,
|
72
|
+
/Plural message without msgstr\[0\] is not allowed/)
|
73
|
+
|
74
|
+
message = "# comment\nmsgid \"id\"\nmsgid_plural \"msg plural\"\nmsgstr[1] \"plural trans\""
|
75
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
76
|
+
to raise_error(SimplePoParser::ParserError,
|
77
|
+
/Bad 'msgstr\[index\]' index/)
|
78
|
+
end
|
79
|
+
|
80
|
+
context "comments" do
|
81
|
+
it "raises an error on unknown comment types" do
|
82
|
+
message = "#- no such comment type"
|
83
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
84
|
+
to raise_error(SimplePoParser::ParserError, /Unknown comment type/)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "raises an error on unknown previous comment types" do
|
88
|
+
message = "#| msgstr \"no such comment type\""
|
89
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
90
|
+
to raise_error(SimplePoParser::ParserError, /Previous comment type .*? unknown/)
|
91
|
+
message = "#| bla "
|
92
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
93
|
+
to raise_error(SimplePoParser::ParserError, /Previous comments must start with '#| msg'/)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "raises an error if any lines are not marked obsolete after the first obsolete line" do
|
97
|
+
message = "# comment\n#~msgid \"hi\"\nmsgstr \"should be obsolete\""
|
98
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
99
|
+
to raise_error(SimplePoParser::ParserError,
|
100
|
+
/All lines must be obsolete after the first obsolete line, but got/)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "raises an error if previous comments are not marked obsolete in obsolete entries" do
|
104
|
+
message = "# comment\n#| msgid \"hi\"\n#~msgid \"hi\"\n#~msgstr \"should be obsolete\""
|
105
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
106
|
+
to raise_error(SimplePoParser::ParserError,
|
107
|
+
/Previous comment entries need to be marked obsolete too in obsolete message entries/)
|
108
|
+
message = "# comment\n#| msgctxt \"hi\"\n#~msgid \"hi\"\n#~msgstr \"should be obsolete\""
|
109
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
110
|
+
to raise_error(SimplePoParser::ParserError,
|
111
|
+
/Previous comment entries need to be marked obsolete too in obsolete message entries/)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "message_line" do
|
116
|
+
it "raises an error if a message_line does not start with a double quote" do
|
117
|
+
message = "msgid No starting double quote\""
|
118
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
119
|
+
to raise_error(SimplePoParser::ParserError,
|
120
|
+
/A message text needs to start with the double quote character/)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "raises an error if a message_line does not end with a double quote" do
|
124
|
+
message = "msgid \"No ending double quote"
|
125
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
126
|
+
to raise_error(SimplePoParser::ParserError,
|
127
|
+
/The message text .*? must be finished with the double quote character/)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "raises an error if there is anything but whitespace after the ending double quote" do
|
131
|
+
message = "msgid \"text\" this shouldn't be here"
|
132
|
+
expect{ SimplePoParser::Parser.parse(message) }.
|
133
|
+
to raise_error(SimplePoParser::ParserError,
|
134
|
+
/There should be only whitespace until the end of line after the double quote character/)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
49
140
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe SimplePoParser do
|
4
|
+
let(:po_file) { Pathname.new('spec/simple_po_parser/fixtures/complete_file.po').realpath }
|
5
|
+
let(:non_ascii_file) { Pathname.new('spec/simple_po_parser/fixtures/non_ascii_file.po').realpath }
|
6
|
+
let(:po_complex_message) { File.read(File.expand_path("fixtures/complex_entry.po", __dir__))}
|
7
|
+
|
8
|
+
it "parses a po file" do
|
9
|
+
expect(SimplePoParser.parse(po_file)).to be_a_kind_of Array
|
10
|
+
end
|
11
|
+
|
12
|
+
it "parses a non ascii po file" do
|
13
|
+
expect(SimplePoParser.parse(non_ascii_file)).to be_a_kind_of Array
|
14
|
+
end
|
15
|
+
|
16
|
+
it "parses a single message" do
|
17
|
+
expect(SimplePoParser.parse_message(po_complex_message)).to be_a_kind_of Hash
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,11 +5,21 @@
|
|
5
5
|
#
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
7
|
|
8
|
-
require '
|
8
|
+
require 'simplecov'
|
9
9
|
require 'coveralls'
|
10
10
|
require 'awesome_print'
|
11
11
|
|
12
|
-
|
12
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
13
|
+
[SimpleCov::Formatter::HTMLFormatter,
|
14
|
+
Coveralls::SimpleCov::Formatter]
|
15
|
+
)
|
16
|
+
|
17
|
+
SimpleCov.start do
|
18
|
+
add_group "gem", "lib"
|
19
|
+
add_group "spec", "spec"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'simple_po_parser'
|
13
23
|
|
14
24
|
RSpec.configure do |config|
|
15
25
|
config.raise_errors_for_deprecations!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_po_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis-Florian Herr
|
@@ -74,10 +74,13 @@ files:
|
|
74
74
|
- lib/simple_po_parser/tokenizer.rb
|
75
75
|
- lib/simple_po_parser/version.rb
|
76
76
|
- simple_po_parser.gemspec
|
77
|
+
- spec/simple_po_parser/fixtures/complete_file.po
|
77
78
|
- spec/simple_po_parser/fixtures/complex_entry.po
|
78
79
|
- spec/simple_po_parser/fixtures/header.po
|
80
|
+
- spec/simple_po_parser/fixtures/non_ascii_file.po
|
79
81
|
- spec/simple_po_parser/fixtures/simple_entry.po
|
80
82
|
- spec/simple_po_parser/parser_spec.rb
|
83
|
+
- spec/simple_po_parser/simple_po_parser_spec.rb
|
81
84
|
- spec/spec_helper.rb
|
82
85
|
- spec/utils/random_pofile_generator.rb
|
83
86
|
- test/benchmark.po
|
@@ -106,9 +109,12 @@ signing_key:
|
|
106
109
|
specification_version: 4
|
107
110
|
summary: A simple PO file to ruby hash parser
|
108
111
|
test_files:
|
112
|
+
- spec/simple_po_parser/fixtures/complete_file.po
|
109
113
|
- spec/simple_po_parser/fixtures/complex_entry.po
|
110
114
|
- spec/simple_po_parser/fixtures/header.po
|
115
|
+
- spec/simple_po_parser/fixtures/non_ascii_file.po
|
111
116
|
- spec/simple_po_parser/fixtures/simple_entry.po
|
112
117
|
- spec/simple_po_parser/parser_spec.rb
|
118
|
+
- spec/simple_po_parser/simple_po_parser_spec.rb
|
113
119
|
- spec/spec_helper.rb
|
114
120
|
- spec/utils/random_pofile_generator.rb
|