Skip to content

Commit bfa8eb1

Browse files
committed
Add --use-one-line-per-reference option
1 parent ecb7b6d commit bfa8eb1

33 files changed

+208
-35
lines changed

lib/gettext/po_entry.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2012-2019 Sutou Kouhei <[email protected]>
1+
# Copyright (C) 2012-2023 Sutou Kouhei <[email protected]>
22
# Copyright (C) 2010 masone (Christian Felder) <[email protected]>
33
# Copyright (C) 2009 Masao Mutoh
44
#
@@ -282,6 +282,9 @@ def escape(string)
282282
# Wraps long lines that is longer than the `:max_line_width`.
283283
# Don't break long lines if `:max_line_width` is less than 0
284284
# such as `-1`.
285+
# @option options [Bool] :use_one_line_per_reference (false)
286+
# Whether each reference comment uses one line or not. If this
287+
# is `true`, `:max_line_width` is ignored for reference comment.
285288
# @option options [Encoding] :encoding (nil)
286289
# Encodes to the specific encoding.
287290
def initialize(entry, options={})
@@ -405,24 +408,29 @@ def format_extracted_comment
405408
end
406409

407410
def format_reference_comment
408-
max_line_width = @options[:max_line_width]
409411
formatted_reference = String.new
410-
if not @entry.references.nil? and not @entry.references.empty?
411-
formatted_reference << REFERENCE_COMMENT_MARK
412-
line_width = 2
413-
@entry.references.each do |reference|
414-
if max_line_width > 0 and
412+
if @options[:use_one_line_per_reference]
413+
@entry.references&.each do |reference|
414+
formatted_reference << "#{REFERENCE_COMMENT_MARK} #{reference}\n"
415+
end
416+
else
417+
max_line_width = @options[:max_line_width]
418+
if not @entry.references.nil? and not @entry.references.empty?
419+
formatted_reference << REFERENCE_COMMENT_MARK
420+
line_width = 2
421+
@entry.references.each do |reference|
422+
if max_line_width > 0 and
415423
line_width + reference.size > max_line_width
416-
formatted_reference << "\n"
417-
formatted_reference << "#{REFERENCE_COMMENT_MARK} #{reference}"
418-
line_width = 3 + reference.size
419-
else
420-
formatted_reference << " #{reference}"
421-
line_width += 1 + reference.size
424+
formatted_reference << "\n"
425+
formatted_reference << "#{REFERENCE_COMMENT_MARK} #{reference}"
426+
line_width = 3 + reference.size
427+
else
428+
formatted_reference << " #{reference}"
429+
line_width += 1 + reference.size
430+
end
422431
end
432+
formatted_reference << "\n"
423433
end
424-
425-
formatted_reference << "\n"
426434
end
427435
formatted_reference
428436
end

lib/gettext/tools/msgcat.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2014-2017 Kouhei Sutou <[email protected]>
1+
# Copyright (C) 2014-2023 Sutou Kouhei <[email protected]>
22
#
33
# License: Ruby's or LGPL
44
#
@@ -200,7 +200,8 @@ def initialize
200200
@output = nil
201201
@order = nil
202202
@po_format_options = {
203-
:max_line_width => POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
203+
max_line_width: POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
204+
use_one_line_per_reference: false,
204205
}
205206
@include_fuzzy = true
206207
@report_warning = true
@@ -322,6 +323,12 @@ def create_option_parser
322323
@po_format_options[:max_line_width] = max_line_width
323324
end
324325

326+
parser.on("--[no-]use-one-line-per-reference",
327+
_("Use one line for each reference comment"),
328+
"(#{@po_format_options[:use_one_line_per_reference]})") do |use|
329+
@po_format_options[:use_one_line_per_reference] = use
330+
end
331+
325332
parser.on("--no-fuzzy",
326333
_("Ignore fuzzy entries")) do |include_fuzzy|
327334
@include_fuzzy = include_fuzzy

lib/gettext/tools/msgmerge.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Copyright (C) 2012-2013 Haruka Yoshihara <[email protected]>
4-
# Copyright (C) 2012-2015 Kouhei Sutou <[email protected]>
5-
# Copyright (C) 2005-2009 Masao Mutoh
6-
# Copyright (C) 2005,2006 speakillof
2+
# Copyright (C) 2012-2023 Sutou Kouhei <[email protected]>
3+
# Copyright (C) 2005-2009 Masao Mutoh
4+
# Copyright (C) 2005,2006 speakillof
75
#
86
# License: Ruby's or LGPL
97
#
@@ -310,7 +308,8 @@ def initialize
310308
@output = nil
311309
@order = :reference
312310
@po_format_options = {
313-
:max_line_width => POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
311+
max_line_width: POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
312+
use_one_line_per_reference: false,
314313
}
315314
@enable_fuzzy_matching = true
316315
@update = nil
@@ -424,6 +423,12 @@ def create_option_parser
424423
@po_format_options[:max_line_width] = max_line_width
425424
end
426425

426+
parser.on("--[no-]use-one-line-per-reference",
427+
_("Use one line for each reference comment"),
428+
"(#{@po_format_options[:use_one_line_per_reference]})") do |use|
429+
@po_format_options[:use_one_line_per_reference] = use
430+
end
431+
427432
parser.on("--[no-]fuzzy-matching",
428433
_("Disable fuzzy matching"),
429434
_("(enable)")) do |boolean|

lib/gettext/tools/xgettext.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Copyright (C) 2012 Haruka Yoshihara <[email protected]>
4-
# Copyright (C) 2012-2014 Kouhei Sutou <[email protected]>
2+
# Copyright (C) 2012-2023 Sutou Kouhei <[email protected]>
53
# Copyright (C) 2003-2010 Masao Mutoh
64
# Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
75
#
@@ -90,7 +88,8 @@ def initialize #:nodoc:
9088

9189
@po_order = :references
9290
@po_format_options = {
93-
:max_line_width => POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
91+
max_line_width: POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
92+
use_one_line_per_reference: false,
9493
}
9594
end
9695

@@ -325,6 +324,12 @@ def parse_arguments(*options) #:nodoc:
325324
@po_format_options[:max_line_width] = max_line_width
326325
end
327326

327+
parser.on("--[no-]use-one-line-per-reference",
328+
_("Use one line for each reference comment"),
329+
"(#{@po_format_options[:use_one_line_per_reference]})") do |use|
330+
@po_format_options[:use_one_line_per_reference] = use
331+
end
332+
328333
parser.on("-r", "--require=library",
329334
_("require the library before executing xgettext")) do |out|
330335
require out

po/bg/gettext.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ msgid ""
8181
"s"
8282
msgstr ""
8383

84+
msgid "Use one line for each reference comment"
85+
msgstr ""
86+
8487
msgid "Ignore fuzzy entries"
8588
msgstr ""
8689

po/bs/gettext.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ msgid ""
8383
"s"
8484
msgstr ""
8585

86+
msgid "Use one line for each reference comment"
87+
msgstr ""
88+
8689
msgid "Ignore fuzzy entries"
8790
msgstr ""
8891

po/ca/gettext.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ msgid ""
8181
"s"
8282
msgstr ""
8383

84+
msgid "Use one line for each reference comment"
85+
msgstr ""
86+
8487
msgid "Ignore fuzzy entries"
8588
msgstr ""
8689

po/cs/gettext.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ msgid ""
8585
"s"
8686
msgstr ""
8787

88+
msgid "Use one line for each reference comment"
89+
msgstr ""
90+
8891
msgid "Ignore fuzzy entries"
8992
msgstr ""
9093

po/de/gettext.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ msgid ""
8787
"s"
8888
msgstr ""
8989

90+
msgid "Use one line for each reference comment"
91+
msgstr ""
92+
9093
msgid "Ignore fuzzy entries"
9194
msgstr ""
9295

po/el/gettext.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ msgid ""
8383
"s"
8484
msgstr ""
8585

86+
msgid "Use one line for each reference comment"
87+
msgstr ""
88+
8689
msgid "Ignore fuzzy entries"
8790
msgstr ""
8891

0 commit comments

Comments
 (0)