Skip to content

Commit

Permalink
Update readme, todo and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed May 12, 2012
1 parent db94616 commit 3710728
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## master

* Add support for localizing methods.

## v0.0.1 - 2012-5-8

* Basic localization for numeric, date and time attributes
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 0 additions & 14 deletions TODO.rdoc
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 3710728

Please sign in to comment.