embedded_localization 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +25 -15
- data/CHANGELOG.md +50 -0
- data/Gemfile +2 -2
- data/README.md +156 -181
- data/Rakefile +1 -1
- data/embedded_localization.gemspec +23 -21
- data/lib/embedded_localization/active_record/act_macro.rb +3 -3
- data/lib/embedded_localization/version.rb +1 -1
- data/lib/extensions/hash.rb +1 -1
- data/spec/spec_helper.rb +0 -4
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c558dc3ee3d3357b8bf674ee00423dda8dd10c855deb800b1b4e47946fa1318f
|
4
|
+
data.tar.gz: 252b5481dbc39a41e800551411a1426db9f4fea1759c2c6a7b05e9e6285a1a24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8a28976e403460d65d6fd9c5af50b224ffa46a9d7b466c7bfec4e4766aa762c2c65e5bb54fdb2b0dd7b7c2a4f6d91759889b067e370af9161a869e7ad7b1804
|
7
|
+
data.tar.gz: f7353af27a41afcc4db023bcff8b229f90e062bb8388c84bf4991de528f3021c5e1d00116ea91d8728ff1ffc59f22c648326379d1501e5749f2c3c999992a3df
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,22 +1,32 @@
|
|
1
1
|
language: ruby
|
2
2
|
bundler_args: --without development
|
3
|
-
|
4
|
-
-
|
5
|
-
-
|
6
|
-
|
7
|
-
- 2.4.2
|
8
|
-
- ruby-head
|
9
|
-
- jruby-head
|
10
|
-
- rbx
|
11
|
-
- ree
|
12
|
-
env: JRUBY_OPTS="--server -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -J-Xms512m -J-Xmx1024m"
|
3
|
+
before_install:
|
4
|
+
- gem install bundler
|
5
|
+
- gem update --system
|
6
|
+
|
13
7
|
matrix:
|
14
|
-
|
15
|
-
-
|
8
|
+
include:
|
9
|
+
- rvm: 2.2.10
|
10
|
+
- rvm: 2.3.8
|
11
|
+
- rvm: 2.4.10
|
12
|
+
- rvm: 2.5.8
|
13
|
+
- rvm: 2.6.9
|
14
|
+
- rvm: 2.7.5
|
15
|
+
- rvm: 3.0.3
|
16
|
+
- rvm: 3.1.0
|
17
|
+
- rvm: 3.2.0
|
18
|
+
- rvm: 3.3.0
|
19
|
+
- rvm: jruby-9.2.19.0
|
20
|
+
- rvm: jruby-9.3.3.0
|
21
|
+
- jruby-head
|
22
|
+
- mruby
|
23
|
+
- rubinius
|
24
|
+
- ree
|
25
|
+
|
26
|
+
env:
|
27
|
+
- JRUBY_OPTS="--server -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -J-Xms512m -J-Xmx1024m"
|
16
28
|
- rvm: ruby-head
|
17
|
-
|
18
|
-
- rvm: ree
|
19
|
-
- rvm: jruby-19mode
|
29
|
+
|
20
30
|
branches:
|
21
31
|
only:
|
22
32
|
- master
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# EmbeddedLocalization CHANGE LOG
|
2
|
+
|
3
|
+
## 1.3.0 (2024-11-13)
|
4
|
+
- fixed ([issue 10](https://github.com/tilo/embedded_localization/issues)) to support Rails >= 7.1 (thanks to [Romain Morlevat](https://github.com/RomainMorlevat))
|
5
|
+
|
6
|
+
## 1.2.2 (2022-04-25)
|
7
|
+
* improved docs
|
8
|
+
|
9
|
+
## 1.2.0 (2017-11-10)
|
10
|
+
* Rails 5 compatibility
|
11
|
+
* fixing tests
|
12
|
+
* updating doc
|
13
|
+
|
14
|
+
## 1.1.1 (2014-11-02)
|
15
|
+
* minor update
|
16
|
+
|
17
|
+
## 1.1.0 (2014-01-12)
|
18
|
+
* adding more rspec tests.
|
19
|
+
* improving documentation and README
|
20
|
+
|
21
|
+
## 1.0.0 (2014-01-11)
|
22
|
+
* adding rspec tests.
|
23
|
+
* fixing issue #6: translated fields for new records were not nil
|
24
|
+
* fixing issue #7: translation_missing for new records is breaking
|
25
|
+
|
26
|
+
|
27
|
+
## 0.2.5 (2013-11-02)
|
28
|
+
* adding MIT and GPL-2 licenses to gem-spec file; contact me if you need another license
|
29
|
+
|
30
|
+
## 0.2.4 (2012-03-02)
|
31
|
+
* Issue #5 : bugfix for attr_writer
|
32
|
+
|
33
|
+
## 0.2.3 (2012-03-02)
|
34
|
+
* Issue #4 : bugfix for attr_writer - no longer updates attributes if value didn't change => timestamps don't change in that case
|
35
|
+
|
36
|
+
## 0.2.2 (2012-02-06)
|
37
|
+
* bugfix for attr_writer
|
38
|
+
|
39
|
+
## 0.2.1 (2012-01-31)
|
40
|
+
* bugfix for serialized i18n attribute
|
41
|
+
|
42
|
+
## 0.2.0 (2012-01-31)
|
43
|
+
* added support for having DB columns for translated attributes, to enable SQL queries in `I18n.default_locale`
|
44
|
+
|
45
|
+
## 0.1.4 (2012-01-31)
|
46
|
+
* fixed bug with dirty tracking of serialized i18n attribute
|
47
|
+
* renamed #fallback? to #fallbacks?
|
48
|
+
|
49
|
+
## 0.1.3 Initial Version (2012-01-27)
|
50
|
+
* initial version
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/tilo/embedded_localization.png?branch=master)](http://travis-ci.org/tilo/embedded_localization) [![Gem Version](https://badge.fury.io/rb/embedded_localization.svg)](http://badge.fury.io/rb/embedded_localization)
|
4
4
|
|
5
|
-
`embedded_localization` is compatible with Rails
|
5
|
+
`embedded_localization` is compatible with Rails 6.x, 7.x, and adds model translations to ActiveRecord. `embedded_localization` is compatible with and builds on the new [I18n API in Ruby on Rails](http://guides.rubyonrails.org/i18n.html)
|
6
6
|
|
7
7
|
`embedded_localization` is very lightweight, and allows you to transparently store translations of attributes right inside each record — no extra database tables needed to store the localization data! Make sure that your database default encoding is UTF-8 or UFT-16.
|
8
8
|
|
@@ -11,10 +11,21 @@ Model translations with `embedded_localization` use default ActiveRecord feature
|
|
11
11
|
On top of that, you also get tools for checking into which locales an attribute was translated to, as well as for checking overall translation coverage.
|
12
12
|
|
13
13
|
|
14
|
+
## Motivation
|
15
|
+
|
16
|
+
One real-life scenario is that you have a SaaS system which needs custom text for each company, which also needs to be translated in to several languages. Another scenario is that you have dynamic content that needs to be translated.
|
17
|
+
|
18
|
+
A recent project needed some localization support for ActiveRecord model data, but I did not want to clutter the schema with one additional table for each translated model, as the globalize gem requires. A second requirement was to allow SQL queries of the fields using the default locale.
|
19
|
+
|
20
|
+
The advantage of EmbeddedLocalization is that it does not need extra tables, and therefore no joins or additional table lookups to get to the translated data.
|
21
|
+
|
22
|
+
If your requirements are different, this approach might not work for you. In that case, I recommend to look at the alternative solutions listed at the bottom of this page.
|
23
|
+
|
24
|
+
|
14
25
|
## Requirements
|
15
26
|
|
16
|
-
* ActiveRecord
|
17
|
-
* I18n
|
27
|
+
* ActiveRecord >= 6
|
28
|
+
* [I18n](http://guides.rubyonrails.org/i18n.html)
|
18
29
|
|
19
30
|
## Installation
|
20
31
|
|
@@ -35,21 +46,25 @@ Model translations allow you to translate your models’ attribute values. The a
|
|
35
46
|
|
36
47
|
Let's assume you have a table for movie genres, and you want to translate the names and the descriptions of the genres. Simply define your `Genre` model as follows:
|
37
48
|
|
38
|
-
|
39
|
-
|
40
|
-
|
49
|
+
```ruby
|
50
|
+
class Genre < ActiveRecord::Base
|
51
|
+
translates :name, :description
|
52
|
+
end
|
53
|
+
```
|
41
54
|
|
42
55
|
In the DB migration, you just need to add the `i18n` text field:
|
43
56
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
57
|
+
```ruby
|
58
|
+
class CreateGenres < ActiveRecord::Migration
|
59
|
+
def self.change
|
60
|
+
create_table :genres do |t|
|
61
|
+
t.text :i18n # stores ALL the translated attributes; persisted as a Hash
|
48
62
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
63
|
+
t.timestamps
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
```
|
53
68
|
|
54
69
|
### Example 2
|
55
70
|
|
@@ -60,17 +75,19 @@ This way you can always do SQL queries against the values in the `I18n.default_l
|
|
60
75
|
|
61
76
|
To do this, using the same model as in example 1, you can modify your migration as follows:
|
62
77
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
78
|
+
```ruby
|
79
|
+
class CreateGenres < ActiveRecord::Migration
|
80
|
+
def self.change
|
81
|
+
create_table :genres do |t|
|
82
|
+
t.text :i18n # stores the translated attributes; persisted as a Hash
|
67
83
|
|
68
|
-
|
84
|
+
t.string :name # allows us to do SQL queries
|
69
85
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
86
|
+
t.timestamps
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
```
|
74
91
|
|
75
92
|
# Usage
|
76
93
|
|
@@ -81,44 +98,47 @@ In your code you can modify the values of your translated attributes in two ways
|
|
81
98
|
Using the built-in getter/setter methods you can set the values for any locale directly, even though
|
82
99
|
you are using your own locale.
|
83
100
|
|
84
|
-
|
85
|
-
|
86
|
-
|
101
|
+
```ruby
|
102
|
+
I18n.locale = :en
|
103
|
+
g = Genre.first
|
104
|
+
g.name = 'science fiction'
|
87
105
|
|
88
|
-
|
106
|
+
# even though you are using the :en locale, you can still set the values for other locales:
|
89
107
|
|
90
|
-
|
91
|
-
|
108
|
+
g.set_localized_attribute( :name, :jp, "サイエンスフィクション" )
|
109
|
+
g.set_localized_attribute( :name, :ko, "공상 과학 소설" )
|
92
110
|
|
93
|
-
|
94
|
-
|
95
|
-
|
111
|
+
g.name # => 'science fiction'
|
112
|
+
g.name(:jp) # => "サイエンスフィクション"
|
113
|
+
g.name(:ko) # => "공상 과학 소설"
|
96
114
|
|
97
|
-
|
98
|
-
|
115
|
+
g.get_localized_attribute( :name, :jp ) # => "サイエンスフィクション"
|
116
|
+
g.get_localized_attribute( :name, :ko ) # => "공상 과학 소설"
|
117
|
+
```
|
99
118
|
|
100
119
|
## Tweaking `I18n.locale`
|
101
120
|
|
102
121
|
By manipulating the `I18n.locale`. This is what happens if you have user's with different locales entering values into a database.
|
103
122
|
|
104
|
-
|
105
|
-
|
106
|
-
I18n.locale = :en
|
107
|
-
g = Genre.first
|
108
|
-
g.name # => 'science fiction'
|
123
|
+
The controller is just assigning the new value via `name=` , but `embedded_localization` gem takes care of storing it for the correct given locale.
|
109
124
|
|
110
|
-
|
111
|
-
|
125
|
+
```ruby
|
126
|
+
I18n.locale = :en
|
127
|
+
g = Genre.first
|
128
|
+
g.name # => 'science fiction'
|
112
129
|
|
113
|
-
|
114
|
-
|
115
|
-
g.name # => "공상 과학 소설"
|
130
|
+
I18n.locale = :jp
|
131
|
+
g.name = "サイエンスフィクション"
|
116
132
|
|
117
|
-
|
118
|
-
|
133
|
+
I18n.locale = :ko
|
134
|
+
g.name = "공상 과학 소설"
|
135
|
+
g.name # => "공상 과학 소설"
|
119
136
|
|
120
|
-
|
137
|
+
I18n.locale = :jp
|
138
|
+
g.name # => "サイエンスフィクション"
|
121
139
|
|
140
|
+
I18n.locale = :en # MAKE SURE to switch back to your default locale if you tweak it
|
141
|
+
```
|
122
142
|
|
123
143
|
## SQL Queries against Translated Fields
|
124
144
|
|
@@ -132,13 +152,15 @@ After defining the column, and running the migration, you need to populate the c
|
|
132
152
|
|
133
153
|
See also Example 2 above.
|
134
154
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
155
|
+
```ruby
|
156
|
+
I18n.locale = :en
|
157
|
+
g = Genre.first
|
158
|
+
g.name = 'science fiction' # in Example 2 this will be stored in the DB column :name as well
|
159
|
+
# ...
|
160
|
+
g.set_localized_attribute( :name, :jp, "サイエンスフィクション" )
|
161
|
+
# ...
|
162
|
+
scifi = Genre.where(:name => "science fiction").first
|
163
|
+
```
|
142
164
|
|
143
165
|
Limitation: You can not search for the translated strings other than for your default locale.
|
144
166
|
|
@@ -148,12 +170,14 @@ Limitation: You can not search for the translated strings other than for your de
|
|
148
170
|
|
149
171
|
Existing data can be migrated from an existing (not-translated) column, into a translated column with the same name as follows:
|
150
172
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
173
|
+
```ruby
|
174
|
+
Genre.record_timestamps = false # to not modify your existing timestamps
|
175
|
+
Genre.all.each do |g|
|
176
|
+
g.name = g.name # the right-hand-side fetches the translation from the i18n attribute hash
|
177
|
+
g.save # saves the :name attribute without updating the updated_at timestamp
|
178
|
+
end
|
179
|
+
Genre.record_timestamps = true
|
180
|
+
```
|
157
181
|
|
158
182
|
## I18n fallbacks for empty translations
|
159
183
|
|
@@ -161,30 +185,31 @@ It is possible to enable fallbacks for empty translations. It will depend on the
|
|
161
185
|
|
162
186
|
You can enable them by adding the next line to `config/application.rb` (or only `config/environments/production.rb` if you only want them in production)
|
163
187
|
|
164
|
-
|
165
|
-
|
166
|
-
|
188
|
+
```ruby
|
189
|
+
config.i18n.fallbacks = true # falls back to I18n.default_locale
|
190
|
+
```
|
167
191
|
|
168
192
|
By default, `embedded_localization` will only use fallbacks when the translation value for the item you've requested is `nil`.
|
169
193
|
|
194
|
+
```ruby
|
195
|
+
class Genre < ActiveRecord::Base
|
196
|
+
translates :name, :description # , :fallbacks => true
|
197
|
+
end
|
170
198
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
I18n.locale = :en
|
176
|
-
g = Genre.first
|
177
|
-
g.name # => 'science fiction'
|
199
|
+
I18n.locale = :en
|
200
|
+
g = Genre.first
|
201
|
+
g.name # => 'science fiction'
|
178
202
|
|
179
|
-
|
180
|
-
|
203
|
+
I18n.locale = :jp
|
204
|
+
g.name # => "サイエンスフィクション"
|
181
205
|
|
182
|
-
|
183
|
-
|
206
|
+
I18n.locale = :de
|
207
|
+
g.name # => nil
|
184
208
|
|
185
|
-
|
186
|
-
|
187
|
-
|
209
|
+
I18n.fallbacks = true
|
210
|
+
I18n.locale = :de
|
211
|
+
g.name # => 'science fiction'
|
212
|
+
```
|
188
213
|
|
189
214
|
## Want some Candy?
|
190
215
|
|
@@ -200,10 +225,11 @@ Each class which uses `embedded_localization` will have these additional methods
|
|
200
225
|
|
201
226
|
e.g.:
|
202
227
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
228
|
+
```ruby
|
229
|
+
Genre.translated_attributes # => [:name,:description]
|
230
|
+
Genre.translated? # => true
|
231
|
+
Genre.fallbacks? # => false
|
232
|
+
```
|
207
233
|
|
208
234
|
### Instance Methods
|
209
235
|
|
@@ -218,40 +244,39 @@ Each model instance of a class which uses `embedded_localization` will have thes
|
|
218
244
|
|
219
245
|
e.g.:
|
220
246
|
|
221
|
-
|
222
|
-
|
223
|
-
# check if an attribute is translated:
|
224
|
-
g.translated?(:name) # => true
|
247
|
+
```ruby
|
248
|
+
g = Genre.where(:name => "science fiction").first
|
225
249
|
|
226
|
-
|
227
|
-
|
250
|
+
# check if an attribute is translated:
|
251
|
+
g.translated?(:name) # => true
|
228
252
|
|
229
|
-
|
230
|
-
|
253
|
+
# which attributes are translated?
|
254
|
+
g.translated_attributes # => [:description, :name]
|
231
255
|
|
232
|
-
|
256
|
+
# check for which locales we have values: (spanning all translated fields)
|
257
|
+
g.translated_locales # => [:en]
|
233
258
|
|
234
|
-
|
235
|
-
g.translated_locales # => [:en, :de]
|
259
|
+
g.set_localized_attribute(:description, :de, "Ich liebe Science Fiction Filme")
|
236
260
|
|
237
|
-
|
238
|
-
|
239
|
-
g.translation_coverage # => {:name=>[:en], :description=>[:de]}
|
261
|
+
# check again for which locales we have values: (spanning all translated fields)
|
262
|
+
g.translated_locales # => [:en, :de]
|
240
263
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
# show where translations are missing:
|
246
|
-
# for all attributes:
|
247
|
-
g.translation_missing # => {:description=>[:en], :name=>[:de]}
|
248
|
-
|
249
|
-
# for a specific attribute:
|
250
|
-
g.translation_missing(:name) # => [:de]
|
251
|
-
g.translation_missing(:description) # => [:en]
|
264
|
+
# show details for which locales the attributes have values for:
|
265
|
+
# for all attributes:
|
266
|
+
g.translation_coverage # => {:name=>[:en], :description=>[:de]}
|
252
267
|
|
268
|
+
# for a specific attribute:
|
269
|
+
g.translation_coverage(:name) # => [:en]
|
270
|
+
g.translation_coverage(:description) # => [:de]
|
253
271
|
|
272
|
+
# show where translations are missing:
|
273
|
+
# for all attributes:
|
274
|
+
g.translation_missing # => {:description=>[:en], :name=>[:de]}
|
254
275
|
|
276
|
+
# for a specific attribute:
|
277
|
+
g.translation_missing(:name) # => [:de]
|
278
|
+
g.translation_missing(:description) # => [:en]
|
279
|
+
```
|
255
280
|
|
256
281
|
#### translated_locales vs translation_coverage
|
257
282
|
|
@@ -271,94 +296,44 @@ For a new empty record, this will be empty.
|
|
271
296
|
|
272
297
|
##### Example
|
273
298
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
g.name(:en) # => 'science fiction'
|
279
|
-
g.name(:ko) # => "공상 과학 소설"
|
280
|
-
g.name(:de) # => nil
|
281
|
-
|
282
|
-
g.translated_locales # => [:en,:jp,:ko]
|
283
|
-
g.translated_attributes # => [:name,:description]
|
284
|
-
g.translated? # => true
|
285
|
-
|
286
|
-
g.translation_coverage
|
287
|
-
# => {"name"=>["en", "ko", "jp"] , "description"=>["en", "de", "fr", "ko", "jp", "es"]}
|
288
|
-
|
289
|
-
g.translation_coverage(:name)
|
290
|
-
# => {"name"=>["en", "ko", "jp"]}
|
291
|
-
|
292
|
-
g.translation_missing
|
293
|
-
# => {"name"=>["de", "fr", "es"]}
|
294
|
-
|
295
|
-
g.translation_missing(:display)
|
296
|
-
# => {} # this indicates that there are no missing translations for the :display attribute
|
297
|
-
|
298
|
-
g.get_localized_attribute(:name, :de)
|
299
|
-
# => nil
|
300
|
-
|
301
|
-
g.set_localized_attribute(:name, :de, "Science-Fiction")
|
302
|
-
# => "Science-Fiction"
|
303
|
-
|
304
|
-
## Motivation
|
305
|
-
|
306
|
-
A recent project needed some localization support for ActiveRecord model data, but I did not want to clutter the schema with one additional table for each translated model, as globalization3 requires. A second requirement was to allow SQL queries of the fields using the default locale.
|
307
|
-
|
308
|
-
The advantage of EmbeddedLocalization is that it does not need extra tables, and therefore no joins or additional table lookups to get to the translated data.
|
309
|
-
|
310
|
-
If your requirements are different, my approach might not work for you. In that case, I recommend to look at the alternative solutions listed below.
|
311
|
-
|
312
|
-
## Changes
|
313
|
-
|
314
|
-
### 1.2.0 (2017-11-10)
|
315
|
-
* Rails 5 compatibility
|
316
|
-
* fixing tests
|
317
|
-
* updating doc
|
318
|
-
|
319
|
-
### 1.1.1 (2014-11-02)
|
320
|
-
* minor update
|
321
|
-
|
322
|
-
### 1.1.0 (2014-01-12)
|
323
|
-
* adding more rspec tests.
|
324
|
-
* improving documentation and README
|
325
|
-
|
326
|
-
### 1.0.0 (2014-01-11)
|
327
|
-
* adding rspec tests.
|
328
|
-
* fixing issue #6: translated fields for new records were not nil
|
329
|
-
* fixing issue #7: translation_missing for new records is breaking
|
330
|
-
|
299
|
+
```ruby
|
300
|
+
I18n.locale = :jp
|
301
|
+
g = Genre.first
|
302
|
+
g.name # => "サイエンスフィクション"
|
331
303
|
|
332
|
-
|
333
|
-
|
304
|
+
g.name(:en) # => 'science fiction'
|
305
|
+
g.name(:ko) # => "공상 과학 소설"
|
306
|
+
g.name(:de) # => nil
|
334
307
|
|
335
|
-
|
336
|
-
|
308
|
+
g.translated_locales # => [:en,:jp,:ko]
|
309
|
+
g.translated_attributes # => [:name,:description]
|
310
|
+
g.translated? # => true
|
337
311
|
|
338
|
-
|
339
|
-
|
312
|
+
g.translation_coverage
|
313
|
+
# => {"name"=>["en", "ko", "jp"] , "description"=>["en", "de", "fr", "ko", "jp", "es"]}
|
340
314
|
|
341
|
-
|
342
|
-
|
315
|
+
g.translation_coverage(:name)
|
316
|
+
# => {"name"=>["en", "ko", "jp"]}
|
343
317
|
|
344
|
-
|
345
|
-
|
318
|
+
g.translation_missing
|
319
|
+
# => {"name"=>["de", "fr", "es"]}
|
346
320
|
|
347
|
-
|
348
|
-
|
321
|
+
g.translation_missing(:display)
|
322
|
+
# => {} # this indicates that there are no missing translations for the :display attribute
|
349
323
|
|
350
|
-
|
351
|
-
|
352
|
-
* renamed #fallback? to #fallbacks?
|
324
|
+
g.get_localized_attribute(:name, :de)
|
325
|
+
# => nil
|
353
326
|
|
354
|
-
|
355
|
-
|
327
|
+
g.set_localized_attribute(:name, :de, "Science-Fiction")
|
328
|
+
# => "Science-Fiction"
|
329
|
+
```
|
356
330
|
|
331
|
+
## [CHANGELOG](CHANGELOG.md)
|
357
332
|
|
358
333
|
## Alternative Solutions
|
359
334
|
|
360
335
|
* [Mongoid](https://github.com/mongoid/mongoid) - awesome Ruby ORM for MongoDB, which includes in-table localization of attributes (mongoid >= 2.3.0)
|
361
|
-
* [
|
336
|
+
* [Globalize](https://github.com/globalize/globalize) - is an awesome gem, but different approach with more tables in the schema.
|
362
337
|
* [Veger's fork of Globalize2](http://github.com/veger/globalize2) - uses default AR schema for the default locale, delegates to the translations table for other locales only
|
363
338
|
* [TranslatableColumns](http://github.com/iain/translatable_columns) - have multiple languages of the same attribute in a model (Iain Hecker)
|
364
339
|
* [localized_record](http://github.com/glennpow/localized_record) - allows records to have localized attributes without any modifications to the database (Glenn Powell)
|
data/Rakefile
CHANGED
@@ -2,29 +2,31 @@
|
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
require "embedded_localization/version"
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "embedded_localization"
|
7
|
+
spec.version = EmbeddedLocalization::VERSION
|
8
|
+
spec.authors = ["Tilo Sloboda"]
|
9
|
+
spec.email = ["tilo.sloboda@gmail.com"]
|
10
|
+
spec.homepage = "https://github.com/tilo/embedded_localization"
|
11
|
+
spec.summary = %q{Rails I18n: library for embedded ActiveRecord model/data translation}
|
12
|
+
spec.description = %q{Rails I18n: Embedded_Localization for ActiveRecord is very lightweight, and allows you to transparently store translations of attributes right inside each record -- no extra database tables needed to store the localization data!}
|
13
13
|
|
14
|
-
#
|
15
|
-
|
14
|
+
# spec.platform = Gem::Platform::RUBY
|
15
|
+
spec.required_ruby_version = ">= 2.5.0"
|
16
16
|
|
17
|
-
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/tilo/embedded_localization/blob/main/CHANGELOG.md"
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
spec.files = `git ls-files`.split("\n")
|
22
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
spec.licenses = ['MIT']
|
24
26
|
# specify any dependencies here; for example:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "activerecord", ">= 6"
|
29
|
+
spec.add_development_dependency "i18n"
|
30
|
+
spec.add_development_dependency "sqlite3"
|
31
|
+
# spec.add_runtime_dependency "rest-client"
|
30
32
|
end
|
@@ -5,8 +5,8 @@ module EmbeddedLocalization
|
|
5
5
|
return if translates? # cludge to make sure we don't set this up twice..
|
6
6
|
|
7
7
|
# for details about I18n fallbacks, check the source:
|
8
|
-
# i18n-0.
|
9
|
-
# i18n-0.
|
8
|
+
# i18n-0.9.0/lib/i18n/backend/fallbacks.rb
|
9
|
+
# i18n-0.9.0/lib/i18n/locale/fallbacks.rb
|
10
10
|
|
11
11
|
# options[:fallbacks] => true or false # not used at this time
|
12
12
|
options = attr_names.extract_options!
|
@@ -23,7 +23,7 @@ module EmbeddedLocalization
|
|
23
23
|
# ::Rails::Railtie.subclasses.map(&:to_s).include?("ActiveRecord::Railtie")
|
24
24
|
#+
|
25
25
|
|
26
|
-
serialize :i18n # we should also protect it from direct assignment by the user
|
26
|
+
serialize :i18n, coder: YAML, type: Hash # we should also protect it from direct assignment by the user
|
27
27
|
|
28
28
|
#-
|
29
29
|
# if Mongoid::Document is in the list of classes which extends the class we are included into:
|
data/lib/extensions/hash.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embedded_localization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tilo Sloboda
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '6'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: i18n
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: 'Rails I18n: Embedded_Localization for ActiveRecord
|
69
|
+
description: 'Rails I18n: Embedded_Localization for ActiveRecord is very lightweight,
|
70
70
|
and allows you to transparently store translations of attributes right inside each
|
71
71
|
record -- no extra database tables needed to store the localization data!'
|
72
72
|
email:
|
@@ -77,6 +77,7 @@ extra_rdoc_files: []
|
|
77
77
|
files:
|
78
78
|
- ".gitignore"
|
79
79
|
- ".travis.yml"
|
80
|
+
- CHANGELOG.md
|
80
81
|
- Gemfile
|
81
82
|
- README.md
|
82
83
|
- Rakefile
|
@@ -97,9 +98,11 @@ files:
|
|
97
98
|
homepage: https://github.com/tilo/embedded_localization
|
98
99
|
licenses:
|
99
100
|
- MIT
|
100
|
-
|
101
|
-
|
102
|
-
|
101
|
+
metadata:
|
102
|
+
homepage_uri: https://github.com/tilo/embedded_localization
|
103
|
+
source_code_uri: https://github.com/tilo/embedded_localization
|
104
|
+
changelog_uri: https://github.com/tilo/embedded_localization/blob/main/CHANGELOG.md
|
105
|
+
post_install_message:
|
103
106
|
rdoc_options: []
|
104
107
|
require_paths:
|
105
108
|
- lib
|
@@ -107,18 +110,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
110
|
requirements:
|
108
111
|
- - ">="
|
109
112
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
113
|
+
version: 2.5.0
|
111
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
115
|
requirements:
|
113
116
|
- - ">="
|
114
117
|
- !ruby/object:Gem::Version
|
115
118
|
version: '0'
|
116
119
|
requirements: []
|
117
|
-
|
118
|
-
|
119
|
-
signing_key:
|
120
|
+
rubygems_version: 3.2.3
|
121
|
+
signing_key:
|
120
122
|
specification_version: 4
|
121
|
-
summary: 'Rails I18n: library for embedded ActiveRecord
|
123
|
+
summary: 'Rails I18n: library for embedded ActiveRecord model/data translation'
|
122
124
|
test_files:
|
123
125
|
- spec/embedded_localization/native_column_spec.rb
|
124
126
|
- spec/embedded_localization/simple_model_spec.rb
|