Skip to content

Commit

Permalink
po parser: fix a bug that flags aren't parsed correctly
Browse files Browse the repository at this point in the history
If a normal comment has "fuzzy", the entry is also treated as a fuzzy
entry.
  • Loading branch information
kou committed Oct 13, 2023
1 parent d99d2fd commit a318f8f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/gettext/po_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ def format_comment(comments)
end
def on_comment(comment)
@fuzzy = true if (/fuzzy/ =~ comment)
if comment.start_with?(POFormat::FLAG_MARK)
content = comment[POFormat::FLAG_MARK.size..-1]
flags = parse_flags_line(content)
@fuzzy = true if flags.include?("fuzzy")
end
if @data.instance_of?(PO)
if comment == "#"
@translator_comments << ""
Expand All @@ -176,7 +180,7 @@ def on_comment(comment)
when POFormat::REFERENCE_COMMENT_MARK
@references.concat(parse_references_line(content))
when POFormat::FLAG_MARK
@flags.concat(parse_flags_line(content))
@flags.concat(flags)
when POFormat::PREVIOUS_COMMENT_MARK
@previous << content
else
Expand Down Expand Up @@ -245,7 +249,7 @@ def parse_references_line(line)
end
def parse_flags_line(line)
line.split(/\s+/)
line.split(",").collect(&:strip)
end
def clear
Expand Down
10 changes: 7 additions & 3 deletions src/po_parser.ry
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ require "gettext/po"
end

def on_comment(comment)
@fuzzy = true if (/fuzzy/ =~ comment)
if comment.start_with?(POFormat::FLAG_MARK)
content = comment[POFormat::FLAG_MARK.size..-1]
flags = parse_flags_line(content)
@fuzzy = flags.include?("fuzzy")
end
if @data.instance_of?(PO)
if comment == "#"
@translator_comments << ""
Expand All @@ -279,7 +283,7 @@ require "gettext/po"
when POFormat::REFERENCE_COMMENT_MARK
@references.concat(parse_references_line(content))
when POFormat::FLAG_MARK
@flags.concat(parse_flags_line(content))
@flags.concat(flags)
when POFormat::PREVIOUS_COMMENT_MARK
@previous << content
else
Expand Down Expand Up @@ -348,7 +352,7 @@ require "gettext/po"
end

def parse_flags_line(line)
line.split(/\s+/)
line.split(",").collect(&:strip)
end

def clear
Expand Down
6 changes: 6 additions & 0 deletions test/test_po_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ def test_fuzzy_ignore
msgid "hello"
msgstr "bonjour"
#, c-format, fuzzy , no-sh-format
#: file.rb:11
msgid "world"
msgstr "monde"
# This is not fuzzy
msgid "non-fuzzy"
msgstr "non-fuzzy string"
PO
Expand Down

0 comments on commit a318f8f

Please sign in to comment.