Hi Rodrigo,
I think the proper way to do this is to override those formats in your 
translation yaml files (config/locales). For reference of what the keys are 
take a look at 
http://github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml#L7-9
You'll notice that those I18n keys are used in the number helpers like in 
`number_with_delimiter` here: 
http://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/number_helper.rb#L209

You'll have to create a file like `config/locales/pt-BR.yml` and at the very 
least add those number I18n keys for separator and delimiter.

-Brian

On Jun 25, 2010, at 6:31 AM, Rodrigo Rosenfeld Rosas wrote:

> What is the suggested path for dealing with number formats in Rails?
> 
> Even if we set locale to pt-BR, for instance, if the user inputs a number 
> like '1.000,00' or '1000,00' in a form input, numerical validation will yield 
> an 'invalid_number' error, even though this is a valid format in Brazil.
> 
> I could monkey patch overriding parse_raw_value_as_a_number to replace '.' 
> with '' and ',' with '.' in ActiveModel::Validations::NumericalityValidator 
> but that wouldn't solve the problem because the application is 
> internationalized. So, even if I monkey patch this method, I would have to 
> take into consideration the current user locale before parsing the number...
> 
> Are there any plans for supporting this on Rails 3?
> 
> Rodrigo.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Core" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-core?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to