i18n-active_record 1.1.0 → 1.2.0

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: 934e01acf036e3a1c8eb23f5f8f96c55e84d462a31a10183c12389e8466e233d
4
- data.tar.gz: a0c8301e9e0c5eaac6badf2dfdeca19b581296eaa0e0a15464a13fbc6796087f
3
+ metadata.gz: 696d09fb79116c47ec3924b359f31ba4c632d68a075d6da1af591dcb0412548f
4
+ data.tar.gz: eff1a17efd57a2f09546e80aa0d1269b07751f8615b65377c891d89186407d45
5
5
  SHA512:
6
- metadata.gz: 0702e26d0b3a600ff2d28db7473e9a34311f18a099a0009ec6bccec5382d5c4bcc9042b33653a214c377c332db0d902adb64103e05a98c1371d6d19ccb3c0297
7
- data.tar.gz: f2dd449433f4b88763c5952831feff25956c727aa4ff086c2ae130709bfd968ef36f61bf7b2af9065681ac7132e7e7c3a05c13b268e5c1c3e282285cd1787c6b
6
+ metadata.gz: 8dc72a6d40f4ce0da1d98f5ade7bc26f660766aa72814771f359b9c6c8e943a4c51acfce8f612794cd3ede72c3ad9808e9442524c951fded1c2ec2457be0201f
7
+ data.tar.gz: cc0fcb1c5121cefa325f52c4edbae8308a095d896cd6a8e3917d5c0144c1460f4f7795a4de6be9f25f399e678b4ce9fa2e95472e0cd651ee08aeead47e30ab03
data/README.md CHANGED
@@ -115,7 +115,7 @@ The `interpolations` field is otherwise unused since the "value" in `Translation
115
115
 
116
116
  ## Examples
117
117
 
118
- * http://collectiveidea.com/blog/archives/2016/05/31/beyond-yml-files-dynamic-translations/
118
+ * http://collectiveidea.com/blog/archives/2016/05/31/beyond-yml-files-dynamic-translations/ ([use `before_action`](https://github.com/svenfuchs/i18n-active_record/issues/138) for Rails 5.1+)
119
119
 
120
120
  ## Contributing
121
121
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module ActiveRecord
5
- VERSION = '1.1.0'
5
+ VERSION = '1.2.0'
6
6
  end
7
7
  end
@@ -53,8 +53,14 @@ module I18n
53
53
 
54
54
  self.table_name = 'translations'
55
55
 
56
- serialize :value
57
- serialize :interpolations, Array
56
+ if ::ActiveRecord.version >= Gem::Version.new('7.1.0.alpha')
57
+ serialize :value, coder: YAML
58
+ serialize :interpolations, coder: YAML, type: Array
59
+ else
60
+ serialize :value
61
+ serialize :interpolations, Array
62
+ end
63
+
58
64
  after_commit :invalidate_translations_cache
59
65
 
60
66
  class << self
@@ -79,7 +85,7 @@ module I18n
79
85
  Translation.select('DISTINCT locale').to_a.map { |t| t.locale.to_sym }
80
86
  end
81
87
 
82
- def to_hash
88
+ def to_h
83
89
  Translation.all.each.with_object({}) do |t, memo|
84
90
  locale_hash = (memo[t.locale.to_sym] ||= {})
85
91
  keys = t.key.split('.')
@@ -64,7 +64,7 @@ module I18n
64
64
  end
65
65
 
66
66
  def init_translations
67
- @translations = Translation.to_hash
67
+ @translations = Translation.to_h
68
68
  end
69
69
 
70
70
  def translations(do_init: false)
@@ -123,7 +123,7 @@ class I18nBackendActiveRecordTest < I18n::TestCase
123
123
  I18n.t('.') # Fixes test flakiness by loading available locales
124
124
  I18n::Backend::ActiveRecord::Translation.destroy_all
125
125
 
126
- assert_equal 'translation missing: en.no key', I18n.t('.')
126
+ assert_match(/[Tt]ranslation missing: en\.no key/, I18n.t('.'))
127
127
  end
128
128
 
129
129
  test 'intially unitinitialized' do
data/test/test_helper.rb CHANGED
@@ -10,35 +10,35 @@ require 'i18n/tests'
10
10
 
11
11
  begin
12
12
  require 'active_record'
13
- ::ActiveRecord::Base.connection
13
+ ActiveRecord::Base.connection
14
14
  rescue LoadError => e
15
15
  puts "can't use ActiveRecord backend because: #{e.message}"
16
- rescue ::ActiveRecord::ConnectionNotEstablished
16
+ rescue ActiveRecord::ConnectionNotEstablished
17
17
  require 'i18n/backend/active_record'
18
18
 
19
- case ENV['DB']
19
+ case ENV.fetch('DB', nil)
20
20
  when 'postgres'
21
- ::ActiveRecord::Base.establish_connection(
21
+ ActiveRecord::Base.establish_connection(
22
22
  adapter: 'postgresql',
23
23
  database: 'i18n_unittest',
24
- username: ENV['PG_USER'] || 'postgres',
25
- password: ENV['PG_PASSWORD'] || 'postgres',
24
+ username: ENV.fetch('PG_USER', 'postgres'),
25
+ password: ENV.fetch('PG_PASSWORD', 'postgres'),
26
26
  host: 'localhost'
27
27
  )
28
28
  when 'mysql'
29
- ::ActiveRecord::Base.establish_connection(
29
+ ActiveRecord::Base.establish_connection(
30
30
  adapter: 'mysql2',
31
31
  database: 'i18n_unittest',
32
- username: ENV['MYSQL_USER'] || 'root',
33
- password: ENV['MYSQL_PASSWORD'] || '',
32
+ username: ENV.fetch('MYSQL_USER', 'root'),
33
+ password: ENV.fetch('MYSQL_PASSWORD', ''),
34
34
  host: '127.0.0.1'
35
35
  )
36
36
  else
37
- ::ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
37
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
38
38
  end
39
39
 
40
- ::ActiveRecord::Migration.verbose = false
41
- ::ActiveRecord::Schema.define(version: 1) do
40
+ ActiveRecord::Migration.verbose = false
41
+ ActiveRecord::Schema.define(version: 1) do
42
42
  create_table :translations, force: true do |t|
43
43
  t.string :locale
44
44
  t.string :key
@@ -48,6 +48,12 @@ rescue ::ActiveRecord::ConnectionNotEstablished
48
48
  end
49
49
  add_index :translations, %i[locale key], unique: true
50
50
  end
51
+
52
+ if ActiveRecord::Base.respond_to?(:yaml_column_permitted_classes=)
53
+ ActiveRecord::Base.yaml_column_permitted_classes = [Symbol]
54
+ elsif ActiveRecord.respond_to?(:yaml_column_permitted_classes=)
55
+ ActiveRecord.yaml_column_permitted_classes = [Symbol]
56
+ end
51
57
  end
52
58
 
53
59
  TEST_CASE = defined?(Minitest::Test) ? Minitest::Test : MiniTest::Unit::TestCase
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: 1.1.0
4
+ version: 1.2.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: 2021-12-01 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -150,7 +150,8 @@ files:
150
150
  homepage: http://github.com/svenfuchs/i18n-active_record
151
151
  licenses:
152
152
  - MIT
153
- metadata: {}
153
+ metadata:
154
+ rubygems_mfa_required: 'true'
154
155
  post_install_message:
155
156
  rdoc_options: []
156
157
  require_paths:
@@ -166,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
167
  - !ruby/object:Gem::Version
167
168
  version: '0'
168
169
  requirements: []
169
- rubygems_version: 3.2.29
170
+ rubygems_version: 3.4.10
170
171
  signing_key:
171
172
  specification_version: 4
172
173
  summary: I18n ActiveRecord backend