# Ruby and unicode

**URL:** <https://rubytalk.org/t/ruby-and-unicode/27698>\
**Category:** ruby-talk\
**Created:** [24 May 2006 18:05 UTC](https://rubytalk.org/t/ruby-and-unicode/27698 "2006-05-24T18:05:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Bergstrom](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Paul\_Bergstrom](https://rubytalk.org/u/Paul_Bergstrom)\
**Post date:** [24 May 2006 18:05 UTC](https://rubytalk.org/t/ruby-and-unicode/27698/1 "2006-05-24T18:05:42Z")

</div>

Does Ruby support unicode? If not it's a disappointment.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Dae\_San\_Hwang](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@Dae\_San\_Hwang](https://rubytalk.org/u/Dae_San_Hwang)\
**Post date:** [24 May 2006 18:18 UTC](https://rubytalk.org/t/ruby-and-unicode/27698/2 "2006-05-24T18:18:17Z")

</div>

Well, there are extension libraries for handling unicodes. It is also expected that Ruby 2.0 will bring more complete I18N supports.

What are your needs?

daesan

> **···**
>
> On May 25, 2006, at 3:05 AM, Pål Bergström wrote:
> 
> > Does Ruby support unicode? If not it's a disappointment.
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> Dae San Hwang  
> daesan@gmail.com

---

<div class="post-metadata">

**Author:** ![Paul\_Bergstrom](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Paul\_Bergstrom](https://rubytalk.org/u/Paul_Bergstrom)\
**Post date:** [24 May 2006 19:20 UTC](https://rubytalk.org/t/ruby-and-unicode/27698/3 "2006-05-24T19:20:08Z")

</div>

Dae San Hwang wrote:

> Well, there are extension libraries for handling unicodes. It is  
> also expected that Ruby 2.0 will bring more complete I18N supports.
> 
> What are your needs?
> 
> daesan
> 
> > Does Ruby support unicode? If not it's a disappointment.
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> Dae San Hwang  
> daesan@gmail.com

Just to be able to work smoothly from source to browser in Swedish  
without problems, the beauty of unicode. As I can understand it works  
like php, where certain methods like string lengths can give problems,  
but besides that it just passes it through. Is this correct?

> **···**
>
> > On May 25, 2006, at 3:05 AM, Pål Bergström wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Peter\_Krantz](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@Peter\_Krantz](https://rubytalk.org/u/Peter_Krantz)\
**Post date:** [24 May 2006 20:37 UTC](https://rubytalk.org/t/ruby-and-unicode/27698/4 "2006-05-24T20:37:32Z")

</div>

Pål, you don't have to use unicode to work in swedish. ISO-8859-1 will  
be sufficient to get accented characters including åäö. ISO-8859-1 is  
handled by Ruby without any problems.

If your are working in Rails, please see the swedish Rails user group  
wiki for details:

[http://rails.se/rails/show/Railstips+för+svenska+applikationer](http://rails.se/rails/show/Railstips+f%C3%B6r+svenska+applikationer)

Regards,

Peter

> **···**
>
> On 5/24/06, Pål Bergström \<pal@palbergstrom.com\> wrote:
> 
> > Just to be able to work smoothly from source to browser in Swedish  
> > without problems, the beauty of unicode.

---

<div class="post-metadata">

**Author:** ![Dae\_San\_Hwang](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@Dae\_San\_Hwang](https://rubytalk.org/u/Dae_San_Hwang)\
**Post date:** [24 May 2006 21:02 UTC](https://rubytalk.org/t/ruby-and-unicode/27698/5 "2006-05-24T21:02:55Z")

</div>

Yes, strings in UTF8 (or any character set for that matter) simply pass through since they are just byte sequence.

If you need methods that properly manipulate UTF8 strings, install unicode gem and install unicode hacks from [http://julik.textdriven.com/svn/tools/rails\_plugins/unicode\_hacks/](http://julik.textdriven.com/svn/tools/rails_plugins/unicode_hacks/)

Unicode hacks replaces String methods with UTF8 aware versions.

You would also need to put following code snippet in config/environment.rb:

$KCODE = 'u'

[http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings](http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings) is a good resource for unicode usage on rails.

daesan

> **···**
>
> On May 25, 2006, at 4:20 AM, Pål Bergström wrote:
> 
> > Just to be able to work smoothly from source to browser in Swedish  
> > without problems, the beauty of unicode. As I can understand it works  
> > like php, where certain methods like string lengths can give problems,  
> > but besides that it just passes it through. Is this correct?
> 
> Dae San Hwang  
> daesan@gmail.com

---

<div class="post-metadata">

**Author:** ![Izidor\_Jerebic](https://avatars.discourse-cdn.com/v4/letter/i/47e85d/32.png) [@Izidor\_Jerebic](https://rubytalk.org/u/Izidor_Jerebic)\
**Post date:** [26 May 2006 16:38 UTC](https://rubytalk.org/t/ruby-and-unicode/27698/6 "2006-05-26T16:38:51Z")

</div>

You should not advise the use of unicode hacks plugin, since it will very probably break any Rails application.

See for example \<[http://www.fngtps.com/2006/01/encoding-in-rails&gt](http://www.fngtps.com/2006/01/encoding-in-rails&gt); and \<[http://redhanded.hobix.com/inspect/unicodeLibForRuby18.html&gt;\.\.\](http://redhanded.hobix.com/inspect/unicodeLibForRuby18.html&gt;%5C.%5C.%5C).

Regards,

izidor

> **···**
>
> On 24.5.2006, at 23:02, Dae San Hwang wrote:
> 
> > If you need methods that properly manipulate UTF8 strings, install unicode gem and install unicode hacks from [http://julik.textdriven.com/svn/tools/rails\_plugins/unicode\_hacks/](http://julik.textdriven.com/svn/tools/rails_plugins/unicode_hacks/)
> > 
> > Unicode hacks replaces String methods with UTF8 aware versions.

---

<div class="post-metadata">

**Author:** ![Dae\_San\_Hwang](https://avatars.discourse-cdn.com/v4/letter/d/7feea3/32.png) [@Dae\_San\_Hwang](https://rubytalk.org/u/Dae_San_Hwang)\
**Post date:** [26 May 2006 19:05 UTC](https://rubytalk.org/t/ruby-and-unicode/27698/7 "2006-05-26T19:05:24Z")

</div>

Right, that is because Rails depend on many of String methods that unicode\_hacks replaces.

However, you can just rename the method names in unicode\_hacks. I just add 'u\_' prefix to all the methods in unicode\_hacks.

Cheers,  
Daesan

> **···**
>
> On May 27, 2006, at 1:38 AM, Izidor Jerebic wrote:
> 
> > On 24.5.2006, at 23:02, Dae San Hwang wrote:
> > 
> > > If you need methods that properly manipulate UTF8 strings, install unicode gem and install unicode hacks from [http://julik.textdriven.com/svn/tools/rails\_plugins/unicode\_hacks/](http://julik.textdriven.com/svn/tools/rails_plugins/unicode_hacks/)
> > > 
> > > Unicode hacks replaces String methods with UTF8 aware versions.
> > 
> > You should not advise the use of unicode hacks plugin, since it will very probably break any Rails application.
> > 
> > See for example \<[http://www.fngtps.com/2006/01/encoding-in-rails&gt](http://www.fngtps.com/2006/01/encoding-in-rails&gt); and \<[http://redhanded.hobix.com/inspect/unicodeLibForRuby18.html&gt;\.\.\](http://redhanded.hobix.com/inspect/unicodeLibForRuby18.html&gt;%5C.%5C.%5C).
> > 
> > Regards,
> > 
> > izidor
> 
> Dae San Hwang  
> daesan@gmail.com
