# Unicode HOWTO?

**URL:** <https://www.ruby-forum.com/t/unicode-howto/96096>\
**Category:** Rails\
**Created:** [June 26, 2006, 12:50am UTC](https://www.ruby-forum.com/t/unicode-howto/96096 "2006-06-26T00:50:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhaus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@rhaus](https://www.ruby-forum.com/u/rhaus)\
**Post date:** [June 26, 2006, 12:50am UTC](https://www.ruby-forum.com/t/unicode-howto/96096/1 "2006-06-26T00:50:00Z")

</div>

I am disappointed about the (seeming) lack of Unicode support in Rails.  
Is there a howto about working the most important limitations? For  
example, figuring out the length of an entered word: “Ã¶Ã¼Ã¶”.length() will  
return 6, not 3. So if there is a maximum number of characters a user is  
allowed to enter, this won’t work as it should – it treats strings as  
byte arrays instead of strings.

Is there an alternate string package that will treat Unicode Strings as  
arrays of Characters instead of Bytes - no matter how many bytes are  
used to encode a Character? Can anyone point me to a HOWTO or tutorial  
or documentation for how to do this?

---

<div class="post-metadata">

**Author:** ![rhaus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@rhaus](https://www.ruby-forum.com/u/rhaus)\
**Post date:** [June 26, 2006, 12:54am UTC](https://www.ruby-forum.com/t/unicode-howto/96096/2 "2006-06-26T00:54:44Z")

</div>

Visit -  
[http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings](http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings)  
they link you to some nice libraries that might be helpful for you.  
But yes, Rails isn’t that hot-show for unicode  
Nice day,  
Dor.

Roman H. wrote:

> I am disappointed about the (seeming) lack of Unicode support in Rails.  
> Is there a howto about working the most important limitations? For  
> example, figuring out the length of an entered word: “Ã¶Ã¼Ã¶”.length() will  
> return 6, not 3. So if there is a maximum number of characters a user is  
> allowed to enter, this won’t work as it should – it treats strings as  
> byte arrays instead of strings.
> 
> Is there an alternate string package that will treat Unicode Strings as  
> arrays of Characters instead of Bytes - no matter how many bytes are  
> used to encode a Character? Can anyone point me to a HOWTO or tutorial  
> or documentation for how to do this?

---

<div class="post-metadata">

**Author:** ![rhaus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@rhaus](https://www.ruby-forum.com/u/rhaus)\
**Post date:** [June 26, 2006, 3:42am UTC](https://www.ruby-forum.com/t/unicode-howto/96096/3 "2006-06-26T03:42:04Z")

</div>

Ã? usually do this with my applications and it works fine! Portuguese  
Brasil.

class ApplicationController \< ActionController::Base  
before\_filter :configure\_charsets

def configure\_charsets  
if request.xhr?  
@response.headers[“Content-Type”] ||= “text/javascript;  
charset=iso-8859-1”  
else  
@response.headers[“Content-Type”] ||= “text/html;  
charset=iso-8859-1”  
end  
end  
end

“Funciona que Ã© uma beleza! AbraÃ§Ã£o!”

---

<div class="post-metadata">

**Author:** ![rhaus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@rhaus](https://www.ruby-forum.com/u/rhaus)\
**Post date:** [June 26, 2006, 11:26am UTC](https://www.ruby-forum.com/t/unicode-howto/96096/4 "2006-06-26T11:26:40Z")

</div>

Roman H. wrote:

> I am disappointed about the (seeming) lack of Unicode support in Rails.  
> Is there a howto about working the most important limitations? For  
> example, figuring out the length of an entered word: “Ã¶Ã¼Ã¶”.length() will  
> return 6, not 3. So if there is a maximum number of characters a user is  
> allowed to enter, this won’t work as it should – it treats strings as  
> byte arrays instead of strings.
> 
> Is there an alternate string package that will treat Unicode Strings as  
> arrays of Characters instead of Bytes - no matter how many bytes are  
> used to encode a Character? Can anyone point me to a HOWTO or tutorial  
> or documentation for how to do this?

Unicode support in Ruby does not exists.

I have been to a kind of workshop last week and Julik presented a kick  
us presentation, you can check the plugin as a start  
[http://julik.nl/code/unicode-hacks/index.html](http://julik.nl/code/unicode-hacks/index.html)

And send a an email to Matsumoto asking when we will have unicode  
support in Ruby.

Good luck  
Gokhan A.  
[www.sylow.net](http://www.sylow.net)

---

<div class="post-metadata">

**Author:** ![rhaus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@rhaus](https://www.ruby-forum.com/u/rhaus)\
**Post date:** [June 26, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/unicode-howto/96096/5 "2006-06-26T17:33:25Z")

</div>

On 26-jun-2006, at 0:50, Roman H. wrote:

> Is there an alternate string package that will treat Unicode  
> Strings as  
> arrays of Characters instead of Bytes - no matter how many bytes are  
> used to encode a Character? Can anyone point me to a HOWTO or tutorial  
> or documentation for how to do this?

There is exactly such a package - it’s behaviour is a little unstable  
now, because as soon as your diacritics  
or parts of a ligature (of compound chars) cannot be normalised into  
one codepoint it does what you don’t really expect.

Try unicode\_hacks. We are trying to get them into Rails but as of  
now I haven’t seen any interest on the part of the core.

–  
Julian ‘Julik’ Tarkhanov  
please send all personal mail to  
me at julik.nl

---

<div class="post-metadata">

**Author:** ![rhaus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@rhaus](https://www.ruby-forum.com/u/rhaus)\
**Post date:** [June 27, 2006, 8:56am UTC](https://www.ruby-forum.com/t/unicode-howto/96096/6 "2006-06-27T08:56:35Z")

</div>

Julian ‘Julik’ Tarkhanov skrev:

> Try unicode\_hacks. We are trying to get them into Rails but as of now  
> I haven’t seen any interest on the part of the core.

Apparently the use of unicode in an application is “application specific  
behaviour”. The Rails core team take many good decisions but the  
decision to not include unicode support in the core is just insane.  
Everyone wanting to use unicode will do it more or less the same. Not  
having it in the core is to break DRY on a universal level.

Yes, I know this can probably be done as a plugin. The problem with  
plugins that will dig as deep into the core as a plugin like this will  
probably break on every new version of the core so the plugin will  
always lag behind the core versions (maybe not long but it will be  
enough). If inside the core someone will have the responsibility to take  
care of it before releasing a new version of the core. No?

/Marcus

ps. They (Rails core team) might have reconsidered to actually include  
unicode support in Rails. If that is the case I take back what I said

---

<div class="post-metadata">

**Author:** ![rhaus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@rhaus](https://www.ruby-forum.com/u/rhaus)\
**Post date:** [June 27, 2006, 9:18am UTC](https://www.ruby-forum.com/t/unicode-howto/96096/7 "2006-06-27T09:18:16Z")

</div>

> Try unicode\_hacks. We are trying to get them into Rails but as of  
> now I haven’t seen any interest on the part of the core.
> 
> –

Which one should we install?

- The plugin at  
[http://julik.textdriven.com/svn/tools/rails\_plugins/unicode\_hacks/](http://julik.textdriven.com/svn/tools/rails_plugins/unicode_hacks/)  
or
- The ActiveSupport patch at [http://dev.rubyonrails.org/ticket/5396](http://dev.rubyonrails.org/ticket/5396)

or both? 🙂 And how do we install both? 🙂

---

<div class="post-metadata">

**Author:** ![rhaus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e68b1a/32.png) [@rhaus](https://www.ruby-forum.com/u/rhaus)\
**Post date:** [June 27, 2006, 7:44pm UTC](https://www.ruby-forum.com/t/unicode-howto/96096/8 "2006-06-27T19:44:27Z")

</div>

On 27-jun-2006, at 9:15, Dmitrii D. wrote:

> > Try unicode\_hacks. We are trying to get them into Rails but as of  
> > now I haven’t seen any interest on the part of the core.
> > 
> > –
> 
> Which one should we install?
> 
> - The plugin at  
> [http://julik.textdriven.com/svn/tools/rails\_plugins/unicode\_hacks/](http://julik.textdriven.com/svn/tools/rails_plugins/unicode_hacks/)  
> or
> - The ActiveSupport patch at [http://dev.rubyonrails.org/ticket/5396](http://dev.rubyonrails.org/ticket/5396)

The plugin is being updated all the time. The patch is more for the  
rails-core to evaluate,  
but we will eventually get to updating it as well.

–  
Julian ‘Julik’ Tarkhanov  
please send all personal mail to  
me at julik.nl
