Skip to content

Commit

Permalink
Fix po entry flag text representation (#105)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ynojima and kou authored Oct 21, 2023
1 parent a318f8f commit 60392df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/gettext/po_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,12 @@ def format_reference_comment
end

def format_flag_comment
formatted_flags = String.new
@entry.flags.each do |flag|
formatted_flags << format_comment(FLAG_MARK, flag)
if @entry.flags.empty?
String.new
else
joined_flags = @entry.flags.join(", ")
format_comment(FLAG_MARK, joined_flags)
end
formatted_flags
end

def format_previous_comment
Expand Down
14 changes: 14 additions & 0 deletions test/test_po_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ def test_flag
assert_equal(expected_po, entry.to_s)
end

def test_multiple_flags
entry = GetText::POEntry.new(:normal)
entry.msgid = "msgid"
entry.msgstr = "msgstr"
entry.flags = ["It's the flag.", "fuzzy"]

expected_po = <<-EOP
#, It's the flag., fuzzy
msgid "msgid"
msgstr "msgstr"
EOP
assert_equal(expected_po, entry.to_s)
end

def test_previous
entry = GetText::POEntry.new(:normal)
entry.msgid = "msgid"
Expand Down

0 comments on commit 60392df

Please sign in to comment.