Skip to content

Instantly share code, notes, and snippets.

@bonyiii
Created February 21, 2011 12:57
Show Gist options
  • Save bonyiii/837029 to your computer and use it in GitHub Desktop.
Save bonyiii/837029 to your computer and use it in GitHub Desktop.
rails gettext ascii-8bit encoding error

If you use a not english msgid in a rails ERB template, for example: _('Jelszó megerősítés'). And then you run rake gettext:find

it will likely raise an error like this:

rake aborted!
"\xC3" from ASCII-8BIT to UTF-8
~/.rvm/gems/ruby-1.9.2-p0@rails3/gems/gettext-2.1.0/lib/gettext/tools/rgettext.rb:198:in `write'

To avoid this error, replace line 31 in lib/gettext/tools/parser/erb.rb from

src = ERB.new(IO.readlines(file).join).src

to

src = ERB.new(IO.readlines(file).join).src.force_encoding('utf-8')

keep in mind use of force_encoding is not recommended by many people around the web:

[This] dont and [This] rubyforum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment