Skip to content

Commit 15c89db

Browse files
author
Sven Fuchs
committed
Merge branch 'master' of github.com:svenfuchs/i18n-active_record
2 parents 2c7f583 + 11c22d2 commit 15c89db

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

README.textile

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,69 @@ h1. I18n::Backend::ActiveRecord
22

33
This 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

i18n-active_record.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# encoding: utf-8
22

33
$:.unshift File.expand_path('../lib', __FILE__)
4-
require 'i18n_active_record/version'
4+
require 'i18n/active_record/version'
55

66
Gem::Specification.new do |s|
77
s.name = "i18n-active_record"

0 commit comments

Comments
 (0)