Skip to content

simi/mongoid-localizer

Repository files navigation

Mongoid::Localizer Build Status

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.

Installation

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

Usage

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"

Preventing I18n.fallbacks

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

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Globalize like behaviour for Mongoid localized models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages