i18n-active_record 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.textile +1 -1
- data/Rakefile +1 -1
- data/lib/generators/i18n/active_record/install_generator.rb +1 -1
- data/lib/generators/i18n/active_record/templates/migration.rb.erb +1 -1
- data/lib/i18n/active_record/version.rb +1 -1
- data/lib/i18n/backend/active_record.rb +18 -0
- data/lib/i18n/backend/active_record/translation.rb +12 -0
- data/test/active_record_test.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7aeed8d25f893fefde754e0836bdc6338529b6313a5809d4312fb7fd30087f3a
|
|
4
|
+
data.tar.gz: e924f6936a5f956f6c62c095374b76d1c84e504d65bdf07f4463d2659cb7c50d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 100bd6c09aa1307292e2f751d45b601e47837e58d708bf881b9e0ba6d02e1ec1d8911d5fa4c3d4f0d6d9409e5997d90772e23e1fdbf86e0e4ed6b1af48101988
|
|
7
|
+
data.tar.gz: 29bd66389ac95bf5afa7f97f89e9676b6bb83be6abaa02876e7577dff6c1a83b7f91fbe70f6166841e5924b403e9449c071338076ef8f3c5d1189bd8f3e9f29a
|
data/README.textile
CHANGED
|
@@ -3,7 +3,7 @@ h1. I18n::Backend::ActiveRecord
|
|
|
3
3
|
!https://travis-ci.org/svenfuchs/i18n-active_record.svg?branch=master!:https://travis-ci.org/svenfuchs/i18n-active_record
|
|
4
4
|
|
|
5
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 and
|
|
6
|
+
It is fully compatible with Rails 3, 4, 5 and 6.
|
|
7
7
|
|
|
8
8
|
h2. Installation
|
|
9
9
|
|
data/Rakefile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
|
2
2
|
def self.up
|
|
3
3
|
create_table :<%= name.tableize %> do |t|
|
|
4
4
|
t.string :locale
|
|
@@ -45,6 +45,24 @@ module I18n
|
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
def reload!
|
|
49
|
+
@translations = nil
|
|
50
|
+
self
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def initialized?
|
|
54
|
+
!@translations.nil?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def init_translations
|
|
58
|
+
@translations = Translation.to_hash
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def translations(do_init: false)
|
|
62
|
+
init_translations if do_init || !initialized?
|
|
63
|
+
@translations ||= {}
|
|
64
|
+
end
|
|
65
|
+
|
|
48
66
|
protected
|
|
49
67
|
|
|
50
68
|
def lookup(locale, key, scope = [], options = {})
|
|
@@ -75,6 +75,18 @@ module I18n
|
|
|
75
75
|
def available_locales
|
|
76
76
|
Translation.select('DISTINCT locale').to_a.map { |t| t.locale.to_sym }
|
|
77
77
|
end
|
|
78
|
+
|
|
79
|
+
def to_hash
|
|
80
|
+
Translation.all.each.with_object({}) do |t, memo|
|
|
81
|
+
locale_hash = (memo[t.locale.to_sym] ||= {})
|
|
82
|
+
keys = t.key.split('.')
|
|
83
|
+
keys.each.with_index.inject(locale_hash) do |iterator, (key_part, index)|
|
|
84
|
+
key = key_part.to_sym
|
|
85
|
+
iterator[key] = keys[index + 1] ? (iterator[key] || {}) : t.value
|
|
86
|
+
iterator[key]
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
78
90
|
end
|
|
79
91
|
|
|
80
92
|
def interpolates?(key)
|
data/test/active_record_test.rb
CHANGED
|
@@ -109,4 +109,28 @@ class I18nBackendActiveRecordTest < I18n::TestCase
|
|
|
109
109
|
|
|
110
110
|
assert_equal "translation missing: en.no key", I18n.t('.')
|
|
111
111
|
end
|
|
112
|
+
|
|
113
|
+
test "intially unitinitialized" do
|
|
114
|
+
refute I18n.backend.initialized?
|
|
115
|
+
I18n.backend.init_translations
|
|
116
|
+
assert I18n.backend.initialized?
|
|
117
|
+
I18n.backend.reload!
|
|
118
|
+
refute I18n.backend.initialized?
|
|
119
|
+
I18n.backend.init_translations
|
|
120
|
+
assert I18n.backend.initialized?
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
test "translations returns all translations" do
|
|
124
|
+
expected_hash = { :en => { :foo => { :bar => 'bar', :baz => 'baz' } } }
|
|
125
|
+
I18n.backend.init_translations
|
|
126
|
+
assert_equal expected_hash, I18n.backend.send(:translations)
|
|
127
|
+
assert I18n.backend.initialized?
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
test "translations initialized with do_init argument" do
|
|
131
|
+
expected_hash = { :en => { :foo => { :bar => 'bar', :baz => 'baz' } } }
|
|
132
|
+
refute I18n.backend.initialized?
|
|
133
|
+
assert_equal expected_hash, I18n.backend.send(:translations, { do_init: true })
|
|
134
|
+
assert I18n.backend.initialized?
|
|
135
|
+
end
|
|
112
136
|
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.4.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: 2020-02-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: i18n
|