Module: LocalizableModel

Defined in:
lib/localizable_model.rb,
lib/localizable_model/engine.rb,
lib/localizable_model/version.rb,
lib/localizable_model/localizer.rb,
lib/localizable_model/any_localizer.rb,
lib/localizable_model/class_methods.rb,
lib/localizable_model/configuration.rb,
lib/localizable_model/scope_extension.rb,
lib/localizable_model/instance_methods.rb,
lib/localizable_model/active_record_extension.rb,
lib/rails/generators/localizable_model/migration/migration_generator.rb

Overview

Localizable

Localizable allows any model to have localized attributes.

Configuring the model

class Page < ActiveRecord::Base
  localizable do
    attribute :name
    attribute :body
  end
end

Usage

page = Page.create(name: 'Hello', locale: 'en')
page.name?     # => true
page.name.to_s # => 'Hello'

The localized attributes always return an instance of Localization.

To get a localized version of a page, call .localize on it:

page = Page.first.localize('en')

.localize also takes a block argument:

page.localize('nb') do |p|
  p.locale # => 'nb'
end
page.locale # => 'en'

Multiple locales can be updated at the same time:

page.name = {'en' => 'Hello', 'nb' => 'Hallo'}

Defined Under Namespace

Modules: ActiveRecordExtension, ClassMethods, Generators, InstanceMethods, ScopeExtension Classes: AnyLocalizer, Configuration, Engine, Localizer

Constant Summary collapse

VERSION =
"0.6.4".freeze