Permalink
Browse files

Update changelog and readme [ci skip]

  • Loading branch information...
1 parent 2d47815 commit 1b99d01f3a67ed3ceca6adb39cc99ae65b47b08b @carlosantoniodasilva committed May 21, 2012
Showing with 34 additions and 1 deletion.
  1. +2 −1 CHANGELOG.md
  2. +32 −0 README.md
View
@@ -1,6 +1,7 @@
## master
-* Add support for localizing methods.
+* Add support for localizing methods
+* Add support for custom parsers ([@caironoleto][https://github.com/caironoleto])
## v0.0.1 - 2012-5-8
View
@@ -109,6 +109,38 @@ end
If the method has a writer method, in this case `total=`, that'd get a parsed version for input values as well.
+### Custom Parsers
+
+If you want to customize the way an attribute is parsed/localized, you can create a custom parser that looks like this:
+
+```ruby
+module MyCustomDateParser
+ include I18n::Alchemy::DateParser
+ extend self
+
+ def localize(value)
+ I18n.localize value, :format => :custom
+ end
+
+ protected
+
+ def i18n_format
+ I18n.t(:custom, :scope => [:date, :formats])
+ end
+end
+```
+
+And then just configure the attribute you want to use with this new parser:
+
+```ruby
+class Product < ActiveRecord::Base
+ include I18n::Alchemy
+ custom_parsers :released_month => MyCustomDateParser
+end
+```
+
+By doing this, **I18n::Alchemy** will be set up to use your custom parser for that particular attribute, which in this case will make use of the `:custom` date format in your i18n locale.
+
## I18n configuration
Right now the lib uses the same configuration for numeric, date and time values from Rails:

0 comments on commit 1b99d01

Please sign in to comment.