No commit activity in last 3 years
No release in over 3 years
I18n ActiveRecord backend. Allows to store translations in a database using ActiveRecord, e.g. for providing a web-interface for managing translations.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0.6.0
 Project Readme

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