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/
69 stars 28 forks source link

Parsing error with `%i[a b]` #53

Closed renchap closed 7 years ago

renchap commented 7 years ago

The parser seems to confuse %i[a b] (or %i(a b)) with a string. I am getting this error when running rake gettext:find:

Error parsing app/models/concerns/normalize_blank.rb:12
           next unless %i[aa bb].include?(self.class.columns_hash[column].type)

 #<TypeError: no implicit conversion of Array into String> in
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/po_entry.rb:228:in `+'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/po_entry.rb:228:in `set_value'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:90:in `set_current_attribute'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:264:in `block in parse_source'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:57:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:242:in `parse_source'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:217:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:134:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:365:in `block in parse_path'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:360:in `each'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:360:in `parse_path'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:168:in `block in parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:166:in `each'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:166:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:217:in `generate_pot'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:151:in `run'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:34:in `run'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/task.rb:330:in `xgettext'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/task.rb:314:in `create_pot'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/task.rb:306:in `block in define_pot_file_task'

After debugging, in the set_value (https://github.com/ruby-gettext/gettext/blob/master/lib/gettext/po_entry.rb#L226) call I get value = [:aa, :bb].

I am not sure what is happening here, I guess the parser needs to take this syntax into account. %i has been introduced in Ruby 2.0.

kou commented 7 years ago

Please provide a Ruby script that reproduces the problem?

I couldn't reproduce it.

# symbols.rb
%i[a b]
% rxgettext symbols.rb
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-08-13 21:24+0900\n"
"PO-Revision-Date: 2017-08-13 21:24+0900\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
renchap commented 7 years ago

Sorry, I should have checked when it occured.

Here is a script that fails:

# symbols.rb
(1..2).each do |i, _|
  %i[aa bb]
end
% rxgettext symbols.rb

Error parsing symbols.rb:2
       %i[aa bb]

 #<TypeError: no implicit conversion of Array into String> in
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/po_entry.rb:226:in `+'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/po_entry.rb:226:in `set_value'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:90:in `set_current_attribute'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:264:in `block in parse_source'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:57:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:242:in `parse_source'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:217:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:134:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:365:in `block in parse_path'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:360:in `each'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:360:in `parse_path'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:168:in `block in parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:166:in `each'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:166:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:217:in `generate_pot'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:151:in `run'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:34:in `run'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/bin/rxgettext:24:in `<top (required)>'
/Users/renchap/.rbenv/versions/2.4.1/bin/rxgettext:22:in `load'
/Users/renchap/.rbenv/versions/2.4.1/bin/rxgettext:22:in `<main>'

I noticed that if you remove the , _ in the block parameters, it works fine (both in the example and my application code).

kou commented 7 years ago

Thanks. I've fixed.

renchap commented 7 years ago

Awesome, thanks!