diff --git a/lib/gettext/po_entry.rb b/lib/gettext/po_entry.rb index fe9a4719..795196fc 100644 --- a/lib/gettext/po_entry.rb +++ b/lib/gettext/po_entry.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2019 Sutou Kouhei +# Copyright (C) 2012-2023 Sutou Kouhei # Copyright (C) 2010 masone (Christian Felder) # Copyright (C) 2009 Masao Mutoh # @@ -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={}) @@ -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 diff --git a/lib/gettext/tools/msgcat.rb b/lib/gettext/tools/msgcat.rb index c8f361e2..d58bb31a 100644 --- a/lib/gettext/tools/msgcat.rb +++ b/lib/gettext/tools/msgcat.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2017 Kouhei Sutou +# Copyright (C) 2014-2023 Sutou Kouhei # # License: Ruby's or LGPL # @@ -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 @@ -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 diff --git a/lib/gettext/tools/msgmerge.rb b/lib/gettext/tools/msgmerge.rb index beba28a3..b95732ca 100644 --- a/lib/gettext/tools/msgmerge.rb +++ b/lib/gettext/tools/msgmerge.rb @@ -1,9 +1,7 @@ -# -*- coding: utf-8 -*- -# # Copyright (C) 2012-2013 Haruka Yoshihara -# Copyright (C) 2012-2015 Kouhei Sutou -# Copyright (C) 2005-2009 Masao Mutoh -# Copyright (C) 2005,2006 speakillof +# Copyright (C) 2012-2023 Sutou Kouhei +# Copyright (C) 2005-2009 Masao Mutoh +# Copyright (C) 2005,2006 speakillof # # License: Ruby's or LGPL # @@ -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 @@ -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| diff --git a/lib/gettext/tools/xgettext.rb b/lib/gettext/tools/xgettext.rb index 34acb1e6..06a6c467 100644 --- a/lib/gettext/tools/xgettext.rb +++ b/lib/gettext/tools/xgettext.rb @@ -1,7 +1,5 @@ -# -*- coding: utf-8 -*- -# # Copyright (C) 2012 Haruka Yoshihara -# Copyright (C) 2012-2014 Kouhei Sutou +# Copyright (C) 2012-2023 Sutou Kouhei # Copyright (C) 2003-2010 Masao Mutoh # Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh # @@ -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 @@ -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 diff --git a/po/bg/gettext.po b/po/bg/gettext.po index b42bbf7e..d6140f29 100644 --- a/po/bg/gettext.po +++ b/po/bg/gettext.po @@ -81,6 +81,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/bs/gettext.po b/po/bs/gettext.po index 9fb403b5..851f4715 100644 --- a/po/bs/gettext.po +++ b/po/bs/gettext.po @@ -83,6 +83,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/ca/gettext.po b/po/ca/gettext.po index 0159a90f..952c0f21 100644 --- a/po/ca/gettext.po +++ b/po/ca/gettext.po @@ -81,6 +81,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/cs/gettext.po b/po/cs/gettext.po index 11b279f2..eb27868d 100644 --- a/po/cs/gettext.po +++ b/po/cs/gettext.po @@ -85,6 +85,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/de/gettext.po b/po/de/gettext.po index 0d3bc740..c6988d43 100644 --- a/po/de/gettext.po +++ b/po/de/gettext.po @@ -87,6 +87,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/el/gettext.po b/po/el/gettext.po index dae1dd00..b746a78f 100644 --- a/po/el/gettext.po +++ b/po/el/gettext.po @@ -83,6 +83,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/eo/gettext.po b/po/eo/gettext.po index d967b656..6b357386 100644 --- a/po/eo/gettext.po +++ b/po/eo/gettext.po @@ -85,6 +85,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/es/gettext.po b/po/es/gettext.po index b30ea3a4..22f7500c 100644 --- a/po/es/gettext.po +++ b/po/es/gettext.po @@ -84,6 +84,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/et/gettext.po b/po/et/gettext.po index ced017c7..399a8988 100644 --- a/po/et/gettext.po +++ b/po/et/gettext.po @@ -84,6 +84,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/fr/gettext.po b/po/fr/gettext.po index d37e29d6..fa9c5e0d 100644 --- a/po/fr/gettext.po +++ b/po/fr/gettext.po @@ -85,6 +85,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/hr/gettext.po b/po/hr/gettext.po index 5a18f4c7..45e13c07 100644 --- a/po/hr/gettext.po +++ b/po/hr/gettext.po @@ -84,6 +84,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/hu/gettext.po b/po/hu/gettext.po index d7f1231a..17b9216c 100644 --- a/po/hu/gettext.po +++ b/po/hu/gettext.po @@ -84,6 +84,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/it/gettext.po b/po/it/gettext.po index 0925dda7..05801cd6 100644 --- a/po/it/gettext.po +++ b/po/it/gettext.po @@ -83,6 +83,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/ja/gettext.po b/po/ja/gettext.po index a31e9092..c24281e6 100644 --- a/po/ja/gettext.po +++ b/po/ja/gettext.po @@ -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 \n" "Language-Team: Japanese\n" "Language: ja\n" @@ -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エントリーを無視" diff --git a/po/ko/gettext.po b/po/ko/gettext.po index 882fd243..af267cb2 100644 --- a/po/ko/gettext.po +++ b/po/ko/gettext.po @@ -83,6 +83,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/lv/gettext.po b/po/lv/gettext.po index 810ead90..1026fcd4 100644 --- a/po/lv/gettext.po +++ b/po/lv/gettext.po @@ -84,6 +84,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/nb/gettext.po b/po/nb/gettext.po index bed59387..ee6ae5bb 100644 --- a/po/nb/gettext.po +++ b/po/nb/gettext.po @@ -84,6 +84,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/nl/gettext.po b/po/nl/gettext.po index 329037ca..c4050afe 100644 --- a/po/nl/gettext.po +++ b/po/nl/gettext.po @@ -83,6 +83,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/pt_BR/gettext.po b/po/pt_BR/gettext.po index a45101ff..b454fb4d 100644 --- a/po/pt_BR/gettext.po +++ b/po/pt_BR/gettext.po @@ -85,6 +85,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/ru/gettext.po b/po/ru/gettext.po index 77f7d74b..ceaf267c 100644 --- a/po/ru/gettext.po +++ b/po/ru/gettext.po @@ -85,6 +85,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/sr/gettext.po b/po/sr/gettext.po index 87206995..251240e5 100644 --- a/po/sr/gettext.po +++ b/po/sr/gettext.po @@ -85,6 +85,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/sv/gettext.po b/po/sv/gettext.po index 990981c8..cce1cc10 100644 --- a/po/sv/gettext.po +++ b/po/sv/gettext.po @@ -81,6 +81,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/uk/gettext.po b/po/uk/gettext.po index c8fb200d..299f7fd2 100644 --- a/po/uk/gettext.po +++ b/po/uk/gettext.po @@ -88,6 +88,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/vi/gettext.po b/po/vi/gettext.po index e9651630..cfba3f59 100644 --- a/po/vi/gettext.po +++ b/po/vi/gettext.po @@ -84,6 +84,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/zh/gettext.po b/po/zh/gettext.po index 229cd6ec..dda52b26 100644 --- a/po/zh/gettext.po +++ b/po/zh/gettext.po @@ -87,6 +87,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/po/zh_TW/gettext.po b/po/zh_TW/gettext.po index e7b37e73..d34a19e1 100644 --- a/po/zh_TW/gettext.po +++ b/po/zh_TW/gettext.po @@ -86,6 +86,9 @@ msgid "" "s" msgstr "" +msgid "Use one line for each reference comment" +msgstr "" + msgid "Ignore fuzzy entries" msgstr "" diff --git a/test/tools/test_msgcat.rb b/test/tools/test_msgcat.rb index f61cba53..ef57e07a 100644 --- a/test/tools/test_msgcat.rb +++ b/test/tools/test_msgcat.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2018 Kouhei Sutou +# Copyright (C) 2014-2023 Sutou Kouhei # # License: Ruby's or LGPL # @@ -243,6 +243,7 @@ def setup @po = <<-PO # translator comment #: a.rb:1 +#: a.rb:2 msgid "Hello" msgstr "" PO @@ -252,6 +253,25 @@ def test_no_location assert_equal(<<-PO, run_msgcat([@po], "--no-location")) # translator comment msgid "Hello" +msgstr "" + PO + end + + def test_wrap + assert_equal(<<-PO, run_msgcat([@po], "--wrap")) +# translator comment +#: a.rb:1 a.rb:2 +msgid "Hello" +msgstr "" + PO + end + + def test_use_one_line_per_reference + assert_equal(<<-PO, run_msgcat([@po], "--wrap", "--use-one-line-per-reference")) +# translator comment +#: a.rb:1 +#: a.rb:2 +msgid "Hello" msgstr "" PO end diff --git a/test/tools/test_msgmerge.rb b/test/tools/test_msgmerge.rb index dea52059..1ca9e2da 100644 --- a/test/tools/test_msgmerge.rb +++ b/test/tools/test_msgmerge.rb @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2012-2020 Sutou Kouhei +# Copyright (C) 2012-2023 Sutou Kouhei # Copyright (C) 2010 Eddie Lau # # License: Ruby's or LGPL @@ -654,6 +652,46 @@ def test_no_location end end + class TestUseOneLinePerReference < self + def pot_content + super + <<-POT + +#: hello.rb:10 +#: hello.rb:20 +#: hello.rb:30 +msgid "Good morning" +msgstr "" + POT + end + + def test_with_wrap + @msgmerge.run("--update", + "--wrap", + "--use-one-line-per-reference", + @po_file_path, @pot_file_path) + assert_equal(<<-PO, File.read(@po_file_path)) +#{po_header(@pot_formatted_time, @po_formatted_time)} +#: hello.rb:1 +msgid "Hello" +msgstr "" + +#: hello.rb:2 +msgid "World" +msgstr "Translated World" + +#: hello.rb:3 +msgid "Good-bye" +msgstr "" + +#: hello.rb:10 +#: hello.rb:20 +#: hello.rb:30 +msgid "Good morning" +msgstr "" + PO + end + end + class TestWidth < self def pot_content <<-POT diff --git a/test/tools/test_xgettext.rb b/test/tools/test_xgettext.rb index 3ba191dc..7e25488c 100644 --- a/test/tools/test_xgettext.rb +++ b/test/tools/test_xgettext.rb @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2012-2020 Sutou Kouhei +# Copyright (C) 2012-2023 Sutou Kouhei # Copyright (C) 2012 Haruka Yoshihara # # License: Ruby's or LGPL @@ -116,6 +114,20 @@ def test_same_message msgstr "" EOP end + + def test_use_one_line_per_reference + pot_content = generate(<<-RUBY, "--use-one-line-per-reference") +_("Hello") +_("Hello") + RUBY + assert_equal(<<-POT, pot_content) +#{header} +#: ../lib/xgettext.rb:1 +#: ../lib/xgettext.rb:2 +msgid "Hello" +msgstr "" + POT + end end class TestParser < self