Rails, i18n and Ruby 1.9

55 views
Skip to first unread message

Erik Dahlstrand

unread,
Jun 2, 2009, 3:13:58 AM6/2/09
to rails-i18n
Hi!

I'm trying to migrate my Rails application to run on Ruby 1.9.

Lets say I'm on a show action for a simple model. The show view
displays the model and also contains some i18n translation strings.
The problem occurs when the model contains non-ASCII character (åäö)
AND any of the translation strings contains non-ASCII characters. Then
there is a view exception:

ActionView::TemplateError (incompatible character encodings:
ASCII-8BIT and UTF-8)

The same problem is for SQLite and MySQL. I would really appreciate
some help. Thanks!

/Erik

Vladimir

unread,
Jun 2, 2009, 6:08:04 AM6/2/09
to rails...@googlegroups.com
Hi,

I guess you need to set default external_encoding, check this http://blog.grayproductions.net/articles/ruby_19s_three_default_encodings for more info.

Erik Dahlstrand

unread,
Jun 2, 2009, 8:55:34 AM6/2/09
to rails-i18n
Thanks Vladimir, but it didn't solve my problem.

I put this in environment.rb
Encoding.default_external = 'UTF-8'



On 2 Juni, 12:08, Vladimir <v.st...@gmail.com> wrote:
> Hi,
>
> I guess you need to set default external_encoding, check thishttp://blog.grayproductions.net/articles/ruby_19s_three_default_encod...
> more info.

Vladimir

unread,
Jun 2, 2009, 9:11:49 AM6/2/09
to rails...@googlegroups.com
There are some other ways in that post to specify default encoding, like $LC_CTYPE environment variable and ruby -w switch.

In any case it would be good to figure out what exactly is in ASCII-8BIT. Try executing in ./script/console
>> I18n.translate('transation_key').internal_encoding

And even better to execute this code inside the view, because server startup environment may differ from console.

Vladimir.

"Martin J. Dürst"

unread,
Jun 11, 2009, 9:20:03 PM6/11/09
to rails...@googlegroups.com
Hello everybody. This is my first post to this list.

I'm not (yet) familiar with Rails i18n, but I'm quite familiar with Ruby
1.9 and with internationalization in general.

For the problem below, please try to find out which side uses ASCII-8BIT
(Ruby speak for ASCII plus 8-bit data of unknown encoding, also used for
binary data) and which side uses UTF-8. By 'side', I mean the database
side and the side that's providing the translation strings.

Then, assuming that you are dealing with UTF-8, have a closer look at
how to have the side that's currently labeling data as ASCII-8BIT change
to UTF-8.

Regards, Martin.
--
#-# Martin J. Dürst, Professor, Aoyama Gakuin University
#-# http://www.sw.it.aoyama.ac.jp mailto:due...@it.aoyama.ac.jp
Reply all
Reply to author
Forward
0 new messages