This project is archived and is in readonly mode.
Rails-3.0.3 - I18n.t does not treat 'number' as a string
-
James B. Byrne
Important condition:
This error only occurs if there is no entry in the translation file. If 'number' is not a key in config/locales/default/en.yml then the error is raised. If it is a key in the tranlation file then the error does not happen.
In other words, instead of a 'translation missing: en.number' string displayed in the view the error is raised.
-
Vijay Dev
A quick check showed that I18n.t("number") returns a Hash. So strip is obviously going to fail.
{:precision=>{:format=>{:delimiter=>""}}, :percentage=>{:format=>{:delimiter=>""}}, :format=>{:precision=>3, :delimiter=>",", :strip_insignificant_zeros=>false, :significant=>false, :separator=>"."}, :currency=>{:format=>{:precision=>2, :delimiter=>",", :format=>"%u%n", :strip_insignificant_zeros=>false, :significant=>false, :separator=>".", :unit=>"$"}}, :human=>{:decimal_units=>{:format=>"%n %u", :units=>{:thousand=>"Thousand", :trillion=>"Trillion", :quadrillion=>"Quadrillion", :billion=>"Billion", :million=>"Million", :unit=>""}}, :format=>{:precision=>3, :delimiter=>"", :strip_insignificant_zeros=>true, :significant=>true}, :storage_units=>{:format=>"%n %u", :units=>{:kb=>"KB", :tb=>"TB", :byte=>{:one=>"Byte", :other=>"Bytes"}, :gb=>"GB", :mb=>"MB"}}}}May be "number" is a reserved word in I18n. Need to see if this is documented.
Edited by Rohit Arondekar for formatting.
-
Vijay Dev
Sorry about the bad formatting in the first line above. Please ignore the @'s.
-
Rohit Arondekar
- Importance changed from to Low
You are basically loading this hash: https://github.com/rails/rails/blob/master/actionpack/lib/action_vi...
Here is a use case:
I18n.t('number.currency.format.unit') => "$"Have you defined a locale file which has
number:? Could you please make a gist of that file and post the link here? -
José Valim
- State changed from new to invalid
This is because Rails adds the number key to your locale files. They contain how the number helpers should be behave. Overwriting it is not recommended and it is correct that it returns a hash.
-
James B. Byrne
Am I to understand then that if one uses BDD and develops a view requiring use of the string 'number' without previously providing a translation for it then the above failure is intentional and that it deliberately does not provide a translation missing notice?
Are there any other 'magic' keys using ordinary English words being added invisibly to locale files and likely to produce similar results?
Is there a reason that the common English word 'number' was chosen for this purpose and not some arbitrary string like rails_number_helper_code that might prove less likely to result in a collision?