Permalink
Browse files

Update readme, todo and changelog

  • Loading branch information...
1 parent db94616 commit 371072893c677720fa1c4b5923fba8e687b40989 @carlosantoniodasilva committed May 12, 2012
Showing with 28 additions and 14 deletions.
  1. +4 −0 CHANGELOG.md
  2. +24 −0 README.md
  3. +0 −14 TODO.rdoc
View
@@ -1,3 +1,7 @@
+## master
+
+* Add support for localizing methods.
+
## v0.0.1 - 2012-5-8
* Basic localization for numeric, date and time attributes
View
@@ -85,6 +85,30 @@ I18n.with_locale :pt do
end
```
+### Localizing methods
+
+Given a product model with a `total` method, that is a simple calculation of `quantity * price`, you can tell **I18n::Alchemy** to localize that method for you together with the attributes:
+
+```ruby
+class Product < ActiveRecord::Base
+ include I18n::Alchemy
+ localize :total => :number
+
+ def total
+ quantity * price
+ end
+end
+
+@product = Product.first
+@product.price = 1.99
+@product.quantity = 10
+
+@product.total # => 19.90
+@localized.total # => "19,90"
+```
+
+If the method has a writer method, in this case `total=`, that'd get a parsed version for input values as well.
+
## I18n configuration
Right now the lib uses the same configuration for numeric, date and time values from Rails:
View
@@ -1,19 +1,5 @@
== I18n Alchemy TODO
-* Allow localization of methods (not db columns)
- Possible APIs:
- # All attributes localized by default
- localize_methods :total => :number
-
- # OR
-
- localize :attributes => { :price => :numeric, :created_at => :datetime },
- :methods => { :total => :number }
- localize :attributes => [:price, :created_at], :methods => { :total => :number }
- localize :attributes => :all, :methods => { :total => :number }
- localize :methods => { :total => :number } # :attributes => :all by default?
- localize :total => :number # :methods => {} by default?
-
* Add currency parser/localization on top of numeric?
* Localization for non AR classes (do not depend on AR::Base.columns)
* Improve type check for date/time parsers

0 comments on commit 3710728

Please sign in to comment.