Skip to content

Commit 60392df

Browse files
ynojimakou
andauthored
Fix po entry flag text representation (#105)
Format multiple flags into a commma separated single line. Without this change, at least `msgcat` command, which is one of gettexts commands only loads last flag and the rest are ignored. --------- Co-authored-by: Sutou Kouhei <[email protected]>
1 parent a318f8f commit 60392df

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/gettext/po_entry.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,12 @@ def format_reference_comment
428428
end
429429

430430
def format_flag_comment
431-
formatted_flags = String.new
432-
@entry.flags.each do |flag|
433-
formatted_flags << format_comment(FLAG_MARK, flag)
431+
if @entry.flags.empty?
432+
String.new
433+
else
434+
joined_flags = @entry.flags.join(", ")
435+
format_comment(FLAG_MARK, joined_flags)
434436
end
435-
formatted_flags
436437
end
437438

438439
def format_previous_comment

test/test_po_entry.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,20 @@ def test_flag
344344
assert_equal(expected_po, entry.to_s)
345345
end
346346

347+
def test_multiple_flags
348+
entry = GetText::POEntry.new(:normal)
349+
entry.msgid = "msgid"
350+
entry.msgstr = "msgstr"
351+
entry.flags = ["It's the flag.", "fuzzy"]
352+
353+
expected_po = <<-EOP
354+
#, It's the flag., fuzzy
355+
msgid "msgid"
356+
msgstr "msgstr"
357+
EOP
358+
assert_equal(expected_po, entry.to_s)
359+
end
360+
347361
def test_previous
348362
entry = GetText::POEntry.new(:normal)
349363
entry.msgid = "msgid"

0 commit comments

Comments
 (0)