ruby-gettext / gettext

Gettext gem is a pure Ruby Localization(L10n) library and tool which is modeled after the GNU gettext package.
https://ruby-gettext.github.io/
68 stars 28 forks source link

gettext does not parse TStrings after bitwise or "|" #73

Closed dorle-o closed 4 years ago

dorle-o commented 4 years ago

Since commit 41ee55b8c50d95175cfb3cb8cb530f09e61ccf7c all occurences of TStrings are ignored after a bitwise or "|". I think it is caused by the exclusion of block parameters with the process_on_op method and the early return in process_on_ident. Both, block parameter limiters and the bitwise or operator, are recoognized as :on_op by the Ripper Lexer.

Here is a dummy example to demonstrate the problem:

test_file.rb:

[1, 2].map do |e|
  puts _('tstring1')
  result = e | 2
  puts _('tstring2')
  result
end
GetText::RubyParser.new('test_file.rb').parse
> [#<GetText::POEntry:0x000055ba94c53218 
          @type=:normal,
          @param_type=[:msgid, :separator, :msgstr], 
          @translator_comment=nil,
          @extracted_comment=nil,
          @references=["test_file.rb:2"],
          @flags=[],
          @previous=nil,
          @msgctxt=nil,
          @msgid="tstring1",
          @msgid_plural=nil,
          @msgstr=nil>]

Even though I would expect an output like this:

> [#<GetText::POEntry:0x000055ba94c53218 
          @type=:normal,
          @param_type=[:msgid, :separator, :msgstr], 
          @translator_comment=nil,
          @extracted_comment=nil,
          @references=["test_file.rb:2"],
          @flags=[],
          @previous=nil,
          @msgctxt=nil,
          @msgid="tstring1",
          @msgid_plural=nil,
          @msgstr=nil>,
   #<GetText::POEntry:0x000055ba94c04820  
          @type=:normal,
          @param_type=[:msgid, :separator, :msgstr],
          @translator_comment=nil, 
          @extracted_comment=nil,
          @references=["test_file.rb:4"],
          @flags=[], 
          @previous=nil, 
          @msgctxt=nil,
          @msgid="tstring2",
          @msgid_plural=nil,
          @msgstr=nil>]
kou commented 4 years ago

Thanks for your report. I've fixed it.