Technology and Software

gettext puzzle: unknown type of %string, Solved

I was running a routine rake updatepo for a Rails application of mine when suddenly I got a unknown type of %string error. The Ruby parsing routines used by gettext weren’t able to understand something that the Ruby interpreter has no problem understanding. There were no hints of the offending lines so finding what to fix in my code was a little troublesome.

A little digging in the error trace got me to the method identify_quotation in the file /usr/lib/ruby/1.8/irb/ruby-lex.rb

I added these lines before RubyLex.fail SyntaxError, "unknown type of %string"

puts "Error parsing Ruby source."
puts "Here are the 200 characters following the error point.\n"
200.times do
  putc getc
end
puts ""

Running rake again let me see the code immediately following the point where the parser failed. As it turned out the problem was the %m format argument of the calls to strtime embedded inside %() or in multi line strings. Rephrasing those strings let rake updatepo succeed.

Advertisements
Standard

2 thoughts on “gettext puzzle: unknown type of %string, Solved

  1. I don’t remember the exact code I was working on but I had to extract the statement with %m from the string. A simple and naive example:

    time_s = time.strftime(“%Y-%m-%d %H:%M”)
    str = %(_(“Time %s”) % time_s)

    I don’t know if you can create a work around for Haml as I’m not using it because of its semantic indentation thing. Too risky.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s