Globalize alike behaviour for Mongoid localized models.
You can switch localized columns locale context without changing I18n.locale
.
Good for administrations, where you want to edit localized documents without changing language for whole page.
Add this line to your application's Gemfile:
gem 'mongoid-localizer', github: 'simi/mongoid-localizer'
And then execute:
$ bundle
Or install it yourself as (not released yet):
$ gem install mongoid-localizer
Mongoid::Localizer.locale # => I18n.locale for default
Mongoid::Localizer.locale = :en
dictionary = Dictionary.create(name: "Otto", description: "English")
Mongoid::Localizer.locale = :de
dictionary.description = "Deutsch"
dictionary.save
Mongoid::Localizer.locale = :en
dictionary.description # => "English"
Mongoid::Localizer.locale = :de
dictionary.description # => "Deutsch"
Mongoid::Localizer.with_locale(:en) do
dictionary.description # => "English"
end
dictionary.description # => "Deutsch"
class Dictionary
include Mongoid::Document
field :name, type: String
field :description, type: String, localize: true
field :slug, type: String, localize: {prevent_fallback: true}
end
Mongoid::Localizer.locale = :en
dictionary = Dictionary.create(name: "Otto", description: "English", slug: "english")
Mongoid::Localizer.locale = :de
dictionary.description => "English"
dictionary.slug => nil
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request