PoParser 3.1.1 → 3.2.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +35 -0
- data/.travis.yml +3 -3
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/README.md +9 -2
- data/lib/poparser.rb +13 -2
- data/lib/poparser/tokenizer.rb +19 -8
- data/lib/poparser/version.rb +1 -1
- data/spec/poparser/entry_spec.rb +2 -2
- data/spec/poparser/po_spec.rb +6 -5
- data/spec/poparser/poparser_spec.rb +15 -1
- data/spec/poparser/tokenizer_spec.rb +3 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69d284ad281dcb8de53d79a3b92fb1336ee5ca7a
|
4
|
+
data.tar.gz: a33178e0caffc6d999b3eaf0707cc1c39aa9551f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b780472d5fa52e5b21fffdd65f876c4cf7434bea99b917b6d41baa6c4ba5898b7a6d6175015dd7f098b9e381618c5b8f625d6900b15c496b8ce27bb7da2159d
|
7
|
+
data.tar.gz: 4bbb2febfc6990f33c2788b6a96cdee43b1c8e394925b009a72cc477ad7b7467d88a6174c94201a56330b7dd5a7971d2dc8f681d6980d3d5275f48bf7aed767d
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
Exclude:
|
4
|
+
- 'spec/**/*'
|
5
|
+
- 'db/**/*'
|
6
|
+
- 'app/views/**/*'
|
7
|
+
- 'config/**/*'
|
8
|
+
- 'bin/*'
|
9
|
+
- 'Rakefile'
|
10
|
+
- 'node_modules/**/*'
|
11
|
+
|
12
|
+
Bundler/OrderedGems:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Metrics/BlockLength:
|
16
|
+
Exclude:
|
17
|
+
- 'lib/tasks/**/*'
|
18
|
+
|
19
|
+
Layout/MultilineMethodCallIndentation:
|
20
|
+
Enabled: true
|
21
|
+
EnforcedStyle: indented
|
22
|
+
|
23
|
+
Layout/AccessModifierIndentation:
|
24
|
+
EnforcedStyle: outdent
|
25
|
+
|
26
|
+
Layout/AlignParameters:
|
27
|
+
EnforcedStyle: with_fixed_indentation
|
28
|
+
|
29
|
+
Style/FrozenStringLiteralComment:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/PercentLiteralDelimiters:
|
33
|
+
PreferredDelimiters:
|
34
|
+
'%i': '()'
|
35
|
+
'%w': '()'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -27,9 +27,16 @@ Working with the GEM is pretty easy:
|
|
27
27
|
|
28
28
|
```ruby
|
29
29
|
require 'poparser'
|
30
|
+
|
31
|
+
content = File.read('example.po')
|
32
|
+
po = PoParser.parse(content)
|
33
|
+
# => <PoParser::Po, Translated: 68.1% Untranslated: 20.4% Fuzzy: 11.5%>
|
34
|
+
|
35
|
+
# Or you could pass a file path:
|
36
|
+
|
30
37
|
path = Pathname.new('example.po')
|
31
|
-
po
|
32
|
-
=> <PoParser::Po, Translated: 68.1% Untranslated: 20.4% Fuzzy: 11.5%>
|
38
|
+
po = PoParser.parse_file(path)
|
39
|
+
# => <PoParser::Po, Translated: 68.1% Untranslated: 20.4% Fuzzy: 11.5%>
|
33
40
|
```
|
34
41
|
|
35
42
|
The `parse` method returns a `PO` object which contains all `Entries`:
|
data/lib/poparser.rb
CHANGED
@@ -13,8 +13,19 @@ require_relative 'poparser/version'
|
|
13
13
|
|
14
14
|
module PoParser
|
15
15
|
class << self
|
16
|
-
def parse(
|
17
|
-
|
16
|
+
def parse(payload)
|
17
|
+
if File.exist?(payload)
|
18
|
+
Kernel.warn 'DEPRICATION WARNING: `parse` only accepts content of a '\
|
19
|
+
'PO file as a string and this behaviour will be removed on next '\
|
20
|
+
'major release. Use `parse_file` instead.'
|
21
|
+
parse_file(payload)
|
22
|
+
else
|
23
|
+
Tokenizer.new.extract(payload)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_file(path)
|
28
|
+
Tokenizer.new(true).extract(path)
|
18
29
|
end
|
19
30
|
end
|
20
31
|
end
|
data/lib/poparser/tokenizer.rb
CHANGED
@@ -1,22 +1,33 @@
|
|
1
1
|
module PoParser
|
2
2
|
# Feed each block of PO file to Parser.
|
3
3
|
class Tokenizer
|
4
|
-
def initialize
|
4
|
+
def initialize(is_file = false)
|
5
5
|
@po = Po.new
|
6
|
+
@is_file = is_file
|
6
7
|
end
|
7
8
|
|
8
|
-
def
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
@po << parse_block(block) if block != ''
|
9
|
+
def extract(payload)
|
10
|
+
if @is_file
|
11
|
+
@po.path = payload
|
12
|
+
payload = File.read(payload, mode: 'r:utf-8')
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
|
+
extract_entries(payload)
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
19
|
+
|
18
20
|
def parse_block(block)
|
19
|
-
|
21
|
+
SimplePoParser.parse_message(block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def extract_entries(payload)
|
25
|
+
payload.split("\n\n").each do |block|
|
26
|
+
block.strip!
|
27
|
+
@po << parse_block(block) if block != ''
|
28
|
+
end
|
29
|
+
|
30
|
+
@po
|
20
31
|
end
|
21
32
|
end
|
22
33
|
end
|
data/lib/poparser/version.rb
CHANGED
data/spec/poparser/entry_spec.rb
CHANGED
@@ -132,8 +132,8 @@ describe PoParser::Entry do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'should further parse the obsolete content' do
|
135
|
-
|
136
|
-
@po = PoParser::Tokenizer.new.
|
135
|
+
file = File.read('spec/poparser/fixtures/complex_obsolete.po')
|
136
|
+
@po = PoParser::Tokenizer.new.extract(file)
|
137
137
|
obsolete_entry = @po.obsolete.first
|
138
138
|
expect(obsolete_entry.obsolete?).to be_truthy
|
139
139
|
expect(obsolete_entry.msgctxt.value).to eq('Context')
|
data/spec/poparser/po_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe PoParser::Po do
|
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
-
before
|
14
|
+
before do
|
15
15
|
@po = PoParser::Po.new
|
16
16
|
end
|
17
17
|
|
@@ -68,7 +68,7 @@ describe PoParser::Po do
|
|
68
68
|
context 'search' do
|
69
69
|
before do
|
70
70
|
path = Pathname.new('spec/poparser/fixtures/test.po').realpath
|
71
|
-
@po = PoParser::Tokenizer.new.
|
71
|
+
@po = PoParser::Tokenizer.new(true).extract(path)
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'raises error if label is not valid' do
|
@@ -87,7 +87,7 @@ describe PoParser::Po do
|
|
87
87
|
context 'Header' do
|
88
88
|
before do
|
89
89
|
path = Pathname.new('spec/poparser/fixtures/header.po').realpath
|
90
|
-
@po = PoParser::Tokenizer.new.
|
90
|
+
@po = PoParser::Tokenizer.new(true).extract(path)
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'should respond to header' do
|
@@ -119,9 +119,10 @@ describe PoParser::Po do
|
|
119
119
|
|
120
120
|
it 'throws error if there\'re two header string' do
|
121
121
|
path = Pathname.new('spec/poparser/fixtures/header_error.po').realpath
|
122
|
+
|
122
123
|
expect{
|
123
|
-
|
124
|
-
|
124
|
+
PoParser::Tokenizer.new(true).extract(path)
|
125
|
+
}.to raise_error(RuntimeError, "Duplicate entry, header was already instantiated")
|
125
126
|
end
|
126
127
|
end
|
127
128
|
|
@@ -3,6 +3,7 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe PoParser do
|
5
5
|
let(:po_file) { Pathname.new('spec/poparser/fixtures/tokenizer.po').realpath }
|
6
|
+
let(:po_file_content) { File.read('spec/poparser/fixtures/tokenizer.po') }
|
6
7
|
let(:header_fixture) { Pathname.new('spec/poparser/fixtures/header.po').realpath }
|
7
8
|
let(:multiline_fixture) { Pathname.new('spec/poparser/fixtures/multiline.po').realpath }
|
8
9
|
let(:plural_fixture) { Pathname.new('spec/poparser/fixtures/plural.po').realpath }
|
@@ -12,6 +13,20 @@ describe PoParser do
|
|
12
13
|
expect(PoParser.parse(po_file)).to be_a_kind_of PoParser::Po
|
13
14
|
end
|
14
15
|
|
16
|
+
it 'should print deprecation warning when passing file to parse' do
|
17
|
+
expect(Kernel).to receive(:warn).with(
|
18
|
+
'DEPRICATION WARNING: `parse` only accepts content of a PO '\
|
19
|
+
'file as a string and this behaviour will be removed on next major '\
|
20
|
+
'release. Use `parse_file` instead.'
|
21
|
+
).once
|
22
|
+
|
23
|
+
PoParser.parse(po_file)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'parses a payload' do
|
27
|
+
expect(PoParser.parse(po_file_content)).to be_a_kind_of PoParser::Po
|
28
|
+
end
|
29
|
+
|
15
30
|
it 'correclty parses header fixture' do
|
16
31
|
entry = PoParser::Entry.new(
|
17
32
|
{
|
@@ -132,5 +147,4 @@ describe PoParser do
|
|
132
147
|
allow_any_instance_of(PoParser::Header).to receive(:puts)
|
133
148
|
expect(PoParser.parse(test_fixture).to_s).to eq(expected_result.to_s)
|
134
149
|
end
|
135
|
-
|
136
150
|
end
|
@@ -2,20 +2,18 @@
|
|
2
2
|
require "spec_helper.rb"
|
3
3
|
|
4
4
|
describe PoParser::Tokenizer do
|
5
|
-
let(:token) { PoParser::Tokenizer.new }
|
5
|
+
let(:token) { PoParser::Tokenizer.new(true) }
|
6
6
|
let(:po_file){ Pathname.new('spec/poparser/fixtures/tokenizer.po').realpath }
|
7
7
|
let(:po_file_empty_line){ Pathname.new('spec/poparser/fixtures/tokenizer_empty_line.po').realpath }
|
8
8
|
let(:result) { [{:reference=>"templates:105", :msgid=>"Afrikaans", :msgstr=>"آفریقایی"}, {:flag=>"fuzzy", :msgid=>"Afrikaans", :msgstr=>"آفریقایی" }] }
|
9
9
|
|
10
10
|
it 'should be able to extracts entries' do
|
11
|
-
expect(
|
12
|
-
token.extract_entries(po_file).to_h
|
13
|
-
).to eq(result)
|
11
|
+
expect(token.extract(po_file).to_h).to eq(result)
|
14
12
|
end
|
15
13
|
|
16
14
|
it 'should gracefully handle empty lines at the beginning' do
|
17
15
|
expect(
|
18
|
-
token.
|
16
|
+
token.extract(po_file_empty_line).to_h
|
19
17
|
).to eq(result)
|
20
18
|
end
|
21
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: PoParser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arash Mousavi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_po_parser
|
@@ -62,6 +62,7 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
64
|
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
65
66
|
- ".travis.yml"
|
66
67
|
- CHANGELOG.md
|
67
68
|
- Gemfile
|