Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update changelog and readme [ci skip]

  • Loading branch information...
commit 1b99d01f3a67ed3ceca6adb39cc99ae65b47b08b 1 parent 2d47815
@carlosantoniodasilva authored
Showing with 34 additions and 1 deletion.
  1. +2 −1  CHANGELOG.md
  2. +32 −0 README.md
View
3  CHANGELOG.md
@@ -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
32 README.md
@@ -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:
Please sign in to comment.
Something went wrong with that request. Please try again.