On Fri, Jun 25, 2010 at 17:38, Rodrigo Rosenfeld Rosas
<[email protected]> wrote:
>> No other options occur to me; I would implement it similarly to the
>> other top-level methods in i18n. Maybe something like:
>>
>> def to_f(object, options = {})
>> return object.to_f unless locale.separator&& locale.delimiter
>> locale = options.delete(:locale) || config.locale
>> object.to_s.gsub(locale.separator_char,
>> '').gsub(locale.delimiter_char, '.').to_f
>> end
>>
>
> Actually, the order does not seem to be right. Maybe you mean:
>
> def to_f(object, options = {})
> locale = options.delete(:locale) || config.locale
> return object.to_f unless locale.separator&& locale.delimiter
> ...
> end
>
Right... so much for email driven development. :)
>> Thinking about it some more though, the problem is, "delimiter" and
>> "separator" are not defined by default, I'm assuming because the i18n
>> library doesn't want to hard-code any assumptions about what goes into
>> the localization files. So I'm not 100% sure this should actually go
>> into i18n, it may be best added somewhere in Rails. I definitely think
>> this is a problem that should be solved, but giving it some more
>> thought, I'm not sure this is the right way to do it.
>>
>
> I warned you it was a pseudo-code. delimiter_char and separator_char are not
> defined in I18n but it made my example clearer. Actual code would be
> something like:
>
> def I18n.delimiter_char
> t('number.format.delimiter', :default => nil)
> end
Sure... the thing is, we're still depending on the locale
implementation putting the delimiter in a certain place.... which
might be fine but would need to be chosen carefully and documented.
Perhaps it would be best to take the discussion to the i18n list.
--
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.