PoParser 0.1.0 → 0.1.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 +5 -0
- data/README.md +3 -2
- data/lib/poparser/entry.rb +26 -34
- data/lib/poparser/message.rb +2 -2
- data/lib/poparser/version.rb +1 -1
- metadata +2 -4
- data/spec/poparser/version_spec.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 066ad9b453a020a745330142e832c8922e95a0da
|
4
|
+
data.tar.gz: 8ce3ba60280751f10fb1b3a749d4ceb51247ab13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72264188d5c4bd28a4837cb29ba9cd5389618138ba3cd545c40fb563c0eaa2aff1ec159a8d302e63a0f7e8b2533070356e79e5290a19094071429ed9d7eea71c
|
7
|
+
data.tar.gz: 02465743b232b2649580b9dc89a5b6757412ef3e71abc14129a0bec89a5a831859078a12a64cc9590af2550efe418e616ff6d7511d6150472307f7dd772fa6ee
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
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
|
+
[![Code Climate](https://codeclimate.com/github/arashm/PoParser.png)](https://codeclimate.com/github/arashm/PoParser)
|
5
6
|
|
6
7
|
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).
|
7
8
|
|
@@ -103,10 +104,10 @@ entry.plural?
|
|
103
104
|
You can get or edit each of property of the `Entry`:
|
104
105
|
|
105
106
|
```ruby
|
106
|
-
entry.msgid
|
107
|
+
entry.msgid.to_s
|
107
108
|
#=> "This is an msgid that needs to get translated"
|
108
109
|
entry.translate = "This entry is translated" # or msgstr= alias
|
109
|
-
entry.msgstr
|
110
|
+
entry.msgstr.to_s
|
110
111
|
#=> "This entry is translated"
|
111
112
|
```
|
112
113
|
|
data/lib/poparser/entry.rb
CHANGED
@@ -1,27 +1,22 @@
|
|
1
1
|
module PoParser
|
2
2
|
class Entry
|
3
3
|
# TODO: raise error if a label is not known
|
4
|
-
def initialize(args= {})
|
4
|
+
def initialize(args = {})
|
5
5
|
# Defining all instance variables to prevent warnings
|
6
6
|
LABELS.each do |label|
|
7
7
|
instance_variable_set "@#{label.to_s}".to_sym, nil
|
8
8
|
end
|
9
9
|
|
10
10
|
# Set passed arguments
|
11
|
-
args.each do |
|
12
|
-
|
13
|
-
instance_variable_set "@#{type.to_s}".to_sym, Comment.new(type, string)
|
14
|
-
elsif ENTRIES_LABELS.include? type
|
15
|
-
instance_variable_set "@#{type.to_s}".to_sym, Message.new(type, string)
|
16
|
-
elsif type.to_s.match(/^msgstr\[[0-9]\]/)
|
17
|
-
# If it's a plural msgstr
|
18
|
-
@msgstr ||= []
|
19
|
-
@msgstr << Message.new(type, string)
|
20
|
-
end
|
11
|
+
args.each do |name, value|
|
12
|
+
set_instance_variable(name, value)
|
21
13
|
end
|
22
14
|
|
23
|
-
define_writer_methods
|
15
|
+
define_writer_methods(COMMENTS_LABELS, 'Comment')
|
16
|
+
define_writer_methods(ENTRIES_LABELS, 'Message')
|
24
17
|
define_reader_methods
|
18
|
+
|
19
|
+
self.class.send(:alias_method, :translate, :msgstr=)
|
25
20
|
end
|
26
21
|
|
27
22
|
# Checks if the entry is untraslated
|
@@ -106,38 +101,35 @@ module PoParser
|
|
106
101
|
|
107
102
|
private
|
108
103
|
|
109
|
-
def
|
110
|
-
COMMENTS_LABELS.
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
instance_variable_set "@#{type}".to_sym, Comment.new(type, val)
|
119
|
-
end
|
120
|
-
instance_variable_get "@#{type}".to_sym
|
121
|
-
})
|
122
|
-
end
|
104
|
+
def set_instance_variable(name, value)
|
105
|
+
if COMMENTS_LABELS.include? name
|
106
|
+
instance_variable_set "@#{name.to_s}".to_sym, Comment.new(name, value)
|
107
|
+
elsif ENTRIES_LABELS.include? name
|
108
|
+
instance_variable_set "@#{name.to_s}".to_sym, Message.new(name, value)
|
109
|
+
elsif name.to_s.match(/^msgstr\[[0-9]\]/)
|
110
|
+
# If it's a plural msgstr
|
111
|
+
@msgstr ||= []
|
112
|
+
@msgstr << Message.new(name, value)
|
123
113
|
end
|
114
|
+
end
|
124
115
|
|
125
|
-
|
116
|
+
def define_writer_methods(labels, object)
|
117
|
+
object = PoParser.const_get(object)
|
118
|
+
labels.each do |type, mark|
|
126
119
|
unless Entry.method_defined? "#{type}=".to_sym
|
127
120
|
self.class.send(:define_method, "#{type}=".to_sym, lambda { |val|
|
128
|
-
if instance_variable_get("@#{type}".to_sym).is_a?
|
129
|
-
|
130
|
-
|
131
|
-
|
121
|
+
if instance_variable_get("@#{type}".to_sym).is_a? object
|
122
|
+
klass = instance_variable_get "@#{type}".to_sym
|
123
|
+
klass.type = type
|
124
|
+
klass.str = val
|
132
125
|
else
|
133
|
-
instance_variable_set "@#{type}".to_sym,
|
126
|
+
instance_variable_set "@#{type}".to_sym, object.new(type, val)
|
134
127
|
end
|
128
|
+
# return value
|
135
129
|
instance_variable_get "@#{type}".to_sym
|
136
130
|
})
|
137
131
|
end
|
138
132
|
end
|
139
|
-
|
140
|
-
self.class.send(:alias_method, :translate, :msgstr=)
|
141
133
|
end
|
142
134
|
|
143
135
|
def define_reader_methods
|
data/lib/poparser/message.rb
CHANGED
@@ -11,7 +11,7 @@ module PoParser
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def str
|
14
|
-
@str.join
|
14
|
+
@str.is_a?(Array) ? @str.join : @str
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_s(with_label = false)
|
@@ -30,7 +30,7 @@ module PoParser
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def to_str
|
33
|
-
@str.join
|
33
|
+
@str.is_a?(Array) ? @str.join : @str
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
data/lib/poparser/version.rb
CHANGED
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: 0.1.
|
4
|
+
version: 0.1.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: 2014-05-
|
11
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -148,7 +148,6 @@ files:
|
|
148
148
|
- spec/poparser/test.po
|
149
149
|
- spec/poparser/tokenizer_spec.rb
|
150
150
|
- spec/poparser/transformer_spec.rb
|
151
|
-
- spec/poparser/version_spec.rb
|
152
151
|
- spec/spec_helper.rb
|
153
152
|
homepage: http://github.com/arashm/poparser
|
154
153
|
licenses:
|
@@ -187,5 +186,4 @@ test_files:
|
|
187
186
|
- spec/poparser/test.po
|
188
187
|
- spec/poparser/tokenizer_spec.rb
|
189
188
|
- spec/poparser/transformer_spec.rb
|
190
|
-
- spec/poparser/version_spec.rb
|
191
189
|
- spec/spec_helper.rb
|