README.md in serial_translator-0.0.9 vs README.md in serial_translator-1.0.0
- old
+ new
@@ -1,25 +1,71 @@
# SerialTranslator
-Translate active record object attributes without the use of additional models.
+[![Gem Version](https://badge.fury.io/rb/serial_translator.svg)](http://badge.fury.io/rb/serial_translator)
+[![Build Status](https://travis-ci.org/betterplace/serial_translator.svg)](https://travis-ci.org/betterplace/serial_translator)
+[![Dependency Status](https://gemnasium.com/betterplace/serial_translator.svg)](https://gemnasium.com/betterplace/serial_translator)
-## Build status
+Translate ActiveRecord object attributes without the use of additional models.
-[![Build Status](https://travis-ci.org/betterplace/serial_translator.png)](https://travis-ci.org/betterplace/serial_translator)
-
## Installation
-Add this line to your application's Gemfile:
+Add it to your Gemfile:
gem 'serial_translator'
-And then execute:
+## Usage
- $ bundle
+Add a `*_translations` column to your table, e.g. `title_translations`.
-## Usage
+```ruby
+class AddTitleTranslationsToBlogPosts < ActiveRecord::Migration
+ def change
+ add_column :blog_posts, :title_translations, :text
+ end
+end
+```
-To be written.
+In your model, call `#serial_translator_for`.
+
+```ruby
+class BlogPost < ActiveRecord::Base
+ serial_translator_for :title
+ # [...]
+end
+```
+
+Now you can read and write `title_translations` or `title_#{locale}` or `title(locale)`.
+
+```ruby
+blog_post = BlogPost.new
+blog_post.title_translations = { de: 'Hallo Welt', en: 'Hello world' }
+blog_post.title_en # => "Hello world"
+blog_post.title(:en) # => "Hello world"
+blog_post.translated_locales # => [:de, :en]
+```
+
+Setting or getting the field name without specifying a locale defaults to the current locale.
+
+```ruby
+I18n.locale = :de
+blog_post.title # => "Hallo Welt"
+blog_post.title = 'Hey'
+blog_post.title_translations # => { de: 'Hey', en: 'Hello world' }
+```
+
+So if you add a `title` field to a BlogPost form it will work on the title in the user’s locale by default. You can override this by setting the record’s `#current_translation_locale`.
+
+Add length or presence validations if you want. They will use the same localization keys for error messages as the standard length and presence validations.
+
+```ruby
+class BlogPost < ActiveRecord::Base
+ validates :title, serial_translator_presence: true
+ validates :text, serial_translator_length: { minimum: 100 }
+end
+```
+
+
+
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)