Rails and localization

I've started to learn Rails about a month ago.

It seems wonderful, except for one major issue: localization!

It's too complicated to develop a serious application in Brazil with
(or whatever other country with localization rules different from

I mean, how can I validate a number from user's input such as 1.234,45
how can I show it in all views in the same format, although storing it
correctly in database and doing math operations correctly... I used to
develop web sites in Perl a long time ago. It was pretty simple to add
localization support.

In Rails, it seems I would need to use something like number.l, at
best, in
my views... Maybe override String#to_f method could make "number
= '1.234,45'.to_f" be
converted to 1234.45, but I'm not that familiar with Ruby already...
how about the oposite? How to do that snippet show correctly?

<%= @project.price %>

I would like '1.234,45' output instead of '1234.45'.

It seems I would need something like

<%= @project.price.l %>

at least (and implement Class#l, of course).

Not to say that I would need to create a plugin for overriding the
validates_numericality_of helper. Or, maybe, overriding String#to_f,
wouldn't be necessary...

That said, IMHO, as Rails claims to follow the 80/20 rule, it should
consider a good suport for basic things like this kind of basic
localization, such as numbers, currency and other charsets, or at
good support to utf-8. I understand it is more a problem of Ruby than
Rails, but I think that there should be a huge effort to achieve
localization as easy as with Perl, Python and so on... Unless, most of
world will not be satisfied with Rails for serious applications,
they need to write only English sites...

More than 50% of the sites in the world are monolanguage in a language
than English. So, it should be considered in Ruby/Rails to give a
support for these applications, for continue claiming their solution

Maybe, the better approach would be embedding this support directly in
Ruby language, but I think the Rails users should help on this...

I've looked at Globalize, GLoc and some other plugins. These two are
internationalization, which is not a requirement for most of these
language than English" applications. They usually just need:
- localization of numbers and currency
- support for other charsets, or at least utf-8 (or 16)
- translation of Rails messages, or, at least, the validation error
messages. I know there are some dirty methods to do that, but I think
should be embedded directly on Rails with language directories
all translated error messages and scaffolding.

Another good topic is scaffolding... I think it should be more
flexive. For
instance, it should be possible for a project having, as an example,
an 'scaffolding' directory that should be used instead of the
ones located at

Actually, it would be a minimum, since a lot more could be done with
scaffolding, such as creating master-details scaffolding and changing
way to deal with dates (having a lot of selects for handling dates is
practice at all).

But the issue that concerns me more is localization, no doubt! All the
remaining can be done without too much complexity, but I don't see a
way of
solving the localization problem in a good way...

Any thought on that?


PS.: I would be very glad with Rails if I only had to develop English
sites... :frowning:

Just a ruby example that gives an idea of what I'm talking about. It
is too simplified, I know, but I'm worried about the idea:


class Float
  alias old_to_s to_s
  def to_s
        temp = old_to_s.sub(/\./,',')
        (temp2 = temp and temp = temp.sub(/(\d)(\d\d\d)([,
\.].*)/,'\1.\2\3')) while temp!=temp2

puts 255132121123.45

class String
  alias old_to_f to_f
  def to_f

puts '234.534.123,45'.to_f


I'd suggest you to check http://www.globalize-rails.org/globalize/ out

Eu sugiro a vc dar uma olhadinha em http://www.globalize-rails.org/globalize/


Thank you Eider (I'll write in English so other may read too),

But Globalize is meant for international projects, I mean
internationalization + localization, when I just need localization. I don't
need to translate my homepages to multiple languages nor I'll need some

I had some problems running the Globalize plugin altogether with the foreign
key plugin from Redhill once. It is too intrusive and what I need is so
much simpler... I do not want to include the translation to error messages
into the database, for instance... I don't want a gettext based approach
also. I just need the appropriate error messages in Brazilian Portuguese
such as my numbers and currency localized and support for ISO-8859-1, or at
least UTF-8.

Besides that, Globalize uses the following for localization:




where I just wanted something like

Time.now # we should use some default instead of specifying the format



What happens in Globalize if a user sends a float value to the controller
action such as '1.234,56'? Does the conversion need to be handled manually
or Globalize automates that?

I remember that in Perl, which has support to locale(), all this was
automatic. Ruby claims to be a better Perl... it should had copied this
behaviour too!

Thanks for the suggestion, Eider.


Eider Oliveira wrote: