i18n-active_record 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.textile +27 -12
- data/lib/generators/i18n/active_record/install_generator.rb +27 -0
- data/lib/generators/i18n/active_record/templates/advanced_initializer.rb.erb +17 -0
- data/lib/generators/i18n/active_record/templates/migration.rb.erb +17 -0
- data/lib/generators/i18n/active_record/templates/simple_initializer.rb.erb +6 -0
- data/lib/i18n/active_record/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 437efadf4380a5cd99eccb3c468bf25f0aa0343808e89e0dfad9ac676b31743f
|
4
|
+
data.tar.gz: 5080254a77103719b02c55127da824ad505e6d76d0ef7b57a8773a7b08db84ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f5823aa96600903b72bb9a6203a6f6b065482b8cc78bcf97df884758893d69a4d1b9e55fe973830027ebc9e19a72c431410bed38ec0e05c4854a59cca1d17f1
|
7
|
+
data.tar.gz: ea61b155163a0eecd7e2ea10317d761b9add3b3c0ad4ef7ce713a87cfa7abc250ae25d21753c66a12f4db2921c4749d77b20f2fa1e2003ad5e49906b3cd71e9f
|
data/README.textile
CHANGED
@@ -13,8 +13,13 @@ For Bundler put the following in your Gemfile:
|
|
13
13
|
gem 'i18n-active_record', :require => 'i18n/active_record'
|
14
14
|
</pre>
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
After updating your bundle, run the installer
|
17
|
+
|
18
|
+
<pre>
|
19
|
+
rails g i18n:active_record:install
|
20
|
+
</pre>
|
21
|
+
|
22
|
+
It creates a migration:
|
18
23
|
|
19
24
|
<pre>
|
20
25
|
class CreateTranslations < ActiveRecord::Migration
|
@@ -36,19 +41,16 @@ Your migration should look like this:
|
|
36
41
|
end
|
37
42
|
</pre>
|
38
43
|
|
39
|
-
|
40
|
-
it.
|
41
|
-
|
42
|
-
To load @I18n::Backend::ActiveRecord@ into your Rails application, create a new file in *config/initializers* named *locale.rb*.
|
43
|
-
|
44
|
-
A simple configuration for your locale.rb could look like this:
|
44
|
+
To specify table name use:
|
45
45
|
|
46
46
|
<pre>
|
47
|
-
|
48
|
-
I18n.backend = I18n::Backend::ActiveRecord.new
|
47
|
+
rails g i18n:active_record:install MyTranslation
|
49
48
|
</pre>
|
50
49
|
|
51
|
-
|
50
|
+
With the translation model you will be able to manage your translation, and add new translations or languages through
|
51
|
+
it.
|
52
|
+
|
53
|
+
By default the installer creates a new file in *config/initializers* named *i18n_active_record.rb* with the following content.
|
52
54
|
|
53
55
|
<pre>
|
54
56
|
require 'i18n/backend/active_record'
|
@@ -66,6 +68,19 @@ A more advanced example (Thanks Moritz), which uses YAML files and ActiveRecord
|
|
66
68
|
end
|
67
69
|
</pre>
|
68
70
|
|
71
|
+
To perform a simpler installation use:
|
72
|
+
|
73
|
+
<pre>
|
74
|
+
rails g i18n:active_record:install --simple
|
75
|
+
</pre>
|
76
|
+
|
77
|
+
It generates:
|
78
|
+
|
79
|
+
<pre>
|
80
|
+
require 'i18n/backend/active_record'
|
81
|
+
I18n.backend = I18n::Backend::ActiveRecord.new
|
82
|
+
</pre>
|
83
|
+
|
69
84
|
You may also configure whether the ActiveRecord backend should use @destroy@ or @delete@ when cleaning up internally.
|
70
85
|
|
71
86
|
<pre>
|
@@ -91,4 +106,4 @@ h2. Examples
|
|
91
106
|
h2. Maintainers
|
92
107
|
|
93
108
|
* Sven Fuchs
|
94
|
-
* Tim
|
109
|
+
* Tim Masliuchenko
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < ::ActiveRecord::Generators::Base
|
7
|
+
desc "Installs i18n-active_record and generates the necessary migrations"
|
8
|
+
|
9
|
+
argument :name, type: :string, default: 'Translation'
|
10
|
+
|
11
|
+
class_option :simple, type: :boolean, default: false, desc: 'Perform the simple setup'
|
12
|
+
|
13
|
+
source_root File.expand_path('templates', __dir__)
|
14
|
+
|
15
|
+
def copy_initializer
|
16
|
+
tpl = "#{options[:simple] ? 'simple' : 'advanced'}_initializer.rb.erb"
|
17
|
+
|
18
|
+
template tpl, 'config/initializers/i18n_active_record.rb'
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_migrations
|
22
|
+
migration_template 'migration.rb.erb', 'db/migrate/create_translations.rb'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'i18n/backend/active_record'
|
2
|
+
|
3
|
+
Translation = I18n::Backend::ActiveRecord::Translation
|
4
|
+
|
5
|
+
if Translation.table_exists?
|
6
|
+
I18n.backend = I18n::Backend::ActiveRecord.new
|
7
|
+
|
8
|
+
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
|
9
|
+
I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
|
10
|
+
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
|
11
|
+
|
12
|
+
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
|
13
|
+
end
|
14
|
+
|
15
|
+
I18n::Backend::ActiveRecord.configure do |config|
|
16
|
+
# config.cleanup_with_destroy = true # defaults to false
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Create<%= name.classify %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version.to_s %>]
|
2
|
+
def self.up
|
3
|
+
create_table :<%= name.tableize %> do |t|
|
4
|
+
t.string :locale
|
5
|
+
t.string :key
|
6
|
+
t.text :value
|
7
|
+
t.text :interpolations
|
8
|
+
t.boolean :is_proc, :default => false
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :<%= name.tableize %>
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-active_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Fuchs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -48,6 +48,10 @@ files:
|
|
48
48
|
- MIT-LICENSE
|
49
49
|
- README.textile
|
50
50
|
- Rakefile
|
51
|
+
- lib/generators/i18n/active_record/install_generator.rb
|
52
|
+
- lib/generators/i18n/active_record/templates/advanced_initializer.rb.erb
|
53
|
+
- lib/generators/i18n/active_record/templates/migration.rb.erb
|
54
|
+
- lib/generators/i18n/active_record/templates/simple_initializer.rb.erb
|
51
55
|
- lib/i18n/active_record.rb
|
52
56
|
- lib/i18n/active_record/version.rb
|
53
57
|
- lib/i18n/backend/active_record.rb
|
@@ -78,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
82
|
- !ruby/object:Gem::Version
|
79
83
|
version: '0'
|
80
84
|
requirements: []
|
81
|
-
|
82
|
-
rubygems_version: 2.5.2
|
85
|
+
rubygems_version: 3.0.3
|
83
86
|
signing_key:
|
84
87
|
specification_version: 4
|
85
88
|
summary: I18n ActiveRecord backend
|