PoParser 2.0.0 → 2.0.1
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/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/poparser/header.rb +29 -3
- data/lib/poparser/version.rb +1 -1
- data/spec/poparser/fixtures/header.po +1 -0
- data/spec/poparser/header_spec.rb +30 -4
- data/spec/poparser/po_spec.rb +15 -0
- 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: 4001750c5298956f310f421c8f9cfe8d8c64283c
|
4
|
+
data.tar.gz: bff6cd76882df6d406cc2f993a010a48b41320b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a67f9b02929802776b34717d0f4d3f3144bf500a9df17a4f9811f43446f15b64f964ccb0736486e44c73bc22760a3687a98fe0414c92e70843ef5247b7b8821e
|
7
|
+
data.tar.gz: 2ffcdb67d60a39d43d49f55222e1dbae130a852522105a1452adebe57285332c68741ac60aefa8c5fbcedeed61a34cc66c183b7bace7588f62993296a7182db4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/poparser/header.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module PoParser
|
2
2
|
class Header
|
3
|
-
attr_reader :entry, :original_configs
|
3
|
+
attr_reader :entry, :original_configs, :flag
|
4
4
|
attr_accessor :comments, :pot_creation_date, :po_revision_date, :project_id,
|
5
5
|
:report_to, :last_translator, :team, :language, :charset,
|
6
6
|
:encoding, :plural_forms
|
@@ -9,6 +9,7 @@ module PoParser
|
|
9
9
|
@entry = entry
|
10
10
|
@comments = entry.translator_comment.value
|
11
11
|
@original_configs = convert_msgstr_to_hash(entry.msgstr)
|
12
|
+
@flag = entry.flag
|
12
13
|
|
13
14
|
HEADER_LABELS.each do |k, v|
|
14
15
|
instance_variable_set "@#{k.to_s}".to_sym, @original_configs[v]
|
@@ -23,15 +24,40 @@ module PoParser
|
|
23
24
|
@original_configs.merge(hash)
|
24
25
|
end
|
25
26
|
|
27
|
+
# Checks if the entry is fuzzy
|
28
|
+
#
|
29
|
+
# @return [Boolean]
|
30
|
+
def fuzzy?
|
31
|
+
@flag.to_s.match('fuzzy') ? true : false
|
32
|
+
end
|
33
|
+
|
34
|
+
# Flag the entry as Fuzzy
|
35
|
+
# @return [Header]
|
36
|
+
def flag_as_fuzzy
|
37
|
+
@flag = 'fuzzy'
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
# Set flag to a custom string
|
42
|
+
def flag_as(flag)
|
43
|
+
raise ArgumentError if flag.class != String
|
44
|
+
@flag = flag
|
45
|
+
end
|
46
|
+
|
26
47
|
def to_h
|
27
48
|
@entry.to_h
|
28
49
|
end
|
29
50
|
|
30
51
|
def to_s
|
31
52
|
string = []
|
32
|
-
@comments.
|
33
|
-
|
53
|
+
if @comments.is_a?(Array)
|
54
|
+
@comments.each do |comment|
|
55
|
+
string << "# #{comment}".strip
|
56
|
+
end
|
57
|
+
else
|
58
|
+
string << "# #{@comments}".strip
|
34
59
|
end
|
60
|
+
string << "#, #{@flag.to_s}" if @flag
|
35
61
|
string << "msgid \"\"\nmsgstr \"\""
|
36
62
|
configs.each do |k, v|
|
37
63
|
if v.nil? || v.empty?
|
data/lib/poparser/version.rb
CHANGED
@@ -7,10 +7,6 @@ describe PoParser::Header do
|
|
7
7
|
msgstr: ["Project-Id-Version: gnome-shell-extensions gnome-3-0\\n", "Report-Msgid-Bugs-To: http://bugzilla.gnome.org/enter_bug.cgi?product=gnome-", "shell&keywords=I18N+L10N&component=extensions\\n", "POT-Creation-Date: 2014-08-28 07:40+0000\\n", "PO-Revision-Date: 2014-08-28 19:59+0430\\n", "Last-Translator: Arash Mousavi <mousavi.arash@gmail.com>\\n", "Language-Team: Persian <>\\n", "Language: fa_IR\\n", "MIME-Version: 1.0\\n", "Content-Type: text/plain; charset=UTF-8\\n", "Content-Transfer-Encoding: 8bit\\n", "X-Poedit-SourceCharset: utf-8\\n", "X-Generator: Gtranslator 2.91.6\\n", "Plural-Forms: nplurals=1; plural=0;\\n"]}
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:comment) do
|
11
|
-
"Persian translation for gnome-shell-extensions.\nCopyright (C) 2011 Iranian Free Software Users Group (IFSUG.org) translation team.\nThis file is distributed under the same license as the gnome-shell-extensions package.\nArash Mousavi <mousavi.arash@gmail.com>, 2011, 2013, 2014.\n"
|
12
|
-
end
|
13
|
-
|
14
10
|
let(:labels) {
|
15
11
|
[
|
16
12
|
:pot_creation_date, :po_revision_date, :project_id,
|
@@ -41,4 +37,34 @@ describe PoParser::Header do
|
|
41
37
|
expect(@header.configs['Language']).to eq('en_US')
|
42
38
|
end
|
43
39
|
|
40
|
+
context 'Comments' do
|
41
|
+
it 'should handle single line comments' do
|
42
|
+
@header.comments = "This is the header"
|
43
|
+
expect(@header.to_s).to start_with("# This is the header\nmsgid")
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should handle single multiline comments' do
|
47
|
+
@header.comments = ["This is a header", "with two lines"]
|
48
|
+
expect(@header.to_s).to start_with("# This is a header\n# with two lines\nmsgid")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'Flags' do
|
53
|
+
it 'should check if a entry is fuzzy' do
|
54
|
+
expect(@header.fuzzy?).to be_falsy
|
55
|
+
@header.flag_as('fuzzy')
|
56
|
+
expect(@header.fuzzy?).to be_truthy
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should flag a entry as fuzzy' do
|
60
|
+
expect(@header.flag_as_fuzzy).to be_truthy
|
61
|
+
expect(@header.flag).to eq('fuzzy')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should be able to set a custome flag' do
|
65
|
+
expect(@header.flag_as 'python-format').to be_truthy
|
66
|
+
expect(@header.flag).to eq('python-format')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
44
70
|
end
|
data/spec/poparser/po_spec.rb
CHANGED
@@ -102,6 +102,21 @@ describe PoParser::Po do
|
|
102
102
|
expect(@po.header.comments).to eq(["Arash Mousavi <mousavi.arash@gmail.com>, 2014.", ""])
|
103
103
|
end
|
104
104
|
|
105
|
+
it 'should parse the flag and be fuzzy' do
|
106
|
+
expect(@po.header.flag.to_s).to eq('fuzzy')
|
107
|
+
expect(@po.header.fuzzy?).to eq(true)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should flag a entry as fuzzy' do
|
111
|
+
expect(@po.header.flag_as_fuzzy).to be_truthy
|
112
|
+
expect(@po.header.flag).to eq('fuzzy')
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should be able to set a custome flag' do
|
116
|
+
expect(@po.header.flag_as 'python-format').to be_truthy
|
117
|
+
expect(@po.header.flag).to eq('python-format')
|
118
|
+
end
|
119
|
+
|
105
120
|
it 'throws error if there\'re two header string' do
|
106
121
|
path = Pathname.new('spec/poparser/fixtures/header_error.po').realpath
|
107
122
|
expect{
|
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: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arash Mousavi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|