gettext 3.0.3 → 3.0.4
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/bin/rmsgcat +22 -0
- data/doc/text/news.md +14 -0
- data/lib/gettext/class_info.rb +2 -1
- data/lib/gettext/po.rb +17 -10
- data/lib/gettext/po_entry.rb +112 -19
- data/lib/gettext/po_parser.rb +9 -5
- data/lib/gettext/tools/msgcat.rb +246 -0
- data/lib/gettext/tools/msginit.rb +4 -2
- data/lib/gettext/tools/msgmerge.rb +23 -14
- data/lib/gettext/tools/xgettext.rb +2 -2
- data/lib/gettext/version.rb +1 -1
- data/po/gettext.pot +113 -54
- data/src/po_parser.ry +9 -5
- data/test/test_class_info.rb +42 -1
- data/test/test_po.rb +18 -0
- data/test/test_po_entry.rb +163 -7
- data/test/tools/test_msgcat.rb +397 -0
- data/test/tools/test_msgmerge.rb +23 -3
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d86db1459c880200329b35e33e864f61379b19e
|
4
|
+
data.tar.gz: 1a5bf66f9c2635dbb6ed24381c561d8caf60f0d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eec3c5b571d10f2554973fdc5250bf6349a6f9580c264609cf551c721ed5ec4be3ad43bb5fe9616c23924492b90666ea2b12630c83bc38725ded0bd1c6fa3539
|
7
|
+
data.tar.gz: 23c26b971dc36dbd92b9e3015650cae86293788bd9a3d9a5534fe15e4f6026723634f66b5c4ca5a04bb11eea0e2ff76599b7e0f92f2832910b9a4e37e690b475
|
data/bin/rmsgcat
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
4
|
+
#
|
5
|
+
# License: Ruby's or LGPL
|
6
|
+
#
|
7
|
+
# This library is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This library is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Lesser General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require "gettext/tools/msgcat"
|
21
|
+
|
22
|
+
GetText::Tools::MsgCat.run(*ARGV)
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
+
## <a id="3-0-4">3.0.4</a>: 2014-02-02
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* Supported `Module#prepend`. [GitHub#29] [Reported by akira yamada]
|
8
|
+
* Added {GetText::POEntry#fuzzy?}.
|
9
|
+
* Added {GetText::Tools::MsgCat}.
|
10
|
+
* Added `rmsgcat` command. [GitHub#23] [Requested by Andreas Loupasakis]
|
11
|
+
|
12
|
+
### Thanks
|
13
|
+
|
14
|
+
* akira yamada
|
15
|
+
* Andreas Loupasakis
|
16
|
+
|
3
17
|
## <a id="3-0-3">3.0.3</a>: 2013-12-15
|
4
18
|
|
5
19
|
### Improvements
|
data/lib/gettext/class_info.rb
CHANGED
@@ -38,7 +38,8 @@ module GetText
|
|
38
38
|
end
|
39
39
|
analyzed_classes << klass unless analyzed_classes.include? klass
|
40
40
|
|
41
|
-
klass.ancestors
|
41
|
+
klass.ancestors.each do |a|
|
42
|
+
next if a == klass
|
42
43
|
ret += related_classes_internal(a, all_classes, analyzed_classes)
|
43
44
|
ret.uniq!
|
44
45
|
end
|
data/lib/gettext/po.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2012-
|
3
|
+
# Copyright (C) 2012-2014 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
|
5
5
|
#
|
6
6
|
# License: Ruby's or LGPL
|
@@ -38,13 +38,20 @@ module GetText
|
|
38
38
|
# @!attribute [rw] order
|
39
39
|
# The order is used to sort PO entries(objects of {POEntry}) in
|
40
40
|
# {#to_s}.
|
41
|
-
# @param [
|
42
|
-
#
|
41
|
+
# @param [:reference, :msgid] order (:reference) The sort key.
|
42
|
+
#
|
43
|
+
# Use `:reference` for sorting by location that message is placed.
|
44
|
+
#
|
45
|
+
# Use `:msgid` for sorting by msgid alphabetical order.
|
46
|
+
#
|
47
|
+
# `:references` is deprecated since 3.0.4. It will be removed
|
48
|
+
# at 4.0.0. Use `:reference` instead.
|
49
|
+
#
|
43
50
|
# @return [Symbol] the name as order by sort.
|
44
51
|
attr_accessor :order
|
45
52
|
|
46
53
|
def initialize(order=nil)
|
47
|
-
@order = order || :
|
54
|
+
@order = order || :reference
|
48
55
|
@entries = {}
|
49
56
|
end
|
50
57
|
|
@@ -214,8 +221,8 @@ module GetText
|
|
214
221
|
private
|
215
222
|
def sort(entries)
|
216
223
|
case @order
|
217
|
-
when :references
|
218
|
-
sorted_entries =
|
224
|
+
when :reference, :references # :references is deprecated.
|
225
|
+
sorted_entries = sort_by_reference(entries)
|
219
226
|
when :msgid
|
220
227
|
sorted_entries = sort_by_msgid(entries)
|
221
228
|
else
|
@@ -223,10 +230,10 @@ module GetText
|
|
223
230
|
end
|
224
231
|
end
|
225
232
|
|
226
|
-
def
|
233
|
+
def sort_by_reference(entries)
|
227
234
|
entries.each do |_, entry|
|
228
235
|
entry.references = entry.references.sort do |reference, other|
|
229
|
-
|
236
|
+
compare_reference(reference, other)
|
230
237
|
end
|
231
238
|
end
|
232
239
|
|
@@ -234,11 +241,11 @@ module GetText
|
|
234
241
|
# msgid_entry = [[msgctxt, msgid], POEntry]
|
235
242
|
entry_first_reference = msgid_entry[1].references.first
|
236
243
|
other_first_reference = other_msgid_entry[1].references.first
|
237
|
-
|
244
|
+
compare_reference(entry_first_reference, other_first_reference)
|
238
245
|
end
|
239
246
|
end
|
240
247
|
|
241
|
-
def
|
248
|
+
def compare_reference(reference, other)
|
242
249
|
entry_source, entry_line_number = split_reference(reference)
|
243
250
|
other_source, other_line_number = split_reference(other)
|
244
251
|
|
data/lib/gettext/po_entry.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
#
|
3
|
-
# Copyright (C) 2012-
|
3
|
+
# Copyright (C) 2012-2014 Kouhei Sutou <kou@clear-code.com>
|
4
4
|
# Copyright (C) 2010 masone (Christian Felder) <ema@rh-productions.ch>
|
5
5
|
# Copyright (C) 2009 Masao Mutoh
|
6
6
|
#
|
@@ -58,7 +58,9 @@ module GetText
|
|
58
58
|
attr_accessor :references # ["file1:line1", "file2:line2", ...]
|
59
59
|
attr_accessor :translator_comment
|
60
60
|
attr_accessor :extracted_comment
|
61
|
-
|
61
|
+
# @return [Array<String>] The flags for this PO entry.
|
62
|
+
# @since 3.0.4
|
63
|
+
attr_accessor :flags
|
62
64
|
attr_accessor :previous
|
63
65
|
attr_accessor :comment
|
64
66
|
|
@@ -68,7 +70,7 @@ module GetText
|
|
68
70
|
@translator_comment = nil
|
69
71
|
@extracted_comment = nil
|
70
72
|
@references = []
|
71
|
-
@
|
73
|
+
@flags = []
|
72
74
|
@previous = nil
|
73
75
|
@msgctxt = nil
|
74
76
|
@msgid = nil
|
@@ -87,6 +89,24 @@ module GetText
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
92
|
+
# @return [String, nil] The flag of the PO entry.
|
93
|
+
# @deprecated Since 3.0.4. Use {#flags} instead.
|
94
|
+
def flag
|
95
|
+
@flags.first
|
96
|
+
end
|
97
|
+
|
98
|
+
# Set the new flag for the PO entry.
|
99
|
+
#
|
100
|
+
# @param [String, nil] flag The new flag.
|
101
|
+
# @deprecated Since 3.0.4. Use {#flags=} instead.
|
102
|
+
def flag=(flag)
|
103
|
+
if flag.nil?
|
104
|
+
@flags = []
|
105
|
+
else
|
106
|
+
@flags = [flag]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
90
110
|
# Checks if the self has same attributes as other.
|
91
111
|
def ==(other)
|
92
112
|
not other.nil? and
|
@@ -99,7 +119,7 @@ module GetText
|
|
99
119
|
translator_comment == other.translator_comment and
|
100
120
|
extracted_comment == other.extracted_comment and
|
101
121
|
references == other.references and
|
102
|
-
|
122
|
+
flags == other.flags and
|
103
123
|
previous == other.previous and
|
104
124
|
comment == other.comment
|
105
125
|
end
|
@@ -177,6 +197,12 @@ module GetText
|
|
177
197
|
@type == :normal and @msgid == :last
|
178
198
|
end
|
179
199
|
|
200
|
+
# @return true if the entry is fuzzy entry, false otherwise.
|
201
|
+
# Fuzzy entry has "fuzzy" flag.
|
202
|
+
def fuzzy?
|
203
|
+
@flags.include?("fuzzy")
|
204
|
+
end
|
205
|
+
|
180
206
|
def [](number)
|
181
207
|
param = @param_type[number]
|
182
208
|
raise ParseError, 'no more string parameters expected' unless param
|
@@ -218,8 +244,22 @@ module GetText
|
|
218
244
|
|
219
245
|
# @param [POEntry] entry The entry to be formatted.
|
220
246
|
# @param [Hash] options
|
247
|
+
# @option options [Bool] :include_translator_comment (true)
|
248
|
+
# Includes translator comments in formatted string if true.
|
249
|
+
# @option options [Bool] :include_extracted_comment (true)
|
250
|
+
# Includes extracted comments in formatted string if true.
|
221
251
|
# @option options [Bool] :include_reference_comment (true)
|
222
252
|
# Includes reference comments in formatted string if true.
|
253
|
+
# @option options [Bool] :include_flag_comment (true)
|
254
|
+
# Includes flag comments in formatted string if true.
|
255
|
+
# @option options [Bool] :include_previous_comment (true)
|
256
|
+
# Includes previous comments in formatted string if true.
|
257
|
+
# @option options [Bool] :include_all_comments (true)
|
258
|
+
# Includes all comments in formatted string if true.
|
259
|
+
# Other specific `:include_XXX` options get preference over
|
260
|
+
# this option.
|
261
|
+
# You can remove all comments by specifying this option as
|
262
|
+
# false and omitting other `:include_XXX` options.
|
223
263
|
# @option options [Integer] :max_line_width (78)
|
224
264
|
# Wraps long lines that is longer than the `:max_line_width`.
|
225
265
|
# Don't break long lines if `:max_line_width` is less than 0
|
@@ -228,7 +268,7 @@ module GetText
|
|
228
268
|
# Encodes to the specific encoding.
|
229
269
|
def initialize(entry, options={})
|
230
270
|
@entry = entry
|
231
|
-
@options =
|
271
|
+
@options = normalize_options(options)
|
232
272
|
end
|
233
273
|
|
234
274
|
def format
|
@@ -236,14 +276,7 @@ module GetText
|
|
236
276
|
return format_obsolete_comment(@entry.comment)
|
237
277
|
end
|
238
278
|
|
239
|
-
str =
|
240
|
-
str << format_translator_comment
|
241
|
-
str << format_extracted_comment
|
242
|
-
if @options[:include_reference_comment]
|
243
|
-
str << format_reference_comment
|
244
|
-
end
|
245
|
-
str << format_flag_comment
|
246
|
-
str << format_previous_comment
|
279
|
+
str = format_comments
|
247
280
|
|
248
281
|
# msgctxt, msgid, msgstr
|
249
282
|
if @entry.msgctxt?
|
@@ -285,15 +318,66 @@ module GetText
|
|
285
318
|
end
|
286
319
|
|
287
320
|
private
|
288
|
-
def
|
321
|
+
def normalize_options(options)
|
289
322
|
options = options.dup
|
290
|
-
|
291
|
-
|
323
|
+
include_comment_keys = [
|
324
|
+
:include_translator_comment,
|
325
|
+
:include_extracted_comment,
|
326
|
+
:include_reference_comment,
|
327
|
+
:include_flag_comment,
|
328
|
+
:include_previous_comment,
|
329
|
+
]
|
330
|
+
if options[:include_all_comments].nil?
|
331
|
+
options[:include_all_comments] = true
|
332
|
+
end
|
333
|
+
default_include_comment_value = options[:include_all_comments]
|
334
|
+
include_comment_keys.each do |key|
|
335
|
+
options[key] = default_include_comment_value if options[key].nil?
|
292
336
|
end
|
293
337
|
options[:max_line_width] ||= DEFAULT_MAX_LINE_WIDTH
|
294
338
|
options
|
295
339
|
end
|
296
340
|
|
341
|
+
def include_translator_comment?
|
342
|
+
@options[:include_translator_comment]
|
343
|
+
end
|
344
|
+
|
345
|
+
def include_extracted_comment?
|
346
|
+
@options[:include_extracted_comment]
|
347
|
+
end
|
348
|
+
|
349
|
+
def include_reference_comment?
|
350
|
+
@options[:include_reference_comment]
|
351
|
+
end
|
352
|
+
|
353
|
+
def include_flag_comment?
|
354
|
+
@options[:include_flag_comment]
|
355
|
+
end
|
356
|
+
|
357
|
+
def include_previous_comment?
|
358
|
+
@options[:include_previous_comment]
|
359
|
+
end
|
360
|
+
|
361
|
+
def format_comments
|
362
|
+
formatted_comment = ""
|
363
|
+
if include_translator_comment?
|
364
|
+
formatted_comment << format_translator_comment
|
365
|
+
end
|
366
|
+
if include_extracted_comment?
|
367
|
+
formatted_comment << format_extracted_comment
|
368
|
+
end
|
369
|
+
if include_reference_comment?
|
370
|
+
formatted_comment << format_reference_comment
|
371
|
+
end
|
372
|
+
if include_flag_comment?
|
373
|
+
formatted_comment << format_flag_comment
|
374
|
+
end
|
375
|
+
if include_previous_comment?
|
376
|
+
formatted_comment << format_previous_comment
|
377
|
+
end
|
378
|
+
formatted_comment
|
379
|
+
end
|
380
|
+
|
297
381
|
def format_translator_comment
|
298
382
|
format_comment("#", @entry.translator_comment)
|
299
383
|
end
|
@@ -326,7 +410,11 @@ module GetText
|
|
326
410
|
end
|
327
411
|
|
328
412
|
def format_flag_comment
|
329
|
-
|
413
|
+
formatted_flags = ""
|
414
|
+
@entry.flags.each do |flag|
|
415
|
+
formatted_flags << format_comment(FLAG_MARK, flag)
|
416
|
+
end
|
417
|
+
formatted_flags
|
330
418
|
end
|
331
419
|
|
332
420
|
def format_previous_comment
|
@@ -365,11 +453,16 @@ module GetText
|
|
365
453
|
end
|
366
454
|
|
367
455
|
def format_message(message)
|
368
|
-
|
456
|
+
empty_formatted_message = "\"\"\n"
|
457
|
+
return empty_formatted_message if message.nil?
|
369
458
|
|
370
459
|
chunks = wrap_message(message)
|
460
|
+
return empty_formatted_message if chunks.empty?
|
461
|
+
|
371
462
|
formatted_message = ""
|
372
|
-
|
463
|
+
if chunks.size > 1 or chunks.first.end_with?("\n")
|
464
|
+
formatted_message << empty_formatted_message
|
465
|
+
end
|
373
466
|
chunks.each do |chunk|
|
374
467
|
formatted_message << "\"#{escape(chunk)}\"\n"
|
375
468
|
end
|
data/lib/gettext/po_parser.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
#
|
12
12
|
# DO NOT MODIFY!!!!
|
13
|
-
# This file is automatically generated by Racc 1.4.
|
13
|
+
# This file is automatically generated by Racc 1.4.11
|
14
14
|
# from Racc grammer file "".
|
15
15
|
#
|
16
16
|
|
@@ -64,7 +64,7 @@ module_eval(<<'...end po_parser.ry/module_eval...', 'po_parser.ry', 123)
|
|
64
64
|
@translator_comments = []
|
65
65
|
@extracted_comments = []
|
66
66
|
@references = []
|
67
|
-
@
|
67
|
+
@flags = []
|
68
68
|
@previous = []
|
69
69
|
@comments = []
|
70
70
|
@data = data
|
@@ -139,7 +139,7 @@ module_eval(<<'...end po_parser.ry/module_eval...', 'po_parser.ry', 123)
|
|
139
139
|
entry = POEntry.new(type)
|
140
140
|
entry.translator_comment = format_comment(@translator_comments)
|
141
141
|
entry.extracted_comment = format_comment(@extracted_comments)
|
142
|
-
entry.
|
142
|
+
entry.flags = @flags
|
143
143
|
entry.previous = format_comment(@previous)
|
144
144
|
entry.references = @references
|
145
145
|
entry.msgctxt = @msgctxt
|
@@ -159,7 +159,7 @@ module_eval(<<'...end po_parser.ry/module_eval...', 'po_parser.ry', 123)
|
|
159
159
|
@translator_comments = []
|
160
160
|
@extracted_comments = []
|
161
161
|
@references = []
|
162
|
-
@
|
162
|
+
@flags = []
|
163
163
|
@previous = []
|
164
164
|
@references = []
|
165
165
|
@comments.clear
|
@@ -191,7 +191,7 @@ module_eval(<<'...end po_parser.ry/module_eval...', 'po_parser.ry', 123)
|
|
191
191
|
when POFormat::REFERENCE_COMMENT_MARK
|
192
192
|
@references.concat(parse_references_line(content))
|
193
193
|
when POFormat::FLAG_MARK
|
194
|
-
@
|
194
|
+
@flags.concat(parse_flags_line(content))
|
195
195
|
when POFormat::PREVIOUS_COMMENT_MARK
|
196
196
|
@previous << content
|
197
197
|
else
|
@@ -258,6 +258,10 @@ module_eval(<<'...end po_parser.ry/module_eval...', 'po_parser.ry', 123)
|
|
258
258
|
def parse_references_line(line)
|
259
259
|
line.split(/\s+/)
|
260
260
|
end
|
261
|
+
|
262
|
+
def parse_flags_line(line)
|
263
|
+
line.split(/\s+/)
|
264
|
+
end
|
261
265
|
...end po_parser.ry/module_eval...
|
262
266
|
##### State transition tables begin ###
|
263
267
|
|
@@ -0,0 +1,246 @@
|
|
1
|
+
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# License: Ruby's or LGPL
|
4
|
+
#
|
5
|
+
# This library is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "optparse"
|
19
|
+
require "gettext"
|
20
|
+
require "gettext/po_parser"
|
21
|
+
require "gettext/po"
|
22
|
+
|
23
|
+
module GetText
|
24
|
+
module Tools
|
25
|
+
class MsgCat
|
26
|
+
class << self
|
27
|
+
# (see #run)
|
28
|
+
#
|
29
|
+
# This method is provided just for convenience. It equals to
|
30
|
+
# `new.run(*command_line)`.
|
31
|
+
def run(*command_line)
|
32
|
+
new.run(*command_line)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Concatenates po-files.
|
37
|
+
#
|
38
|
+
# @param [Array<String>] command_line
|
39
|
+
# The command line arguments for rmsgcat.
|
40
|
+
# @return [void]
|
41
|
+
def run(*command_line)
|
42
|
+
config = Config.new
|
43
|
+
config.parse(command_line)
|
44
|
+
|
45
|
+
parser = POParser.new
|
46
|
+
parser.report_warning = config.report_warning?
|
47
|
+
parser.ignore_fuzzy = !config.include_fuzzy?
|
48
|
+
output_po = PO.new
|
49
|
+
output_po.order = config.order
|
50
|
+
merger = Merger.new(output_po, config)
|
51
|
+
config.pos.each do |po_file_name|
|
52
|
+
po = PO.new
|
53
|
+
parser.parse_file(po_file_name, po)
|
54
|
+
merger.merge(po)
|
55
|
+
end
|
56
|
+
|
57
|
+
output_po_string = output_po.to_s(config.po_format_options)
|
58
|
+
if config.output.is_a?(String)
|
59
|
+
File.open(File.expand_path(config.output), "w") do |file|
|
60
|
+
file.print(output_po_string)
|
61
|
+
end
|
62
|
+
else
|
63
|
+
puts(output_po_string)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# @private
|
68
|
+
class Merger
|
69
|
+
def initialize(output_po, config)
|
70
|
+
@output_po = output_po
|
71
|
+
@config = config
|
72
|
+
end
|
73
|
+
|
74
|
+
def merge(po)
|
75
|
+
po.each do |entry|
|
76
|
+
id = [entry.msgctxt, entry.msgid]
|
77
|
+
if @output_po.has_key?(*id)
|
78
|
+
merged_entry = merge_entry(@output_po[*id], entry)
|
79
|
+
else
|
80
|
+
merged_entry = entry
|
81
|
+
end
|
82
|
+
@output_po[*id] = merged_entry if merged_entry
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def merge_entry(base_entry, new_entry)
|
88
|
+
if base_entry.header?
|
89
|
+
return merge_header(base_entry, new_entry)
|
90
|
+
end
|
91
|
+
|
92
|
+
if base_entry.fuzzy?
|
93
|
+
return merge_fuzzy_entry(base_entry, new_entry)
|
94
|
+
end
|
95
|
+
|
96
|
+
base_entry
|
97
|
+
end
|
98
|
+
|
99
|
+
def merge_header(base_entry, new_entry)
|
100
|
+
base_entry
|
101
|
+
end
|
102
|
+
|
103
|
+
def merge_fuzzy_entry(base_entry, new_entry)
|
104
|
+
if new_entry.fuzzy?
|
105
|
+
base_entry
|
106
|
+
else
|
107
|
+
new_entry
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# @private
|
113
|
+
class Config
|
114
|
+
include GetText
|
115
|
+
|
116
|
+
bindtextdomain("gettext")
|
117
|
+
|
118
|
+
# @return [Array<String>] The input PO file names.
|
119
|
+
attr_accessor :pos
|
120
|
+
|
121
|
+
# @return [String] The output file name.
|
122
|
+
attr_accessor :output
|
123
|
+
|
124
|
+
# @return [:reference, :msgid] The sort key.
|
125
|
+
attr_accessor :order
|
126
|
+
|
127
|
+
# @return [Hash] The PO format options.
|
128
|
+
# @see PO#to_s
|
129
|
+
# @see POEntry#to_s
|
130
|
+
attr_accessor :po_format_options
|
131
|
+
|
132
|
+
# (see include_fuzzy?)
|
133
|
+
attr_writer :include_fuzzy
|
134
|
+
|
135
|
+
# (see report_warning?)
|
136
|
+
attr_writer :report_warning
|
137
|
+
|
138
|
+
def initialize
|
139
|
+
@pos = []
|
140
|
+
@output = nil
|
141
|
+
@order = nil
|
142
|
+
@po_format_options = {
|
143
|
+
:max_line_width => POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
|
144
|
+
}
|
145
|
+
@include_fuzzy = true
|
146
|
+
@report_warning = true
|
147
|
+
end
|
148
|
+
|
149
|
+
# @return [Boolean] Whether includes fuzzy entries or not.
|
150
|
+
def include_fuzzy?
|
151
|
+
@include_fuzzy
|
152
|
+
end
|
153
|
+
|
154
|
+
# @return [Boolean] Whether reports warning messages or not.
|
155
|
+
def report_warning?
|
156
|
+
@report_warning
|
157
|
+
end
|
158
|
+
|
159
|
+
def parse(command_line)
|
160
|
+
parser = create_option_parser
|
161
|
+
@pos = parser.parse(command_line)
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
def create_option_parser
|
166
|
+
parser = OptionParser.new
|
167
|
+
parser.version = GetText::VERSION
|
168
|
+
parser.banner = _("Usage: %s [OPTIONS] PO_FILE1 PO_FILE2 ...") % $0
|
169
|
+
parser.separator("")
|
170
|
+
parser.separator(_("Concatenates and merges PO files."))
|
171
|
+
parser.separator("")
|
172
|
+
parser.separator(_("Specific options:"))
|
173
|
+
|
174
|
+
parser.on("-o", "--output=FILE",
|
175
|
+
_("Write output to specified file"),
|
176
|
+
_("(default: the standard output)")) do |output|
|
177
|
+
@output = output
|
178
|
+
end
|
179
|
+
|
180
|
+
parser.on("--sort-by-msgid",
|
181
|
+
_("Sort output by msgid")) do
|
182
|
+
@order = :msgid
|
183
|
+
end
|
184
|
+
|
185
|
+
parser.on("--sort-by-location",
|
186
|
+
_("Sort output by location")) do
|
187
|
+
@order = :reference
|
188
|
+
end
|
189
|
+
|
190
|
+
parser.on("--sort-by-file",
|
191
|
+
_("Sort output by location"),
|
192
|
+
_("It is same as --sort-by-location"),
|
193
|
+
_("Just for GNU gettext's msgcat compatibility")) do
|
194
|
+
@order = :reference
|
195
|
+
end
|
196
|
+
|
197
|
+
parser.on("--[no-]sort-output",
|
198
|
+
_("Sort output by msgid"),
|
199
|
+
_("It is same as --sort-by-msgid"),
|
200
|
+
_("Just for GNU gettext's msgcat compatibility")) do |sort|
|
201
|
+
@order = sort ? :msgid : nil
|
202
|
+
end
|
203
|
+
|
204
|
+
parser.on("--no-location",
|
205
|
+
_("Remove location information")) do |boolean|
|
206
|
+
@po_format_options[:include_reference_comment] = boolean
|
207
|
+
end
|
208
|
+
|
209
|
+
parser.on("--no-all-comments",
|
210
|
+
_("Remove all comments")) do |boolean|
|
211
|
+
@po_format_options[:include_all_comments] = boolean
|
212
|
+
end
|
213
|
+
|
214
|
+
parser.on("--width=WIDTH", Integer,
|
215
|
+
_("Set output page width"),
|
216
|
+
"(#{@po_format_options[:max_line_width]})") do |width|
|
217
|
+
@po_format_options[:max_line_width] = width
|
218
|
+
end
|
219
|
+
|
220
|
+
parser.on("--[no-]wrap",
|
221
|
+
_("Break long message lines, longer than the output page width, into several lines"),
|
222
|
+
"(#{@po_format_options[:max_line_width] >= 0})") do |wrap|
|
223
|
+
if wrap
|
224
|
+
max_line_width = POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH
|
225
|
+
else
|
226
|
+
max_line_width = -1
|
227
|
+
end
|
228
|
+
@po_format_options[:max_line_width] = max_line_width
|
229
|
+
end
|
230
|
+
|
231
|
+
parser.on("--no-fuzzy",
|
232
|
+
_("Ignore fuzzy entries")) do |include_fuzzy|
|
233
|
+
@include_fuzzy = include_fuzzy
|
234
|
+
end
|
235
|
+
|
236
|
+
parser.on("--no-report-warning",
|
237
|
+
_("Don't report warning messages")) do |report_warning|
|
238
|
+
@report_warning = report_warning
|
239
|
+
end
|
240
|
+
|
241
|
+
parser
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|