PoParser 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/CHANGELOG.md +4 -0
- data/README.md +19 -2
- data/lib/poparser/po.rb +16 -0
- data/lib/poparser/version.rb +1 -1
- data/poparser.gemspec +1 -1
- data/spec/poparser/{test.po → fixtures/test.po} +0 -0
- data/spec/poparser/po_spec.rb +19 -0
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a310a16fa33cd64c3cb41e3e0c62ffdc2605953
|
4
|
+
data.tar.gz: 30ecf8f919e4d28e530c7ba3fed2d1f145507ada
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f087afddd470840a6bcd7a7c7d8c538ca8cfc29aaca6eacef102b7573925d256833157211866b0ae96eab5e78556e33e7346071370a4810cf79ae4db19ef37c1
|
7
|
+
data.tar.gz: c9c277fe627b1543496387b3cf683ee24b206691daae7656da8235b6a054b12b32d3c144f30c107e85ef2602c8d7d5cf5bc84560805f2e947457e07b96301081
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## Version 0.2.1
|
2
|
+
|
3
|
+
* Add search_in method.
|
4
|
+
|
1
5
|
## Version 0.2.0
|
2
6
|
|
3
7
|
* Some entries in PO files are started with "#~", these entries are just kept by program for later use and are not counted as active entries. `PoParser` now supports them. We won't count them in stats or show them in Tanslated or Untranslated entries. They're just there.
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/arashm/PoParser.svg?branch=master)](https://travis-ci.org/arashm/PoParser)
|
4
4
|
[![Coverage Status](https://img.shields.io/coveralls/arashm/PoParser.svg)](https://coveralls.io/r/arashm/PoParser)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/arashm/PoParser.png)](https://codeclimate.com/github/arashm/PoParser)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/PoParser.svg)](http://badge.fury.io/rb/PoParser)
|
6
7
|
|
7
8
|
A Ruby PO file parser, editor and generator. PO files are translation files generated by GNU/Gettext tool. This GEM is compatible with [GNU PO file specification](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html). report misbehaviours and bugs, to the [issue tracker](https://github.com/arashm/PoParser/issues).
|
8
9
|
|
@@ -36,7 +37,9 @@ The `parse` method returns a `PO` object which contains all `Entries`:
|
|
36
37
|
# get all entries
|
37
38
|
po.entries # or .all alias
|
38
39
|
|
39
|
-
# include cashed entries (started with "#~", these
|
40
|
+
# include cashed entries (started with "#~", these
|
41
|
+
# entries are just kept by program for later use and are
|
42
|
+
# not counted as active entries)
|
40
43
|
po.entries(true)
|
41
44
|
|
42
45
|
# get all fuzzy entries
|
@@ -132,7 +135,21 @@ entry.to_s(true)
|
|
132
135
|
|
133
136
|
### Searching
|
134
137
|
|
135
|
-
`PO` is an `Enumerable`. All exciting methods from `Enumerable` are available in `PO`.
|
138
|
+
`PO` is an `Enumerable`. All exciting methods from `Enumerable` are available in `PO`. The `PO` yields `Entry`.
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
po.find_all do |entry|
|
142
|
+
entry.msgid.str.match(/some text/i)
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
There is a helper method that does the same:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
po.search_in(:msgstr, 'some string to search')
|
150
|
+
```
|
151
|
+
|
152
|
+
This method returns an array of matched entries.
|
136
153
|
|
137
154
|
### Saving
|
138
155
|
You can simply save the PO file using the `PO` object:
|
data/lib/poparser/po.rb
CHANGED
@@ -87,6 +87,22 @@ module PoParser
|
|
87
87
|
end
|
88
88
|
alias_method :length, :size
|
89
89
|
|
90
|
+
# Search for entries with provided string
|
91
|
+
#
|
92
|
+
# @param label [Symbol] One of the known LABELS
|
93
|
+
# @param string [String] String to search for
|
94
|
+
# @return [Array] Array of matched entries
|
95
|
+
def search_in(label, string)
|
96
|
+
if !LABELS.include? label.to_sym
|
97
|
+
raise ArgumentError, "Unknown key: #{label}"
|
98
|
+
end
|
99
|
+
|
100
|
+
find_all do |entry|
|
101
|
+
text = entry.send(label).str
|
102
|
+
text.match(/#{string}/i)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
90
106
|
# Shows statistics and status of the provided file in percentage.
|
91
107
|
#
|
92
108
|
# @return [Hash] a hash of translated, untranslated and fuzzy percentages
|
data/lib/poparser/version.rb
CHANGED
data/poparser.gemspec
CHANGED
File without changes
|
data/spec/poparser/po_spec.rb
CHANGED
@@ -52,4 +52,23 @@ describe PoParser::Po do
|
|
52
52
|
@po << cached
|
53
53
|
expect(@po.size).to eq(1)
|
54
54
|
end
|
55
|
+
|
56
|
+
context 'search' do
|
57
|
+
before do
|
58
|
+
path = Pathname.new('spec/poparser/fixtures/test.po').realpath
|
59
|
+
@po = PoParser::Tokenizer.new.extract_entries(path)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'raises error if label is not valid' do
|
63
|
+
expect{
|
64
|
+
@po.search_in(:wrong, 'sth')
|
65
|
+
}.to raise_error(ArgumentError, 'Unknown key: wrong')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'searches in PO file' do
|
69
|
+
result = @po.search_in(:msgid, 'Invalid action')
|
70
|
+
expect(result.length).to eq(1)
|
71
|
+
expect(result[0].msgid.str).to eq('Invalid action. Someone probably posted another action just before you.')
|
72
|
+
end
|
73
|
+
end
|
55
74
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: PoParser
|
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
|
- Arash Mousavi
|
@@ -14,16 +14,16 @@ dependencies:
|
|
14
14
|
name: parslet
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,12 +146,12 @@ files:
|
|
146
146
|
- spec/poparser/entry_spec.rb
|
147
147
|
- spec/poparser/fixtures/multiline.po
|
148
148
|
- spec/poparser/fixtures/plural.po
|
149
|
+
- spec/poparser/fixtures/test.po
|
149
150
|
- spec/poparser/fixtures/tokenizer.po
|
150
151
|
- spec/poparser/message_spec.rb
|
151
152
|
- spec/poparser/parser_spec.rb
|
152
153
|
- spec/poparser/po_spec.rb
|
153
154
|
- spec/poparser/poparser_spec.rb
|
154
|
-
- spec/poparser/test.po
|
155
155
|
- spec/poparser/tokenizer_spec.rb
|
156
156
|
- spec/poparser/transformer_spec.rb
|
157
157
|
- spec/spec_helper.rb
|
@@ -184,13 +184,12 @@ test_files:
|
|
184
184
|
- spec/poparser/entry_spec.rb
|
185
185
|
- spec/poparser/fixtures/multiline.po
|
186
186
|
- spec/poparser/fixtures/plural.po
|
187
|
+
- spec/poparser/fixtures/test.po
|
187
188
|
- spec/poparser/fixtures/tokenizer.po
|
188
189
|
- spec/poparser/message_spec.rb
|
189
190
|
- spec/poparser/parser_spec.rb
|
190
191
|
- spec/poparser/po_spec.rb
|
191
192
|
- spec/poparser/poparser_spec.rb
|
192
|
-
- spec/poparser/test.po
|
193
193
|
- spec/poparser/tokenizer_spec.rb
|
194
194
|
- spec/poparser/transformer_spec.rb
|
195
195
|
- spec/spec_helper.rb
|
196
|
-
has_rdoc:
|