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 Rails (or whatever other country with localization rules different from English). I mean, how can I validate a number from user's input such as 1.234,45 and 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... But, 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, it wouldn't be necessary... That said, IMHO, as Rails claims to follow the 80/20 rule, it should really consider a good suport for basic things like this kind of basic localization, such as numbers, currency and other charsets, or at least, 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 the world will not be satisfied with Rails for serious applications, unless they need to write only English sites... More than 50% of the sites in the world are monolanguage in a language other than English. So, it should be considered in Ruby/Rails to give a better support for these applications, for continue claiming their solution is 80/20... Maybe, the better approach would be embedding this support directly in the 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 for internationalization, which is not a requirement for most of these "other 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 this should be embedded directly on Rails with language directories containing 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 default ones located at rails/lib/rails_generator/generators/components/scaffold/templates Actually, it would be a minimum, since a lot more could be done with scaffolding, such as creating master-details scaffolding and changing the way to deal with dates (having a lot of selects for handling dates is not 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? Rodrigo. PS.: I would be very glad with Rails if I only had to develop English sites... :(
on 2007-06-20 21:03
on 2007-06-20 21:44
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: #!/usr/bin/ruby 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 temp end end puts 255132121123.45 class String alias old_to_f to_f def to_f gsub(/\./,'').gsub(/,/,'.').old_to_f end end puts '234.534.123,45'.to_f #>255.132.121.123,45 #>234.534.123,45
on 2007-06-21 05:37
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/ s On 6/20/07, firstname.lastname@example.org <email@example.com> wrote: > I mean, how can I validate a number from user's input such as 1.234,45 > converted to 1234.45, but I'm not that familiar with Ruby already... > > localization, such as numbers, currency and other charsets, or at > other > I've looked at Globalize, GLoc and some other plugins. These two are > containing > Actually, it would be a minimum, since a lot more could be done with > > Any thought on that? > > Rodrigo. > > PS.: I would be very glad with Rails if I only had to develop English > sites... :( > > > > > -- Eider Oliveira Site: http://eider.eti.br Blog: http://web.mac.com/eider.oliveira/iWeb/Home/Blog/Blog.html
on 2007-06-21 16:29
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 day... 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: Time.now.loc(XXX) and number.loc where I just wanted something like Time.now # we should use some default instead of specifying the format always... and number 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. Rodrigo.