# International characters

**URL:** <https://www.ruby-forum.com/t/international-characters/57286>\
**Category:** Rails\
**Created:** [April 9, 2006, 12:57am UTC](https://www.ruby-forum.com/t/international-characters/57286 "2006-04-09T00:57:36Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 12:57am UTC](https://www.ruby-forum.com/t/international-characters/57286/1 "2006-04-09T00:57:36Z")

</div>

I am new to Ruby on Rails. I have read a lot, and bought several books,  
and now I have started to implement a modified “shopping cart”,  
following the AWDWR-book, with modifications to suit our application  
(subscriptions and memberships).

Having done up to chapter 7 I have had no real problems, except one:

Since our customers are Swedish I need the screen names, texts etc to be  
in swedish, (the internals are ok with English, which we always have  
used to be prepared for business abroad some day).

When I in the .rhtml files write characters Ã¥, Ã¤, and Ã¶ (or Ã?, Ã?,  
Ã?)[these are swedish charactera a a and o, A, A with umlaut characters  
above] I get a problem: the show up on the screen as a question mark [?]

Does not UTF-8 take care of this?

How do I adjust the .rhtml files to show Swedish characters?

Thanks in advance!

Per-Olof

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 8:32am UTC](https://www.ruby-forum.com/t/international-characters/57286/2 "2006-04-09T08:32:35Z")

</div>

> > > > > “Per-Olof” == Per-Olof H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> When I in the .rhtml files write characters å, ä, and ö (or Å, Ä,  
> Ö)[these are swedish charactera a a and o, A, A with umlaut characters  
> above] I get a problem: the show up on the screen as a question mark [?]

> Does not UTF-8 take care of this?

## You have to make sure that the rhtml files are actually in UTF-8.

```
	     Calle D. <removed_email_address@domain.invalid>
	 http://www.livejournal.com/users/cdybedahl/
"Just about anything can be done if you are demented enough."
	-- Christopher C. Petro, scary.devil.monastery

```

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 9:35am UTC](https://www.ruby-forum.com/t/international-characters/57286/3 "2006-04-09T09:35:09Z")

</div>

Calle D. wrote:

> > > > > > “Per-Olof” == Per-Olof H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> > When I in the .rhtml files write characters ï¿½, ï¿½, and ï¿½ (or ï¿½, ï¿½,  
> > ï¿½)[these are swedish charactera a a and o, A, A with umlaut characters  
> > above] I get a problem: the show up on the screen as a question mark [?]
> 
> > Does not UTF-8 take care of this?
> 
> ## You have to make sure that the rhtml files are actually in UTF-8.
> 
> ```
> Calle D. <removed_email_address@domain.invalid>
> http://www.livejournal.com/users/cdybedahl/
> 
> ```
> 
> “Just about anything can be done if you are demented enough.”  
> – Christopher C. Petro, scary.devil.monastery

I have tried that, but I realize now that I also must configure RoR to  
be in “UTF-8 mode”, and that there are some complications with this.

Is there any other way?

Per-Olof

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 9:45am UTC](https://www.ruby-forum.com/t/international-characters/57286/4 "2006-04-09T09:45:26Z")

</div>

> > > > > “Per-Olof” == Per-Olof H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> I have tried that, but I realize now that I also must configure RoR to  
> be in “UTF-8 mode”, and that there are some complications with this.

There are? It seems to be working perfectly for me. What complications  
are you experiencing?

> Is there any other way?

## Make everything Latin-1 instead? Rails itself is fairly encoding-agnostic, as far as I’ve seen.

```
	     Calle D. <removed_email_address@domain.invalid>
	 http://www.livejournal.com/users/cdybedahl/
         Try again. Try harder. -*- Fail again. Fail better.

```

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 10:00am UTC](https://www.ruby-forum.com/t/international-characters/57286/5 "2006-04-09T10:00:50Z")

</div>

> > Is there any other way?  
> > Hej!

Try putting this snippet in application.rb:

def configure\_charsets  
@response.headers[“Content-Type”] = “text/html; charset=utf-8”  
suppress(ActiveRecord::StatementInvalid) do  
ActiveRecord::Base.connection.execute ‘SET NAMES UTF8’  
end  
end

If you want to learn more, This is a good article about Rails and  
Unicode  
[http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/](http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/)

Magnus

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 10:02am UTC](https://www.ruby-forum.com/t/international-characters/57286/6 "2006-04-09T10:02:25Z")

</div>

magnus Hjelm wrote:

> > > Is there any other way?  
> > > Hej!
> 
> Try putting this snippet in application.rb:
> 
> def configure\_charsets  
> @response.headers[“Content-Type”] = “text/html; charset=utf-8”  
> suppress(ActiveRecord::StatementInvalid) do  
> ActiveRecord::Base.connection.execute ‘SET NAMES UTF8’  
> end  
> end
> 
> If you want to learn more, This is a good article about Rails and  
> Unicode  
> [http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/](http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/)
> 
> Magnus

Thanks, IÂ´ll try it,

Per-Olof

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 10:10am UTC](https://www.ruby-forum.com/t/international-characters/57286/7 "2006-04-09T10:10:31Z")

</div>

magnus Hjelm wrote:

> > > Is there any other way?  
> > > Hej!
> 
> Try putting this snippet in application.rb:
> 
> def configure\_charsets  
> @response.headers[“Content-Type”] = “text/html; charset=utf-8”  
> suppress(ActiveRecord::StatementInvalid) do  
> ActiveRecord::Base.connection.execute ‘SET NAMES UTF8’  
> end  
> end
> 
> If you want to learn more, This is a good article about Rails and  
> Unicode  
> [http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/](http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/)
> 
> Magnus

This seems only to have changed the content of fields in tables. That  
was actually no problem before. I had problems with the .rhtml text, not  
the content strings of my database. Still get wrong characters of the  
texts i the .rhtml pages.

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 10:01am UTC](https://www.ruby-forum.com/t/international-characters/57286/8 "2006-04-09T10:01:38Z")

</div>

Calle D. wrote:

> > > > > > “Per-Olof” == Per-Olof H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:
> 
> > I have tried that, but I realize now that I also must configure RoR to  
> > be in “UTF-8 mode”, and that there are some complications with this.
> 
> There are? It seems to be working perfectly for me. What complications  
> are you experiencing?
> 
> > Is there any other way?
> 
> ## Make everything Latin-1 instead? Rails itself is fairly encoding-agnostic, as far as I’ve seen.
> 
> ```
> Calle D. <removed_email_address@domain.invalid>
> http://www.livejournal.com/users/cdybedahl/
> Try again. Try harder. -*- Fail again. Fail better.
> 
> ```

I havenÂ´t set the environment.rb to UTF-8 yet, but I read the  
Wiki:[Peak Obsession](http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings) and  
they take upp some of the issues (strings, sorting etc)

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 10:11am UTC](https://www.ruby-forum.com/t/international-characters/57286/9 "2006-04-09T10:11:55Z")

</div>

Per-Olof H. wrote:

> Calle D. wrote:
> 
> > Make everything Latin-1 instead? Rails itself is fairly  
> > encoding-agnostic, as far as I’ve seen.

ThatÂ´s what I had from start. Contents are ok, but problems with the  
characters in the .rhtml pages.

Per-Olof

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 10:15am UTC](https://www.ruby-forum.com/t/international-characters/57286/10 "2006-04-09T10:15:58Z")

</div>

We’re using UTF-8 here and just don’t tell Rails about it. 🙂

So, we’re just moving the character data from the database to the  
browser  
or vice-versa as “plain bytes”.

If you need stuff like sorting/upcase/downcase in Ruby to work  
correctly,  
you can try using the “unicode” gem as described on the wiki page:  
…using the routines from the Unicode library by Yoshida Masato,  
available as a gem

gem install unicode  
After that the following functions will be available:

Unicode::downcase(string)  
Unicode::downcase(string)  
Unicode::normalize etc.

-Thomas

Am 09.04.2006 um 10:01 schrieb Per-Olof H.:

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 10:32am UTC](https://www.ruby-forum.com/t/international-characters/57286/11 "2006-04-09T10:32:22Z")

</div>

Thomas F. wrote:

> We’re using UTF-8 here and just don’t tell Rails about it. 🙂

As of now I have content from database fields showing ok, but problems  
with certaing .rhtml files:

/views/layouts/subcribe.rhtml works fine:

\<?xml version="1.0" encoding="iso-8859-1"?\> FÃ¶rlagets Namn \<%= stylesheet\_link\_tag 'subscribe', :media =\> 'all' %\> 

```
<body>

  <div id='banner'>
    <img src="/images/logo.png" alt="Logga" height="40" width="40" 

```

border=“5” /\>  
\<%= @page\_title || “PrenumerationsanmÃ¤lan” %\>

```
  <div id='columns'>

```

* * *

but not  
/views/subscribe/index.rhtml:

\<% for product in @products %\>

### \<%=h(product.designation) %\>
 \<%= product.commitment %\> \<%= product.segment %\>   
  
 \<%= sprintf("%0.2f", product.price) %\> Kr

```
  <%= link_to 'BestÃ¤ll',
              {:action => 'add_to_cart', :id => product },
              :class => 'addtocart' %> <br/>

```

&nbsp;
\<% end %\> \<%= link\_to "Visa min bestÃ¤llning", :action =\> "display\_cart" %\>

the word ‘BestÃ¤ll’ and “Visa min bestÃ¤llning” becomes Best?ll etc.

Per-Olof

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 3:24pm UTC](https://www.ruby-forum.com/t/international-characters/57286/12 "2006-04-09T15:24:18Z")

</div>

On the issue of international characters I (as a total newbie) wonder if  
the following distinction of internationalization is correct in RoR.

The issue has three levels (and I found it difficult to distinguish  
between them in the documentation on the RoR-Wikil

1. rhtml-level, how to get UTF-8 characters to be presented correctly in  
a browser (view-level?)

2. database content (i.e the content in the fields of the tables in the  
database (controller-level?)

3. database design (meta?) level, i.e the names of tables and fields of  
the database (model-level?)

I have solved level one in my installation, and that works for me, I  
donÂ´t need table names and fields with other than english characters  
since we use english on the database design level.

In the future I might need a solution on level 2, but IÂ´ll tackle that  
when that time comes…

Regards,

Per-Olof

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 2:52pm UTC](https://www.ruby-forum.com/t/international-characters/57286/13 "2006-04-09T14:52:51Z")

</div>

I have now reverted to “not telling Rails about it”, i.e in  
application.rb I donÂ´t have any reference to character sets.

In the layout I have:

Thirdly I made sure to save the index.rhtml (referenced as \<%=  
@content\_for\_layout %\> in the layout) with format UTF-8. Obviously my  
editor (UltraEdit) saved it as something else by default, and when I  
experimented the layout got saved as UTF-8 but not the index.rhtml.

So, my problem solved.

It was Thomas F. messsage not to tel “Rails about it” that got me  
thinking in the right direction.

Thanks everyone!

Per-Olof

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 4:29pm UTC](https://www.ruby-forum.com/t/international-characters/57286/14 "2006-04-09T16:29:57Z")

</div>

Per-Olof H. wrote:

> Per-Olof H. wrote:
> 
> > Calle D. wrote:
> > 
> > > Make everything Latin-1 instead? Rails itself is fairly  
> > > encoding-agnostic, as far as I’ve seen.
> 
> ThatÂ´s what I had from start. Contents are ok, but problems with the  
> characters in the .rhtml pages.
> 
> Per-Olof  
> Make sure your .rhtml files are encoded in UTF8 and not some latin-1 or  
> macroman format… This setting is done in your editor. Textedit on mac  
> has an option to set the encoding when you “save as…” for example.  
> Textmate has the same.

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/international-characters/57286/15 "2006-04-09T18:35:56Z")

</div>

> I tried RadRails, but could not find where to set the encoding type.
> 
> Per-Olof  
> Ctrl+Click a file/folder --\> Properties --\> Text file encoding

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 9, 2006, 6:03pm UTC](https://www.ruby-forum.com/t/international-characters/57286/16 "2006-04-09T18:03:31Z")

</div>

Gazoduc wrote:

> Make sure your .rhtml files are encoded in UTF8 and not some latin-1 or  
> macroman format… This setting is done in your editor. Textedit on mac  
> has an option to set the encoding when you “save as…” for example.  
> Textmate has the same.

Yes, I am learning that the hard way, UltraEdit that I use can set “sav  
as…”, but then it seam I cannot type in UTF8-mode (I canÂ´t see what I  
type). I have posted a question on UltraEdit forum about this, but it  
seems that I need to fina another editor.

I tried RadRails, but could not find where to set the encoding type.

Per-Olof

---

<div class="post-metadata">

**Author:** ![perherman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ec8ea/32.png) [@perherman](https://www.ruby-forum.com/u/perherman)\
**Post date:** [April 10, 2006, 1:22pm UTC](https://www.ruby-forum.com/t/international-characters/57286/17 "2006-04-10T13:22:39Z")

</div>

Gazoduc wrote:

> > I tried RadRails, but could not find where to set the encoding type.
> > 
> > Per-Olof  
> > Ctrl+Click a file/folder --\> Properties --\> Text file encoding

Thanks,  
I tried it and it works fine. Also found where to set it in UltraEdit.  
But from what i have seen in Radrails I will use Radrails for working  
with RoR, and keep UltraEdit for working with large textfiles.

Per-Olof
