@@ -2,5 +2,69 @@ h1. I18n::Backend::ActiveRecord
22
33This repository contains the I18n ActiveRecord backend and support code that has been extracted from the "I18n":https://github.com/svenfuchs/i18n.
44
5- If you are interested in maintaining this repository, please drop me a note!
5+ h2. Installation
6+
7+ For Bundler put the following in your Gemfile:
8+
9+ <pre>
10+ gem 'i18n-active_record',
11+ :git => 'git://github.com/svenfuchs/i18n-active_record.git',
12+ :require => 'i18n/active_record'
13+ </pre>
14+
15+ Next create a active record model named @Translation@ with the Rails Generator.
16+ Your migration should look like this:
17+
18+ <pre>
19+ class CreateTranslations < ActiveRecord::Migration
20+ def self.up
21+ create_table :translations do |t|
22+ t.string :locale
23+ t.string :key
24+ t.text :value
25+ t.text :interpolations
26+ t.boolean :is_proc, :default => false
27+
28+ t.timestamps
29+ end
30+ end
31+
32+ def self.down
33+ drop_table :translations
34+ end
35+ end
36+ </pre>
37+
38+ With this translation model you will be able to manage your translation, and add new translations or languages through
39+ it.
40+
41+ To load @I18n::Backend::ActiveRecord@ into your Rails application, create a new file in *config/initializers* named *locale.rb*.
42+
43+ A simple configuration for your locale.rb could look like this:
44+
45+ <pre>
46+ I18n.backend = I18n::Backend::Database.new
47+ </pre>
48+
49+ A more adavanced example (Thanks Moritz), which uses YAML files and ActiveRecord for lookups:
50+
51+ <pre>
52+ I18n.backend = I18n::Backend::ActiveRecord.new
53+
54+ I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
55+ I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Flatten)
56+ I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
57+ I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
58+
59+ I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
60+ </pre>
61+
62+ h2. Usage
63+
64+ You can now use @I18n.t('Your String')@ to lookup translations in the database.
65+
66+ h2. Maintainers
67+
68+ * Sven Fuchs
69+
670
0 commit comments