Skip to content

endSly/i18n-active_record-backend

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

I18n ActiveRecord backend

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%