This gem tries to internationalize numbers and percentages of ruby on rails application.
Rails provides methods to show numbers and percentages to the user in the correct format depending on the language.
Nevertheless, it doesn't allow to input numbers and percentages in other format rather than ruby format.
To solve this problem, this gem do 4 things:
-
Using a custom version of attribute_normalizer, saves the input of the user as text and transform it to ruby format before validation
-
Adds a validator to verify that the input (as the user specified) is a valid number (using internationalization)
-
If the field is specified as percentage, it adds a before_save call to divide the number by 100. This way you can do math operations with percentage wihtout any complication.
-
Finally, it overrides the number_field use text_field with the value that the user specified before sending the request.
Add this line to your application's Gemfile:
gem 'number_internationalizer', :git => 'git://github.com/bishma-stornelli/number_internationalizer.git'
And then execute:
$ bundle
Or install it yourself as:
$ gem install number_internationalizer
To internationalize numbers or percentages use this method in your model:
internationalize_number :price # For one attribute
internationalize_numbers :price, :value # For many attributes
internationalize_number :progress, :percentage => true # For percentages
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request ======= number_internationalizer ========================