puttext 0.1.1 → 0.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/.codeclimate.yml +0 -0
- data/.gitattributes +0 -0
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.rubocop.yml +0 -0
- data/.ruby-version +0 -0
- data/.travis.yml +0 -0
- data/Gemfile +0 -0
- data/Gemfile.lock +4 -2
- data/LICENSE +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/lib/puttext.rb +0 -0
- data/lib/puttext/cmdline.rb +0 -0
- data/lib/puttext/extractor.rb +0 -0
- data/lib/puttext/parser/base.rb +0 -0
- data/lib/puttext/parser/ruby.rb +0 -0
- data/lib/puttext/parser/slim.rb +0 -0
- data/lib/puttext/po_entry.rb +17 -3
- data/lib/puttext/po_file.rb +19 -2
- data/puttext.gemspec +3 -2
- data/spec/fixtures/extractor_fixtures/another_file.php +0 -0
- data/spec/fixtures/extractor_fixtures/file_1.rb +0 -0
- data/spec/fixtures/extractor_fixtures/file_2.rb +0 -0
- data/spec/fixtures/extractor_fixtures/random_file.txt +0 -0
- data/spec/fixtures/extractor_fixtures/subfolder/subfile.py +0 -0
- data/spec/fixtures/extractor_fixtures/subfolder/subfile_1.rb +0 -0
- data/spec/fixtures/extractor_fixtures/subfolder/subfile_2.rb +0 -0
- data/spec/fixtures/parser_base_shared_fixture.rb +0 -0
- data/spec/shared/parser_base_shared.rb +0 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/extractor_spec.rb +0 -0
- data/spec/unit/parser/ruby_spec.rb +0 -0
- data/spec/unit/parser/slim_spec.rb +0 -0
- data/spec/unit/po_entry_spec.rb +23 -1
- data/spec/unit/po_file_spec.rb +15 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17a3eeac3b04d7960efb45c4bb8612d6d27e7dd0
|
4
|
+
data.tar.gz: c7f567b35813bbda434db72d9d78d808c0cdcc92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3aee3dda5612c226367c922913b1250f6693f62a372d2c7c9a9e7b5d362888c3d647a578fd5b72858831d7b57373b8d8437323eed0f3da374713b60cd185f82
|
7
|
+
data.tar.gz: baf6b7a5508f58c0adac8ecb8fb64d55c80eba49879bbd224192e1a885bf7e58599259e127b1ff24cbd9d2f053ebad709e7fd3f809f13d0a518d34c5853e80e0
|
data/.codeclimate.yml
CHANGED
File without changes
|
data/.gitattributes
CHANGED
File without changes
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.rubocop.yml
CHANGED
File without changes
|
data/.ruby-version
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
puttext (0.
|
4
|
+
puttext (0.2.0)
|
5
5
|
parser (>= 2.4.0.0, < 3.0)
|
6
|
+
unindent
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -48,6 +49,7 @@ GEM
|
|
48
49
|
tilt (>= 1.3.3, < 2.1)
|
49
50
|
temple (0.7.7)
|
50
51
|
tilt (2.0.7)
|
52
|
+
timecop (0.8.1)
|
51
53
|
unicode-display_width (1.2.1)
|
52
54
|
unindent (1.0)
|
53
55
|
|
@@ -62,7 +64,7 @@ DEPENDENCIES
|
|
62
64
|
rubocop (~> 0.46.0)
|
63
65
|
simplecov
|
64
66
|
slim (~> 3.0)
|
65
|
-
|
67
|
+
timecop
|
66
68
|
|
67
69
|
BUNDLED WITH
|
68
70
|
1.14.6
|
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/lib/puttext.rb
CHANGED
File without changes
|
data/lib/puttext/cmdline.rb
CHANGED
File without changes
|
data/lib/puttext/extractor.rb
CHANGED
File without changes
|
data/lib/puttext/parser/base.rb
CHANGED
File without changes
|
data/lib/puttext/parser/ruby.rb
CHANGED
File without changes
|
data/lib/puttext/parser/slim.rb
CHANGED
File without changes
|
data/lib/puttext/po_entry.rb
CHANGED
@@ -15,6 +15,8 @@ module PutText
|
|
15
15
|
attr_reader :msgid
|
16
16
|
attr_reader :msgid_plural
|
17
17
|
attr_reader :msgctxt
|
18
|
+
attr_reader :msgstr
|
19
|
+
attr_reader :flags
|
18
20
|
attr_reader :references
|
19
21
|
|
20
22
|
# Create a new POEntry
|
@@ -26,8 +28,10 @@ module PutText
|
|
26
28
|
# @option attrs [String] :msgid_plural the pluralized id of the string (the
|
27
29
|
# pluralized string that needs to be translated).
|
28
30
|
# @option attrs [String] :msgctxt the context of the string.
|
31
|
+
# @option attrs [Array<String>] :msgstr the translated strings.
|
29
32
|
# @option attrs [Array<String>] :references a list of files with line
|
30
33
|
# numbers, pointing to where the string was found.
|
34
|
+
# @option attrs [Array<String>] :flags a list of flags for this entry.
|
31
35
|
# @option attrs [String] :separator the separator of context from id in
|
32
36
|
# :msgid.
|
33
37
|
def initialize(attrs)
|
@@ -38,7 +42,9 @@ module PutText
|
|
38
42
|
@msgid = id
|
39
43
|
@msgctxt = attrs[:msgctxt] || ctx
|
40
44
|
@msgid_plural = attrs[:msgid_plural]
|
45
|
+
@msgstr = Array(attrs[:msgstr] || '')
|
41
46
|
@references = attrs[:references] || []
|
47
|
+
@flags = attrs[:flags] || []
|
42
48
|
end
|
43
49
|
|
44
50
|
# Convert the entry to a string representation, to be written to a .po file
|
@@ -48,6 +54,7 @@ module PutText
|
|
48
54
|
|
49
55
|
# Add comments
|
50
56
|
str = add_comment(str, ':', @references.join(' ')) if references?
|
57
|
+
str = add_comment(str, ',', @flags.join("\n")) if flags?
|
51
58
|
|
52
59
|
# Add id and context
|
53
60
|
str = add_string(str, 'msgctxt', @msgctxt) if @msgctxt
|
@@ -64,6 +71,12 @@ module PutText
|
|
64
71
|
!@references.empty?
|
65
72
|
end
|
66
73
|
|
74
|
+
# Check if the entry has any flags.
|
75
|
+
# @return [Boolean] whether the entry has any flags.
|
76
|
+
def flags?
|
77
|
+
!@flags.empty?
|
78
|
+
end
|
79
|
+
|
67
80
|
# Check if the entry has a plural form.
|
68
81
|
# @return [Boolean] whether the entry has a plural form.
|
69
82
|
def plural?
|
@@ -123,10 +136,11 @@ module PutText
|
|
123
136
|
|
124
137
|
def add_translations(str)
|
125
138
|
if plural?
|
126
|
-
|
127
|
-
|
139
|
+
@msgstr.each_with_index do |msgstr, index|
|
140
|
+
add_string(str, "msgstr[#{index}]", msgstr)
|
141
|
+
end
|
128
142
|
else
|
129
|
-
add_string(str, 'msgstr',
|
143
|
+
add_string(str, 'msgstr', @msgstr.first)
|
130
144
|
end
|
131
145
|
|
132
146
|
str
|
data/lib/puttext/po_file.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'unindent'
|
4
|
+
require_relative 'po_entry'
|
5
|
+
|
3
6
|
module PutText
|
4
7
|
class POFile
|
5
8
|
attr_accessor :entries
|
@@ -9,6 +12,18 @@ module PutText
|
|
9
12
|
# be placed in this file.
|
10
13
|
def initialize(entries)
|
11
14
|
@entries = entries
|
15
|
+
|
16
|
+
now = Time.now.strftime('%Y-%m-%d %H:%M%z')
|
17
|
+
|
18
|
+
@header_entry = POEntry.new(
|
19
|
+
flags: ['fuzzy'],
|
20
|
+
msgid: '',
|
21
|
+
msgstr: <<-STRING.unindent
|
22
|
+
POT-Creation-Date: #{now}
|
23
|
+
MIME-Version: 1.0
|
24
|
+
Content-Type: text/plain; charset=UTF-8
|
25
|
+
STRING
|
26
|
+
)
|
12
27
|
end
|
13
28
|
|
14
29
|
def to_s
|
@@ -22,8 +37,10 @@ module PutText
|
|
22
37
|
def write_to(io)
|
23
38
|
deduplicate
|
24
39
|
|
25
|
-
@
|
26
|
-
|
40
|
+
io.write(@header_entry.to_s)
|
41
|
+
|
42
|
+
@entries.each do |entry|
|
43
|
+
io.write("\n")
|
27
44
|
io.write(entry.to_s)
|
28
45
|
end
|
29
46
|
end
|
data/puttext.gemspec
CHANGED
@@ -4,7 +4,7 @@ require 'date'
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'puttext'
|
7
|
-
s.version = '0.
|
7
|
+
s.version = '0.2.0'
|
8
8
|
s.date = Date.today.to_s
|
9
9
|
s.summary = 'Extract gettext strings from Ruby source'
|
10
10
|
s.authors = ['Mantas Norvaiša']
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.required_ruby_version = '>= 2.0.0'
|
20
20
|
|
21
21
|
s.add_runtime_dependency('parser', '>= 2.4.0.0', '< 3.0')
|
22
|
+
s.add_runtime_dependency('unindent')
|
22
23
|
|
23
24
|
# Optional dependencies at runtime, required for development
|
24
25
|
s.add_development_dependency('slim', '~> 3.0')
|
@@ -28,7 +29,7 @@ Gem::Specification.new do |s|
|
|
28
29
|
|
29
30
|
# Testing
|
30
31
|
s.add_development_dependency('rspec', '~> 3.5')
|
31
|
-
s.add_development_dependency('
|
32
|
+
s.add_development_dependency('timecop')
|
32
33
|
|
33
34
|
# Linters and code policies
|
34
35
|
s.add_development_dependency('rubocop', '~> 0.46.0')
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
data/spec/unit/extractor_spec.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/spec/unit/po_entry_spec.rb
CHANGED
@@ -135,6 +135,29 @@ describe PutText::POEntry do
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
|
+
describe '#flags?' do
|
139
|
+
context 'entry has flags' do
|
140
|
+
let(:entry) do
|
141
|
+
described_class.new(
|
142
|
+
msgid: 'An error occurred!',
|
143
|
+
flags: ['fuzzy']
|
144
|
+
)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'returns true' do
|
148
|
+
expect(entry.flags?).to be true
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'entry does not have flags' do
|
153
|
+
let(:entry) { described_class.new(msgid: 'An error occurred!') }
|
154
|
+
|
155
|
+
it 'returns false' do
|
156
|
+
expect(entry.flags?).to be false
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
138
161
|
describe '#plural?' do
|
139
162
|
context 'entry is a pluralized entry' do
|
140
163
|
let(:entry) do
|
@@ -257,7 +280,6 @@ describe PutText::POEntry do
|
|
257
280
|
msgid "An error occurred!"
|
258
281
|
msgid_plural "%d errors occurred!"
|
259
282
|
msgstr[0] ""
|
260
|
-
msgstr[1] ""
|
261
283
|
PO
|
262
284
|
end
|
263
285
|
end
|
data/spec/unit/po_file_spec.rb
CHANGED
@@ -36,10 +36,25 @@ describe PutText::POFile do
|
|
36
36
|
)
|
37
37
|
end
|
38
38
|
|
39
|
+
before do
|
40
|
+
Timecop.freeze(Time.utc(2017))
|
41
|
+
end
|
42
|
+
|
43
|
+
after do
|
44
|
+
Timecop.return
|
45
|
+
end
|
46
|
+
|
39
47
|
let(:file) { described_class.new([entry_1, entry_2, entry_3]) }
|
40
48
|
|
41
49
|
it 'generates correct string' do
|
42
50
|
expect(file.to_s).to eq(<<-PO.unindent)
|
51
|
+
#, fuzzy
|
52
|
+
msgid ""
|
53
|
+
msgstr ""
|
54
|
+
"POT-Creation-Date: 2017-01-01 00:00+0000\\n"
|
55
|
+
"MIME-Version: 1.0\\n"
|
56
|
+
"Content-Type: text/plain; charset=UTF-8\\n"
|
57
|
+
|
43
58
|
#: error1.rb:1
|
44
59
|
msgid "Error #1 occurred"
|
45
60
|
msgstr ""
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puttext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mantas Norvaiša
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04
|
11
|
+
date: 2017-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: unindent
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: slim
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,7 +87,7 @@ dependencies:
|
|
73
87
|
- !ruby/object:Gem::Version
|
74
88
|
version: '3.5'
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
90
|
+
name: timecop
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
78
92
|
requirements:
|
79
93
|
- - ">="
|
@@ -192,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
206
|
version: '0'
|
193
207
|
requirements: []
|
194
208
|
rubyforge_project:
|
195
|
-
rubygems_version: 2.6.
|
209
|
+
rubygems_version: 2.6.8
|
196
210
|
signing_key:
|
197
211
|
specification_version: 4
|
198
212
|
summary: Extract gettext strings from Ruby source
|