Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Mongoid add-on to deal with localizable fields
Branch: master
Pull request Compare This branch is 41 commits behind Papipo:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib/mongoid
spec
.document
.gitignore
.rvmrc
Gemfile
Gemfile.lock
LICENSE
README.rdoc
Rakefile
VERSION
mongoid_i18n.gemspec

README.rdoc

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 © 2010 Rodrigo Álvarez. See LICENSE for details.

Something went wrong with that request. Please try again.