Sha256: c2480b48c72af2c721c2c2838d56e2eb852e982e5b8a2d035ede76a1e41d793d
Contents?: true
Size: 1.65 KB
Versions: 8
Compression:
Stored size: 1.65 KB
Contents
= mongoid_i18n Mongoid::I18n is a gem that makes localization almost transparent for the developer. == Usage First, include it in your Gemfile. Remeber to add the :require parameter: gem 'mongoid_i18n', :require => 'mongoid/i18n' Now you can add the module to the documents that need localization: class Entry include Mongoid::Document include Mongoid::I18n localized_field :title # Just use localized_field instead of field field :published, :type => Boolean end This will allow you to do stuff like this: I18n.locale = :en @entry = Entry.new(:title => 'Title') # will be stored in the 'en' translation I18n.locale :es @entry.title = 'Título' # will be stored in the 'es' translation @entry.title_translations # this returns a hash: {'en' => 'Title', 'es' => 'Title'} @entry.title_translations = {'en' => 'New title', 'es' => 'Nuevo título} # You can always mass-assign. Criteria is handled for you: I18n.locale = :en Entry.where(:title => 'Title') # This will search automatically for the 'en' translation Entry.find(:first, :title.in => ['Stuff', 'More stuff']) # find() and complex criteria also works == Note on Patches/Pull Requests * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull) * Send me a pull request. Bonus points for topic branches. == Copyright Copyright (c) 2010 Rodrigo Álvarez. See LICENSE for details.
Version data entries
8 entries across 8 versions & 1 rubygems