Skip to content

Commit

Permalink
Add --use-one-line-per-reference option
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 21, 2023
1 parent ecb7b6d commit bfa8eb1
Show file tree
Hide file tree
Showing 33 changed files with 208 additions and 35 deletions.
38 changes: 23 additions & 15 deletions lib/gettext/po_entry.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2012-2019 Sutou Kouhei <[email protected]>
# Copyright (C) 2012-2023 Sutou Kouhei <[email protected]>
# Copyright (C) 2010 masone (Christian Felder) <[email protected]>
# Copyright (C) 2009 Masao Mutoh
#
Expand Down Expand Up @@ -282,6 +282,9 @@ def escape(string)
# Wraps long lines that is longer than the `:max_line_width`.
# Don't break long lines if `:max_line_width` is less than 0
# such as `-1`.
# @option options [Bool] :use_one_line_per_reference (false)
# Whether each reference comment uses one line or not. If this
# is `true`, `:max_line_width` is ignored for reference comment.
# @option options [Encoding] :encoding (nil)
# Encodes to the specific encoding.
def initialize(entry, options={})
Expand Down Expand Up @@ -405,24 +408,29 @@ def format_extracted_comment
end

def format_reference_comment
max_line_width = @options[:max_line_width]
formatted_reference = String.new
if not @entry.references.nil? and not @entry.references.empty?
formatted_reference << REFERENCE_COMMENT_MARK
line_width = 2
@entry.references.each do |reference|
if max_line_width > 0 and
if @options[:use_one_line_per_reference]
@entry.references&.each do |reference|
formatted_reference << "#{REFERENCE_COMMENT_MARK} #{reference}\n"
end
else
max_line_width = @options[:max_line_width]
if not @entry.references.nil? and not @entry.references.empty?
formatted_reference << REFERENCE_COMMENT_MARK
line_width = 2
@entry.references.each do |reference|
if max_line_width > 0 and
line_width + reference.size > max_line_width
formatted_reference << "\n"
formatted_reference << "#{REFERENCE_COMMENT_MARK} #{reference}"
line_width = 3 + reference.size
else
formatted_reference << " #{reference}"
line_width += 1 + reference.size
formatted_reference << "\n"
formatted_reference << "#{REFERENCE_COMMENT_MARK} #{reference}"
line_width = 3 + reference.size
else
formatted_reference << " #{reference}"
line_width += 1 + reference.size
end
end
formatted_reference << "\n"
end

formatted_reference << "\n"
end
formatted_reference
end
Expand Down
11 changes: 9 additions & 2 deletions lib/gettext/tools/msgcat.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2014-2017 Kouhei Sutou <[email protected]>
# Copyright (C) 2014-2023 Sutou Kouhei <[email protected]>
#
# License: Ruby's or LGPL
#
Expand Down Expand Up @@ -200,7 +200,8 @@ def initialize
@output = nil
@order = nil
@po_format_options = {
:max_line_width => POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
max_line_width: POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
use_one_line_per_reference: false,
}
@include_fuzzy = true
@report_warning = true
Expand Down Expand Up @@ -322,6 +323,12 @@ def create_option_parser
@po_format_options[:max_line_width] = max_line_width
end

parser.on("--[no-]use-one-line-per-reference",
_("Use one line for each reference comment"),
"(#{@po_format_options[:use_one_line_per_reference]})") do |use|
@po_format_options[:use_one_line_per_reference] = use
end

parser.on("--no-fuzzy",
_("Ignore fuzzy entries")) do |include_fuzzy|
@include_fuzzy = include_fuzzy
Expand Down
17 changes: 11 additions & 6 deletions lib/gettext/tools/msgmerge.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012-2013 Haruka Yoshihara <[email protected]>
# Copyright (C) 2012-2015 Kouhei Sutou <[email protected]>
# Copyright (C) 2005-2009 Masao Mutoh
# Copyright (C) 2005,2006 speakillof
# Copyright (C) 2012-2023 Sutou Kouhei <[email protected]>
# Copyright (C) 2005-2009 Masao Mutoh
# Copyright (C) 2005,2006 speakillof
#
# License: Ruby's or LGPL
#
Expand Down Expand Up @@ -310,7 +308,8 @@ def initialize
@output = nil
@order = :reference
@po_format_options = {
:max_line_width => POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
max_line_width: POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
use_one_line_per_reference: false,
}
@enable_fuzzy_matching = true
@update = nil
Expand Down Expand Up @@ -424,6 +423,12 @@ def create_option_parser
@po_format_options[:max_line_width] = max_line_width
end

parser.on("--[no-]use-one-line-per-reference",
_("Use one line for each reference comment"),
"(#{@po_format_options[:use_one_line_per_reference]})") do |use|
@po_format_options[:use_one_line_per_reference] = use
end

parser.on("--[no-]fuzzy-matching",
_("Disable fuzzy matching"),
_("(enable)")) do |boolean|
Expand Down
13 changes: 9 additions & 4 deletions lib/gettext/tools/xgettext.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Haruka Yoshihara <[email protected]>
# Copyright (C) 2012-2014 Kouhei Sutou <[email protected]>
# Copyright (C) 2012-2023 Sutou Kouhei <[email protected]>
# Copyright (C) 2003-2010 Masao Mutoh
# Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
#
Expand Down Expand Up @@ -90,7 +88,8 @@ def initialize #:nodoc:

@po_order = :references
@po_format_options = {
:max_line_width => POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
max_line_width: POEntry::Formatter::DEFAULT_MAX_LINE_WIDTH,
use_one_line_per_reference: false,
}
end

Expand Down Expand Up @@ -325,6 +324,12 @@ def parse_arguments(*options) #:nodoc:
@po_format_options[:max_line_width] = max_line_width
end

parser.on("--[no-]use-one-line-per-reference",
_("Use one line for each reference comment"),
"(#{@po_format_options[:use_one_line_per_reference]})") do |use|
@po_format_options[:use_one_line_per_reference] = use
end

parser.on("-r", "--require=library",
_("require the library before executing xgettext")) do |out|
require out
Expand Down
3 changes: 3 additions & 0 deletions po/bg/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/bs/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/ca/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/cs/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/de/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/el/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/eo/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/es/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/et/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/fr/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/hr/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/hu/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/it/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
5 changes: 4 additions & 1 deletion po/ja/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: gettext 2.3.1\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2022-05-20 19:57+0900\n"
"PO-Revision-Date: 2023-10-22 06:40+0900\n"
"Last-Translator: Haruka Yoshihara <[email protected]>\n"
"Language-Team: Japanese\n"
"Language: ja\n"
Expand Down Expand Up @@ -78,6 +78,9 @@ msgid ""
"s"
msgstr "メッセージ中の出力ページ幅より長い行を複数行に分割"

msgid "Use one line for each reference comment"
msgstr "1行に1つのリファレンスコメントだけを入れる\n"

msgid "Ignore fuzzy entries"
msgstr "fuzzyエントリーを無視"

Expand Down
3 changes: 3 additions & 0 deletions po/ko/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/lv/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/nb/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/nl/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/pt_BR/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/ru/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/sr/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/sv/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
3 changes: 3 additions & 0 deletions po/uk/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ msgid ""
"s"
msgstr ""

msgid "Use one line for each reference comment"
msgstr ""

msgid "Ignore fuzzy entries"
msgstr ""

Expand Down
Loading

0 comments on commit bfa8eb1

Please sign in to comment.