Sha256: 7c7622ff7f67f6d4ab271f9555f6ca7d24fb1e21e91ac2a5a2ede4b9e5dc0206
Contents?: true
Size: 1.58 KB
Versions: 1
Compression:
Stored size: 1.58 KB
Contents
= i18n_column == Introduction This extension provides the capabilities of storing and retrieving translations from a single database column. The translations are stored as a JSON object i.e. {"en":"Home","de":"Zuhause"}. The current and default locale are retrieved from the {Rails Internationalization (I18n) API}[http://guides.rubyonrails.org/i18n.html]. Set the current locale on each request with i.e. <tt>I18n.locale = :de</tt>. If not set the default locale will be taken: <tt>I18n.default_locale</tt>. <tt>I18n.locale</tt> is used as the JSON key to store a translation i.e. <tt>"en":"Home"</tt>. <tt>i18n_column</tt> is tested with rails version 3. == Installation <b>Gem</b> gem install i18n_column <b>Bundler</b> gem('i18n_column') == Example <b>Migration</b> class CreateNodes < ActiveRecord::Migration def self.up create_table(:nodes) do |t| t.text(:name) end end def self.down drop_table(:nodes) end end <b>Model</b> class Node < ActiveRecord::Base i18n_column(:name) end <b>Controller</b> class ApplicationController < ActionController::Base before_filter(:set_locale) private def set_locale I18n.locale = params[:locale] end end <b>Set the default locale in config/application.rb file</b> config.i18n.default_locale = :de <b>Console</b> I18n.locale = :en node = Node.create!(:name => 'Home') => {"en":"Home"} node.name => 'Home' I18n.locale = :de node.name = 'Zuhause' node.save! => {"en":"Home","de":"Zuhause"} node.name => 'Zuhause' == Copyright Copyright (c) 2010 Philipp Ullmann. See LICENSE for details.
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
i18n_column-0.0.2 | README.rdoc |