Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
I18n ActiveRecord backend
Ruby
branch: master

This branch is 14 commits ahead, 7 commits behind svenfuchs:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
ci
lib
test
.gitignore
MIT-LICENSE
README.textile
Rakefile
i18n-active_record-backend.gemspec

README.textile

I18n::Backend::ActiveRecord

This repository contains the I18n ActiveRecord backend and support code that has been extracted from the I18n gem.

Installation

For Bundler put the following in your Gemfile:

  gem 'i18n-active_record',
      :git => 'git://github.com/svenfuchs/i18n-active_record.git',
      :branch => 'rails-3.2',
      :require => 'i18n/active_record'

This gem can generate a migration to create a database table named translations, which will store the localized strings.

  rails g i18n:active_record:install
  rake db:migrate

To load I18n::Backend::ActiveRecord into your Rails application, create a new file in config/initializers named locale.rb.

A simple configuration for your locale.rb could look like this:

  require 'i18n/backend/active_record'
  I18n.backend = I18n::Backend::ActiveRecord.new

A more advanced example (thanks, Moritz), which uses YAML files and ActiveRecord for lookups:

  require 'i18n/backend/active_record'
  I18n.backend = I18n::Backend::ActiveRecord.new

  I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
  I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Flatten)
  I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
  I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)

  I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)

Usage

You can now use I18n.t('Your String') to lookup translations in the database.

Contributing

  bundle install --gemfile=ci/Gemfile.rails-3.2
  rake

Maintainers

Something went wrong with that request. Please try again.