PoParser 2.0.1 → 3.0.0
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/Gemfile +5 -2
- data/README.md +23 -1
- data/Rakefile +65 -1
- data/lib/poparser/comment.rb +33 -6
- data/lib/poparser/constants.rb +4 -2
- data/lib/poparser/entry.rb +10 -10
- data/lib/poparser/header.rb +20 -0
- data/lib/poparser/po.rb +10 -10
- data/lib/poparser/tokenizer.rb +5 -17
- data/lib/poparser/version.rb +1 -1
- data/lib/poparser.rb +9 -11
- data/poparser.gemspec +1 -1
- data/spec/poparser/comment_spec.rb +4 -2
- data/spec/poparser/entry_spec.rb +23 -6
- data/spec/poparser/po_spec.rb +6 -6
- data/spec/poparser/poparser_spec.rb +126 -0
- data/spec/spec_helper.rb +12 -3
- data/spec/utils/random_pofile_generator.rb +175 -0
- data/test/benchmark.po +683 -0
- data/test/benchmark_small.po +46 -0
- data/test/complex_entry.po +21 -0
- data/test/escape_string.txt +7 -0
- metadata +12 -12
- data/lib/poparser/parser.rb +0 -67
- data/lib/poparser/transformer.rb +0 -59
- data/spec/poparser/parser_spec.rb +0 -72
- data/spec/poparser/transformer_spec.rb +0 -24
data/spec/spec_helper.rb
CHANGED
@@ -5,13 +5,22 @@
|
|
5
5
|
#
|
6
6
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
7
|
|
8
|
-
require '
|
9
|
-
require 'parslet/rig/rspec'
|
8
|
+
require 'simplecov'
|
10
9
|
require 'coveralls'
|
11
10
|
require 'awesome_print'
|
12
11
|
require 'pry'
|
13
12
|
|
14
|
-
|
13
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
14
|
+
[SimpleCov::Formatter::HTMLFormatter,
|
15
|
+
Coveralls::SimpleCov::Formatter]
|
16
|
+
)
|
17
|
+
|
18
|
+
SimpleCov.start do
|
19
|
+
add_group "gem", "lib"
|
20
|
+
add_group "spec", "spec"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'poparser'
|
15
24
|
|
16
25
|
RSpec.configure do |config|
|
17
26
|
config.raise_errors_for_deprecations!
|
@@ -0,0 +1,175 @@
|
|
1
|
+
module PoParser
|
2
|
+
module RandomPoFileGenerator
|
3
|
+
require 'securerandom'
|
4
|
+
def self.generate_file(file_path, length = 1000, obsoletes = 10)
|
5
|
+
header = "# PO benchmark file header
|
6
|
+
#
|
7
|
+
#, fuzzy
|
8
|
+
msgid \"\"
|
9
|
+
msgstr \"\"
|
10
|
+
\"Project-Id-Version: somehwat master\\n\"
|
11
|
+
\"Report-Msgid-Bugs-To: \\n\"
|
12
|
+
\"Last-Translator: last t <last.transh@e.mail>\\n\"
|
13
|
+
\"Language-Team: team\\n\"
|
14
|
+
\"Content-Type: text/plain; charset=UTF-8\\n\"
|
15
|
+
\"MIME-Version: 1.0\\n\"
|
16
|
+
\"Content-Transfer-Encoding: 8bit\\n\"
|
17
|
+
\"Plural-Forms: nplurals=1; plural=0;\\n\""
|
18
|
+
|
19
|
+
@random = Random.new
|
20
|
+
File.open(file_path, 'w+') do |file|
|
21
|
+
file.write header
|
22
|
+
file.write "\n\n"
|
23
|
+
for i in 0..length-obsoletes do
|
24
|
+
file.write generate_random_message
|
25
|
+
end
|
26
|
+
|
27
|
+
for i in 0...obsoletes do
|
28
|
+
file.write generate_random_message(true)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def self.generate_random_message(obsolete = false)
|
37
|
+
random_message = ""
|
38
|
+
|
39
|
+
untranslated_chance = 0.05
|
40
|
+
fuzzy_chance = 0.1
|
41
|
+
plural_chance = 0.1
|
42
|
+
multiline_chance = 0.1
|
43
|
+
translator_comment_chance = 0.2
|
44
|
+
extracted_comment_chance = 0.05
|
45
|
+
msgctxt_chance = 0.9
|
46
|
+
reference_chance = 0.9
|
47
|
+
multiple_reference_chance = 0.1
|
48
|
+
|
49
|
+
plural = @random.rand < plural_chance ? true : false
|
50
|
+
untranslated = @random.rand < untranslated_chance ? true : false
|
51
|
+
fuzzy = !untranslated && @random.rand < fuzzy_chance ? true : false
|
52
|
+
multiline = @random.rand < multiline_chance ? true : false
|
53
|
+
translator_comment = @random.rand < translator_comment_chance ? true : false
|
54
|
+
extracted_comment = @random.rand < extracted_comment_chance ? true : false
|
55
|
+
reference = @random.rand < reference_chance ? true : false
|
56
|
+
multiple_reference = @random.rand < multiple_reference_chance ? true : false
|
57
|
+
with_msgctxt = @random.rand < msgctxt_chance ? true : false
|
58
|
+
|
59
|
+
msgctxt = with_msgctxt ? SecureRandom.base64((@random.rand*70.0).ceil) : nil
|
60
|
+
if multiline
|
61
|
+
lines = (@random.rand*4.0).ceil
|
62
|
+
msgid = []
|
63
|
+
msgstr = []
|
64
|
+
for i in 0..lines
|
65
|
+
msgid[i] = SecureRandom.base64((@random.rand*70.0).ceil)
|
66
|
+
msgstr[i] = SecureRandom.base64((@random.rand*70.0).ceil)
|
67
|
+
end
|
68
|
+
else
|
69
|
+
msgid = SecureRandom.base64((@random.rand*150.0).ceil)
|
70
|
+
msgstr = SecureRandom.base64((@random.rand*150.0).ceil)
|
71
|
+
end
|
72
|
+
if plural
|
73
|
+
if multiline
|
74
|
+
msgid_plural = []
|
75
|
+
msgstr_plural = []
|
76
|
+
for i in 0..lines
|
77
|
+
msgid_plural[i] = SecureRandom.base64((@random.rand*70.0).ceil)
|
78
|
+
msgstr_plural[i] = SecureRandom.base64((@random.rand*70.0).ceil)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
msgid_plural = SecureRandom.base64((@random.rand*150.0).ceil)
|
82
|
+
msgstr_plural = SecureRandom.base64((@random.rand*70.0).ceil)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
random_message += "# #{SecureRandom.base64((@random.rand*50.0).to_i)}\n" if translator_comment
|
87
|
+
random_message += "#. #{SecureRandom.base64((@random.rand*50.0).to_i)}\n" if extracted_comment
|
88
|
+
random_message += "#: #{SecureRandom.base64((@random.rand*50.0).to_i)}\n" if reference
|
89
|
+
if multiple_reference
|
90
|
+
references = (@random.rand*3.0).ceil
|
91
|
+
for i in 0..references
|
92
|
+
random_message += "#: #{SecureRandom.base64((@random.rand*50.0).to_i)}\n"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
if fuzzy
|
96
|
+
random_message += "#, fuzzy\n"
|
97
|
+
random_message += "##{"~" if obsolete}| msgctxt \"#{msgctxt}\"\n" if msgctxt
|
98
|
+
if msgid.is_a?(Array)
|
99
|
+
random_message += "##{"~" if obsolete}| msgid \"\"\n"
|
100
|
+
msgid.each do |line|
|
101
|
+
random_message += "##{"~" if obsolete}| \"#{line}\\n\"\n"
|
102
|
+
end
|
103
|
+
else
|
104
|
+
random_message += "##{"~" if obsolete}| msgid \"#{msgid}\"\n"
|
105
|
+
end
|
106
|
+
if plural
|
107
|
+
if msgid_plural.is_a?(Array)
|
108
|
+
random_message += "##{"~" if obsolete}| msgid_plural \"\"\n"
|
109
|
+
msgid_plural.each do |line|
|
110
|
+
random_message += "##{"~" if obsolete}| \"#{line}\\n\"\n"
|
111
|
+
end
|
112
|
+
else
|
113
|
+
random_message += "##{"~" if obsolete}| msgid_plural \"#{msgid_plural}\"\n"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
random_message += "#{"#~ " if obsolete}msgctxt \"#{msgctxt}\"\n" if msgctxt
|
118
|
+
if msgid.is_a?(Array)
|
119
|
+
random_message += "#{"#~ " if obsolete}msgid \"\"\n"
|
120
|
+
msgid.each do |line|
|
121
|
+
random_message += "#{"#~ " if obsolete}\"#{line}\\n\"\n"
|
122
|
+
end
|
123
|
+
else
|
124
|
+
random_message += "#{"#~ " if obsolete}msgid \"#{msgid}\"\n"
|
125
|
+
end
|
126
|
+
if plural
|
127
|
+
if msgid_plural.is_a?(Array)
|
128
|
+
random_message += "#{"#~ " if obsolete}msgid_plural \"\"\n"
|
129
|
+
msgid_plural.each do |line|
|
130
|
+
random_message += "#{"#~ " if obsolete}\"#{line}\\n\"\n"
|
131
|
+
end
|
132
|
+
else
|
133
|
+
random_message += "#{"#~ " if obsolete}msgid_plural \"#{msgid_plural}\"\n"
|
134
|
+
end
|
135
|
+
if untranslated
|
136
|
+
random_message += "#{"#~ " if obsolete}msgstr[0] \"\"\n"
|
137
|
+
random_message += "#{"#~ " if obsolete}msgstr[1] \"\"\n"
|
138
|
+
else
|
139
|
+
if msgstr.is_a?(Array)
|
140
|
+
random_message += "#{"#~ " if obsolete}msgstr[0] \"\"\n"
|
141
|
+
msgstr.each do |line|
|
142
|
+
random_message += "#{"#~ " if obsolete}\"#{line}\\n\"\n"
|
143
|
+
end
|
144
|
+
else
|
145
|
+
random_message += "#{"#~ " if obsolete}msgstr[0] \"#{msgstr}\"\n"
|
146
|
+
end
|
147
|
+
if msgstr_plural.is_a?(Array)
|
148
|
+
random_message += "#{"#~ " if obsolete}msgstr[1] \"\"\n"
|
149
|
+
msgstr_plural.each do |line|
|
150
|
+
random_message += "#{"#~ " if obsolete}\"#{line}\\n\"\n"
|
151
|
+
end
|
152
|
+
else
|
153
|
+
random_message += "#{"#~ " if obsolete}msgstr[1] \"#{msgstr}\"\n"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
else
|
157
|
+
if untranslated
|
158
|
+
random_message += "#{"#~ " if obsolete}msgstr \"\"\n"
|
159
|
+
else
|
160
|
+
if msgstr.is_a?(Array)
|
161
|
+
random_message += "#{"#~ " if obsolete}msgstr \"\"\n"
|
162
|
+
msgstr.each do |line|
|
163
|
+
random_message += "#{"#~ " if obsolete}\"#{line}\\n\"\n"
|
164
|
+
end
|
165
|
+
else
|
166
|
+
random_message += "#{"#~ " if obsolete}msgstr \"#{msgstr}\"\n"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
random_message += "\n"
|
171
|
+
random_message
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
end
|