i18n-active_record 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aeed8d25f893fefde754e0836bdc6338529b6313a5809d4312fb7fd30087f3a
4
- data.tar.gz: e924f6936a5f956f6c62c095374b76d1c84e504d65bdf07f4463d2659cb7c50d
3
+ metadata.gz: d742b8d5877fc39c8855a29b4cd864732b750f3167567ced3dcd3bf2e9ad3d25
4
+ data.tar.gz: e6f0df2b6ff56a75568c44e11c7e19e6a5e161352308247e12afeb8ffd294522
5
5
  SHA512:
6
- metadata.gz: 100bd6c09aa1307292e2f751d45b601e47837e58d708bf881b9e0ba6d02e1ec1d8911d5fa4c3d4f0d6d9409e5997d90772e23e1fdbf86e0e4ed6b1af48101988
7
- data.tar.gz: 29bd66389ac95bf5afa7f97f89e9676b6bb83be6abaa02876e7577dff6c1a83b7f91fbe70f6166841e5924b403e9449c071338076ef8f3c5d1189bd8f3e9f29a
6
+ metadata.gz: 7fba006f4b5feb3d33cc9917a8c487d11b33e1bdfc64dff8e78e52f909393a0ee86b5a820b674f1b69ad28223459a336dba509fd1cf7f4a9eecbcf922ba4b86c
7
+ data.tar.gz: b8e8a9b39d0d531d0cea78034372f2ac46dedfe1a66269bd9aa72738dcc82544b307222aa603dd1037874a1609f9cb592f7349de4d879aca3c4a4f74f67736d4
data/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # I18n::Backend::ActiveRecord
2
+
3
+ This repository contains the I18n ActiveRecord backend and support code that has been extracted from the "I18n": http://github.com/svenfuchs/i18n.
4
+ It is fully compatible with Rails 3, 4, 5 and 6.
5
+
6
+ ## Installation
7
+
8
+ For Bundler put the following in your Gemfile:
9
+
10
+ ```ruby
11
+ gem 'i18n-active_record', require: 'i18n/active_record'
12
+ ```
13
+
14
+ After updating your bundle, run the installer
15
+
16
+ $ rails g i18n:active_record:install
17
+
18
+ It creates a migration:
19
+
20
+ ```ruby
21
+ class CreateTranslations < ActiveRecord::Migration
22
+ def change
23
+ create_table :translations do |t|
24
+ t.string :locale
25
+ t.string :key
26
+ t.text :value
27
+ t.text :interpolations
28
+ t.boolean :is_proc, default: false
29
+
30
+ t.timestamps
31
+ end
32
+ end
33
+ end
34
+ ```
35
+
36
+ To specify table name use:
37
+
38
+ $ rails g i18n:active_record:install MyTranslation
39
+
40
+ With the translation model you will be able to manage your translation, and add new translations or languages through
41
+ it.
42
+
43
+ By default the installer creates a new file in `config/initializers` named `i18n_active_record.rb` with the following content.
44
+
45
+ ```ruby
46
+ require 'i18n/backend/active_record'
47
+
48
+ Translation = I18n::Backend::ActiveRecord::Translation
49
+
50
+ if Translation.table_exists?
51
+ I18n.backend = I18n::Backend::ActiveRecord.new
52
+
53
+ I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
54
+ I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
55
+ I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
56
+
57
+ I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
58
+ end
59
+ ```
60
+
61
+ To perform a simpler installation use:
62
+
63
+ $ rails g i18n:active_record:install --simple
64
+
65
+ It generates:
66
+
67
+ ```ruby
68
+ require 'i18n/backend/active_record'
69
+ I18n.backend = I18n::Backend::ActiveRecord.new
70
+ ```
71
+
72
+ You may also configure whether the ActiveRecord backend should use `destroy` or `delete` when cleaning up internally.
73
+
74
+ ```ruby
75
+ I18n::Backend::ActiveRecord.configure do |config|
76
+ config.cleanup_with_destroy = true # defaults to false
77
+ end
78
+ ```
79
+
80
+ ## Usage
81
+
82
+ You can now use `I18n.t('Your String')` to lookup translations in the database.
83
+
84
+ ## Missing Translations -> Interpolations
85
+
86
+ The `interpolations` field in the `translations` table is used by `I18n::Backend::ActiveRecord::Missing` to store the interpolations seen the first time this Translation was requested. This will help translators understand what interpolations to expect, and thus to include when providing the translations.
87
+
88
+ The `interpolations` field is otherwise unused since the "value" in `Translation#value` is actually used for interpolation during actual translations.
89
+
90
+ ## Examples
91
+
92
+ * http://collectiveidea.com/blog/archives/2016/05/31/beyond-yml-files-dynamic-translations/
93
+
94
+ ## Maintainers
95
+
96
+ * Sven Fuchs
97
+ * Tim Masliuchenko
data/Rakefile CHANGED
@@ -8,8 +8,9 @@ def execute(command)
8
8
  end
9
9
 
10
10
  def bundle_options
11
- opt = ''
12
- opt += "--gemfile #{ENV['BUNDLE_GEMFILE']}" if ENV['BUNDLE_GEMFILE']
11
+ return '' unless ENV['BUNDLE_GEMFILE']
12
+
13
+ "--gemfile #{ENV['BUNDLE_GEMFILE']}"
13
14
  end
14
15
 
15
16
  def each_database(&block)
@@ -33,8 +34,12 @@ namespace :bundle do
33
34
  execute "bundle install #{bundle_options}"
34
35
  end
35
36
 
37
+ task update: :env do
38
+ execute "bundle update #{bundle_options}"
39
+ end
40
+
36
41
  task :install_all do
37
- [nil, '3', '4', '5', '6', 'master'].each do |ar|
42
+ [nil, '3', '4', '5', '6', 'head'].each do |ar|
38
43
  opt = ar && "AR=#{ar}"
39
44
  execute "rake bundle:install #{opt}"
40
45
  end
@@ -1,17 +1,13 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
- def self.up
3
- create_table :<%= name.tableize %> do |t|
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
4
  t.string :locale
5
5
  t.string :key
6
- t.text :value
7
- t.text :interpolations
8
- t.boolean :is_proc, :default => false
6
+ t.text :value
7
+ t.text :interpolations
8
+ t.boolean :is_proc, default: false
9
9
 
10
10
  t.timestamps
11
11
  end
12
12
  end
13
-
14
- def self.down
15
- drop_table :<%= name.tableize %>
16
- end
17
13
  end
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module ActiveRecord
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.1'
4
4
  end
5
5
  end
data/test/missing_test.rb CHANGED
@@ -51,7 +51,7 @@ class I18nActiveRecordMissingTest < I18n::TestCase
51
51
 
52
52
  test "creates a stub when a custom separator is used" do
53
53
  I18n.t('foo|baz', :separator => '|')
54
- I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz").first.update_attributes(:value => 'baz!')
54
+ I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz").first.update(:value => 'baz!')
55
55
  assert_equal 'baz!', I18n.t('foo|baz', :separator => '|')
56
56
  end
57
57
 
@@ -64,7 +64,7 @@ class I18nActiveRecordMissingTest < I18n::TestCase
64
64
  test "creates a stub when a custom separator is used and the key contains the flatten separator (a dot character)" do
65
65
  key = 'foo|baz.zab'
66
66
  I18n.t(key, :separator => '|')
67
- I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz\001zab").first.update_attributes(:value => 'baz!')
67
+ I18n::Backend::ActiveRecord::Translation.locale(:en).lookup("foo.baz\001zab").first.update(:value => 'baz!')
68
68
  assert_equal 'baz!', I18n.t(key, :separator => '|')
69
69
  end
70
70
  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.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-27 00:00:00.000000000 Z
11
+ date: 2021-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -46,7 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - MIT-LICENSE
49
- - README.textile
49
+ - README.md
50
50
  - Rakefile
51
51
  - lib/generators/i18n/active_record/install_generator.rb
52
52
  - lib/generators/i18n/active_record/templates/advanced_initializer.rb.erb
@@ -67,7 +67,7 @@ homepage: http://github.com/svenfuchs/i18n-active_record
67
67
  licenses:
68
68
  - MIT
69
69
  metadata: {}
70
- post_install_message:
70
+ post_install_message:
71
71
  rdoc_options: []
72
72
  require_paths:
73
73
  - lib
@@ -82,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  requirements: []
85
- rubygems_version: 3.0.3
86
- signing_key:
85
+ rubygems_version: 3.1.4
86
+ signing_key:
87
87
  specification_version: 4
88
88
  summary: I18n ActiveRecord backend
89
89
  test_files: []
data/README.textile DELETED
@@ -1,109 +0,0 @@
1
- h1. I18n::Backend::ActiveRecord
2
-
3
- !https://travis-ci.org/svenfuchs/i18n-active_record.svg?branch=master!:https://travis-ci.org/svenfuchs/i18n-active_record
4
-
5
- This repository contains the I18n ActiveRecord backend and support code that has been extracted from the "I18n":http://github.com/svenfuchs/i18n.
6
- It is fully compatible with Rails 3, 4, 5 and 6.
7
-
8
- h2. Installation
9
-
10
- For Bundler put the following in your Gemfile:
11
-
12
- <pre>
13
- gem 'i18n-active_record', :require => 'i18n/active_record'
14
- </pre>
15
-
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:
23
-
24
- <pre>
25
- class CreateTranslations < ActiveRecord::Migration
26
- def self.up
27
- create_table :translations do |t|
28
- t.string :locale
29
- t.string :key
30
- t.text :value
31
- t.text :interpolations
32
- t.boolean :is_proc, :default => false
33
-
34
- t.timestamps
35
- end
36
- end
37
-
38
- def self.down
39
- drop_table :translations
40
- end
41
- end
42
- </pre>
43
-
44
- To specify table name use:
45
-
46
- <pre>
47
- rails g i18n:active_record:install MyTranslation
48
- </pre>
49
-
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.
54
-
55
- <pre>
56
- require 'i18n/backend/active_record'
57
-
58
- Translation = I18n::Backend::ActiveRecord::Translation
59
-
60
- if Translation.table_exists?
61
- I18n.backend = I18n::Backend::ActiveRecord.new
62
-
63
- I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
64
- I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
65
- I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
66
-
67
- I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)
68
- end
69
- </pre>
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
-
84
- You may also configure whether the ActiveRecord backend should use @destroy@ or @delete@ when cleaning up internally.
85
-
86
- <pre>
87
- I18n::Backend::ActiveRecord.configure do |config|
88
- config.cleanup_with_destroy = true # defaults to false
89
- end
90
- </pre>
91
-
92
- h2. Usage
93
-
94
- You can now use @I18n.t('Your String')@ to lookup translations in the database.
95
-
96
- h2. Missing Translations -> Interpolations
97
-
98
- The interpolations field in the Translations table is used by I18n::Backend::ActiveRecord::Missing to store the interpolations seen the first time this Translation was requested. This will help translators understand what interpolations to expect, and thus to include when providing the translations.
99
-
100
- The interpolations field is otherwise unused since the "value" in Translation.value is actually used for interpolation during actual translations.
101
-
102
- h2. Examples
103
-
104
- * http://collectiveidea.com/blog/archives/2016/05/31/beyond-yml-files-dynamic-translations/
105
-
106
- h2. Maintainers
107
-
108
- * Sven Fuchs
109
- * Tim Masliuchenko