embedded_localization 1.2.2 → 1.3.1
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/.github/dependabot.yml +8 -0
- data/.github/workflows/codeql-analysis.yml +72 -0
- data/.github/workflows/ruby.yml +64 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +53 -0
- data/Gemfile +2 -2
- data/README.md +148 -174
- data/Rakefile +7 -0
- data/embedded_localization.gemspec +25 -19
- data/lib/embedded_localization/active_record/act_macro.rb +1 -1
- data/lib/embedded_localization/version.rb +1 -1
- data/lib/embedded_localization.rb +1 -0
- data/spec/spec_helper.rb +10 -3
- metadata +34 -14
- data/.travis.yml +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 162d9b08b64767f51c21f4b82a05973b3f8b351c783e0d8dc11b9d79e67900fd
|
4
|
+
data.tar.gz: d397c1f3bcdc9968ea13b375c2434c7c9eab5fd298c89ae91f607e050a93a14f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dafa255cbae9e668e862e6cb7dbf684554d205c14b14dd34e13dfd8e5516e556545558cecbd313f1b87957d4ddd81b9c5a8e7ef80bb0f9545ac2c836969f9d6
|
7
|
+
data.tar.gz: 8284a738edaf160761752d7eeaaa6ff73a24cc898b82c46dbca830c6ce39a66f524f7ad1d287cc88d3749ae01869cc61ae091c0e5ca3c022ee6935465369d79f
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ "main" ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ "main" ]
|
20
|
+
schedule:
|
21
|
+
- cron: '39 11 * * 2'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v4
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v3
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
|
52
|
+
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
53
|
+
# queries: security-extended,security-and-quality
|
54
|
+
|
55
|
+
|
56
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
57
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
58
|
+
- name: Autobuild
|
59
|
+
uses: github/codeql-action/autobuild@v3
|
60
|
+
|
61
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
62
|
+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
63
|
+
|
64
|
+
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
65
|
+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
66
|
+
|
67
|
+
# - run: |
|
68
|
+
# echo "Run, Build Application using script"
|
69
|
+
# ./location_of_script_within_repo/buildscript.sh
|
70
|
+
|
71
|
+
- name: Perform CodeQL Analysis
|
72
|
+
uses: github/codeql-action/analyze@v3
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# install dependencies and run tests
|
2
|
+
# https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
3
|
+
|
4
|
+
name: Ruby
|
5
|
+
|
6
|
+
on:
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- main
|
10
|
+
|
11
|
+
pull_request:
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
test_matrix:
|
15
|
+
|
16
|
+
strategy:
|
17
|
+
fail-fast: false
|
18
|
+
matrix:
|
19
|
+
os:
|
20
|
+
- ubuntu
|
21
|
+
- macos
|
22
|
+
ruby:
|
23
|
+
- 2.5
|
24
|
+
- 2.6
|
25
|
+
- 2.7
|
26
|
+
- "3.0"
|
27
|
+
- 3.1
|
28
|
+
- 3.2
|
29
|
+
- 3.3
|
30
|
+
- head
|
31
|
+
- truffleruby
|
32
|
+
- truffleruby-head
|
33
|
+
- mingw
|
34
|
+
- jruby
|
35
|
+
- jruby-head
|
36
|
+
exclude:
|
37
|
+
- { os: ubuntu, ruby: mingw }
|
38
|
+
- { os: macos, ruby: mingw }
|
39
|
+
- { os: windows, ruby: truffleruby }
|
40
|
+
- { os: windows, ruby: truffleruby-head }
|
41
|
+
|
42
|
+
runs-on: ${{ matrix.os }}-latest
|
43
|
+
|
44
|
+
steps:
|
45
|
+
- name: clone ${{ github.repository }}
|
46
|
+
uses: actions/checkout@v4
|
47
|
+
- name: setup Ruby ${{ matrix.ruby }}
|
48
|
+
uses: ruby/setup-ruby@v1
|
49
|
+
with:
|
50
|
+
ruby-version: ${{ matrix.ruby }}
|
51
|
+
bundler-cache: true
|
52
|
+
env:
|
53
|
+
JAVA_OPTS: -Djdk.io.File.enableADS=true
|
54
|
+
- name: Run tests
|
55
|
+
run: bundle exec rake
|
56
|
+
env:
|
57
|
+
JAVA_OPTS: -Djdk.io.File.enableADS=true
|
58
|
+
|
59
|
+
finish:
|
60
|
+
runs-on: ubuntu-latest
|
61
|
+
needs: [ test_matrix ]
|
62
|
+
steps:
|
63
|
+
- name: Wait for status checks
|
64
|
+
run: echo "All Green!"
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# EmbeddedLocalization CHANGE LOG
|
2
|
+
|
3
|
+
## 1.3.1 (2024-11-26)
|
4
|
+
* [Issue 14](https://github.com/tilo/embedded_localization/pull/14) Fix active support proxy object deprecation (thanks to [Romain Morlevat](https://github.com/RomainMorlevat))
|
5
|
+
|
6
|
+
## 1.3.0 (2024-11-13)
|
7
|
+
* fixed ([issue 10](https://github.com/tilo/embedded_localization/issues)) to support Rails >= 7.1 (thanks to [Romain Morlevat](https://github.com/RomainMorlevat))
|
8
|
+
|
9
|
+
## 1.2.2 (2022-04-25)
|
10
|
+
* improved docs
|
11
|
+
|
12
|
+
## 1.2.0 (2017-11-10)
|
13
|
+
* Rails 5 compatibility
|
14
|
+
* fixing tests
|
15
|
+
* updating doc
|
16
|
+
|
17
|
+
## 1.1.1 (2014-11-02)
|
18
|
+
* minor update
|
19
|
+
|
20
|
+
## 1.1.0 (2014-01-12)
|
21
|
+
* adding more rspec tests.
|
22
|
+
* improving documentation and README
|
23
|
+
|
24
|
+
## 1.0.0 (2014-01-11)
|
25
|
+
* adding rspec tests.
|
26
|
+
* fixing issue #6: translated fields for new records were not nil
|
27
|
+
* fixing issue #7: translation_missing for new records is breaking
|
28
|
+
|
29
|
+
|
30
|
+
## 0.2.5 (2013-11-02)
|
31
|
+
* adding MIT and GPL-2 licenses to gem-spec file; contact me if you need another license
|
32
|
+
|
33
|
+
## 0.2.4 (2012-03-02)
|
34
|
+
* Issue #5 : bugfix for attr_writer
|
35
|
+
|
36
|
+
## 0.2.3 (2012-03-02)
|
37
|
+
* Issue #4 : bugfix for attr_writer - no longer updates attributes if value didn't change => timestamps don't change in that case
|
38
|
+
|
39
|
+
## 0.2.2 (2012-02-06)
|
40
|
+
* bugfix for attr_writer
|
41
|
+
|
42
|
+
## 0.2.1 (2012-01-31)
|
43
|
+
* bugfix for serialized i18n attribute
|
44
|
+
|
45
|
+
## 0.2.0 (2012-01-31)
|
46
|
+
* added support for having DB columns for translated attributes, to enable SQL queries in `I18n.default_locale`
|
47
|
+
|
48
|
+
## 0.1.4 (2012-01-31)
|
49
|
+
* fixed bug with dirty tracking of serialized i18n attribute
|
50
|
+
* renamed #fallback? to #fallbacks?
|
51
|
+
|
52
|
+
## 0.1.3 Initial Version (2012-01-27)
|
53
|
+
* initial version
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# Embedded Localization
|
2
2
|
|
3
|
-
[](https://codecov.io/gh/tilo/embedded_localization)  [View on RubyGems](https://rubygems.org/gems/embedded_localization)
|
4
4
|
|
5
|
-
`embedded_localization`
|
5
|
+
`embedded_localization` allows you to store your translations directly insight each record.
|
6
6
|
|
7
|
-
`embedded_localization` is
|
7
|
+
`embedded_localization` is compatible with Rails 6.x, 7.x, and adds model translations to ActiveRecord, and is compatible with and builds on the [I18n API in Ruby on Rails](http://guides.rubyonrails.org/i18n.html)
|
8
|
+
|
9
|
+
`embedded_localization` is very lightweight, and allows you to transparently store multiple 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
10
|
|
9
11
|
Model translations with `embedded_localization` use default ActiveRecord features and do not limit any ActiveRecord functionality.
|
10
12
|
|
@@ -13,7 +15,7 @@ On top of that, you also get tools for checking into which locales an attribute
|
|
13
15
|
|
14
16
|
## Motivation
|
15
17
|
|
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.
|
18
|
+
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. Product translations are another use case, as well as movies, books, TV-shows, etc. Another scenario is that you have dynamic content that needs to be translated.
|
17
19
|
|
18
20
|
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
21
|
|
@@ -24,7 +26,7 @@ If your requirements are different, this approach might not work for you. In tha
|
|
24
26
|
|
25
27
|
## Requirements
|
26
28
|
|
27
|
-
* ActiveRecord >=
|
29
|
+
* ActiveRecord >= 6 # including 7.x
|
28
30
|
* [I18n](http://guides.rubyonrails.org/i18n.html)
|
29
31
|
|
30
32
|
## Installation
|
@@ -46,21 +48,25 @@ Model translations allow you to translate your models’ attribute values. The a
|
|
46
48
|
|
47
49
|
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:
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
```ruby
|
52
|
+
class Genre < ActiveRecord::Base
|
53
|
+
translates :name, :description
|
54
|
+
end
|
55
|
+
```
|
52
56
|
|
53
57
|
In the DB migration, you just need to add the `i18n` text field:
|
54
58
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
```ruby
|
60
|
+
class CreateGenres < ActiveRecord::Migration
|
61
|
+
def self.change
|
62
|
+
create_table :genres do |t|
|
63
|
+
t.text :i18n # stores ALL the translated attributes; persisted as a Hash
|
59
64
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
65
|
+
t.timestamps
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
64
70
|
|
65
71
|
### Example 2
|
66
72
|
|
@@ -71,17 +77,19 @@ This way you can always do SQL queries against the values in the `I18n.default_l
|
|
71
77
|
|
72
78
|
To do this, using the same model as in example 1, you can modify your migration as follows:
|
73
79
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
80
|
+
```ruby
|
81
|
+
class CreateGenres < ActiveRecord::Migration
|
82
|
+
def self.change
|
83
|
+
create_table :genres do |t|
|
84
|
+
t.text :i18n # stores the translated attributes; persisted as a Hash
|
78
85
|
|
79
|
-
|
86
|
+
t.string :name # allows us to do SQL queries
|
80
87
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
88
|
+
t.timestamps
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
```
|
85
93
|
|
86
94
|
# Usage
|
87
95
|
|
@@ -92,44 +100,47 @@ In your code you can modify the values of your translated attributes in two ways
|
|
92
100
|
Using the built-in getter/setter methods you can set the values for any locale directly, even though
|
93
101
|
you are using your own locale.
|
94
102
|
|
95
|
-
|
96
|
-
|
97
|
-
|
103
|
+
```ruby
|
104
|
+
I18n.locale = :en
|
105
|
+
g = Genre.first
|
106
|
+
g.name = 'science fiction'
|
98
107
|
|
99
|
-
|
108
|
+
# even though you are using the :en locale, you can still set the values for other locales:
|
100
109
|
|
101
|
-
|
102
|
-
|
110
|
+
g.set_localized_attribute( :name, :jp, "サイエンスフィクション" )
|
111
|
+
g.set_localized_attribute( :name, :ko, "공상 과학 소설" )
|
103
112
|
|
104
|
-
|
105
|
-
|
106
|
-
|
113
|
+
g.name # => 'science fiction'
|
114
|
+
g.name(:jp) # => "サイエンスフィクション"
|
115
|
+
g.name(:ko) # => "공상 과학 소설"
|
107
116
|
|
108
|
-
|
109
|
-
|
117
|
+
g.get_localized_attribute( :name, :jp ) # => "サイエンスフィクション"
|
118
|
+
g.get_localized_attribute( :name, :ko ) # => "공상 과학 소설"
|
119
|
+
```
|
110
120
|
|
111
121
|
## Tweaking `I18n.locale`
|
112
122
|
|
113
123
|
By manipulating the `I18n.locale`. This is what happens if you have user's with different locales entering values into a database.
|
114
124
|
|
115
|
-
|
116
|
-
|
117
|
-
I18n.locale = :en
|
118
|
-
g = Genre.first
|
119
|
-
g.name # => 'science fiction'
|
125
|
+
The controller is just assigning the new value via `name=` , but `embedded_localization` gem takes care of storing it for the correct given locale.
|
120
126
|
|
121
|
-
|
122
|
-
|
127
|
+
```ruby
|
128
|
+
I18n.locale = :en
|
129
|
+
g = Genre.first
|
130
|
+
g.name # => 'science fiction'
|
123
131
|
|
124
|
-
|
125
|
-
|
126
|
-
g.name # => "공상 과학 소설"
|
132
|
+
I18n.locale = :jp
|
133
|
+
g.name = "サイエンスフィクション"
|
127
134
|
|
128
|
-
|
129
|
-
|
135
|
+
I18n.locale = :ko
|
136
|
+
g.name = "공상 과학 소설"
|
137
|
+
g.name # => "공상 과학 소설"
|
130
138
|
|
131
|
-
|
139
|
+
I18n.locale = :jp
|
140
|
+
g.name # => "サイエンスフィクション"
|
132
141
|
|
142
|
+
I18n.locale = :en # MAKE SURE to switch back to your default locale if you tweak it
|
143
|
+
```
|
133
144
|
|
134
145
|
## SQL Queries against Translated Fields
|
135
146
|
|
@@ -143,13 +154,15 @@ After defining the column, and running the migration, you need to populate the c
|
|
143
154
|
|
144
155
|
See also Example 2 above.
|
145
156
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
157
|
+
```ruby
|
158
|
+
I18n.locale = :en
|
159
|
+
g = Genre.first
|
160
|
+
g.name = 'science fiction' # in Example 2 this will be stored in the DB column :name as well
|
161
|
+
# ...
|
162
|
+
g.set_localized_attribute( :name, :jp, "サイエンスフィクション" )
|
163
|
+
# ...
|
164
|
+
scifi = Genre.where(:name => "science fiction").first
|
165
|
+
```
|
153
166
|
|
154
167
|
Limitation: You can not search for the translated strings other than for your default locale.
|
155
168
|
|
@@ -159,12 +172,14 @@ Limitation: You can not search for the translated strings other than for your de
|
|
159
172
|
|
160
173
|
Existing data can be migrated from an existing (not-translated) column, into a translated column with the same name as follows:
|
161
174
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
175
|
+
```ruby
|
176
|
+
Genre.record_timestamps = false # to not modify your existing timestamps
|
177
|
+
Genre.all.each do |g|
|
178
|
+
g.name = g.name # the right-hand-side fetches the translation from the i18n attribute hash
|
179
|
+
g.save # saves the :name attribute without updating the updated_at timestamp
|
180
|
+
end
|
181
|
+
Genre.record_timestamps = true
|
182
|
+
```
|
168
183
|
|
169
184
|
## I18n fallbacks for empty translations
|
170
185
|
|
@@ -172,30 +187,31 @@ It is possible to enable fallbacks for empty translations. It will depend on the
|
|
172
187
|
|
173
188
|
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)
|
174
189
|
|
175
|
-
|
176
|
-
|
177
|
-
|
190
|
+
```ruby
|
191
|
+
config.i18n.fallbacks = true # falls back to I18n.default_locale
|
192
|
+
```
|
178
193
|
|
179
194
|
By default, `embedded_localization` will only use fallbacks when the translation value for the item you've requested is `nil`.
|
180
195
|
|
196
|
+
```ruby
|
197
|
+
class Genre < ActiveRecord::Base
|
198
|
+
translates :name, :description # , :fallbacks => true
|
199
|
+
end
|
181
200
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
I18n.locale = :en
|
187
|
-
g = Genre.first
|
188
|
-
g.name # => 'science fiction'
|
201
|
+
I18n.locale = :en
|
202
|
+
g = Genre.first
|
203
|
+
g.name # => 'science fiction'
|
189
204
|
|
190
|
-
|
191
|
-
|
205
|
+
I18n.locale = :jp
|
206
|
+
g.name # => "サイエンスフィクション"
|
192
207
|
|
193
|
-
|
194
|
-
|
208
|
+
I18n.locale = :de
|
209
|
+
g.name # => nil
|
195
210
|
|
196
|
-
|
197
|
-
|
198
|
-
|
211
|
+
I18n.fallbacks = true
|
212
|
+
I18n.locale = :de
|
213
|
+
g.name # => 'science fiction'
|
214
|
+
```
|
199
215
|
|
200
216
|
## Want some Candy?
|
201
217
|
|
@@ -211,10 +227,11 @@ Each class which uses `embedded_localization` will have these additional methods
|
|
211
227
|
|
212
228
|
e.g.:
|
213
229
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
230
|
+
```ruby
|
231
|
+
Genre.translated_attributes # => [:name,:description]
|
232
|
+
Genre.translated? # => true
|
233
|
+
Genre.fallbacks? # => false
|
234
|
+
```
|
218
235
|
|
219
236
|
### Instance Methods
|
220
237
|
|
@@ -229,40 +246,39 @@ Each model instance of a class which uses `embedded_localization` will have thes
|
|
229
246
|
|
230
247
|
e.g.:
|
231
248
|
|
232
|
-
|
249
|
+
```ruby
|
250
|
+
g = Genre.where(:name => "science fiction").first
|
233
251
|
|
234
|
-
|
235
|
-
|
252
|
+
# check if an attribute is translated:
|
253
|
+
g.translated?(:name) # => true
|
236
254
|
|
237
|
-
|
238
|
-
|
255
|
+
# which attributes are translated?
|
256
|
+
g.translated_attributes # => [:description, :name]
|
239
257
|
|
240
|
-
|
241
|
-
|
258
|
+
# check for which locales we have values: (spanning all translated fields)
|
259
|
+
g.translated_locales # => [:en]
|
242
260
|
|
243
|
-
|
261
|
+
g.set_localized_attribute(:description, :de, "Ich liebe Science Fiction Filme")
|
244
262
|
|
245
|
-
|
246
|
-
|
263
|
+
# check again for which locales we have values: (spanning all translated fields)
|
264
|
+
g.translated_locales # => [:en, :de]
|
247
265
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
# for a specific attribute:
|
253
|
-
g.translation_coverage(:name) # => [:en]
|
254
|
-
g.translation_coverage(:description) # => [:de]
|
255
|
-
|
256
|
-
# show where translations are missing:
|
257
|
-
# for all attributes:
|
258
|
-
g.translation_missing # => {:description=>[:en], :name=>[:de]}
|
259
|
-
|
260
|
-
# for a specific attribute:
|
261
|
-
g.translation_missing(:name) # => [:de]
|
262
|
-
g.translation_missing(:description) # => [:en]
|
266
|
+
# show details for which locales the attributes have values for:
|
267
|
+
# for all attributes:
|
268
|
+
g.translation_coverage # => {:name=>[:en], :description=>[:de]}
|
263
269
|
|
270
|
+
# for a specific attribute:
|
271
|
+
g.translation_coverage(:name) # => [:en]
|
272
|
+
g.translation_coverage(:description) # => [:de]
|
264
273
|
|
274
|
+
# show where translations are missing:
|
275
|
+
# for all attributes:
|
276
|
+
g.translation_missing # => {:description=>[:en], :name=>[:de]}
|
265
277
|
|
278
|
+
# for a specific attribute:
|
279
|
+
g.translation_missing(:name) # => [:de]
|
280
|
+
g.translation_missing(:description) # => [:en]
|
281
|
+
```
|
266
282
|
|
267
283
|
#### translated_locales vs translation_coverage
|
268
284
|
|
@@ -282,81 +298,39 @@ For a new empty record, this will be empty.
|
|
282
298
|
|
283
299
|
##### Example
|
284
300
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
g.name(:en) # => 'science fiction'
|
290
|
-
g.name(:ko) # => "공상 과학 소설"
|
291
|
-
g.name(:de) # => nil
|
292
|
-
|
293
|
-
g.translated_locales # => [:en,:jp,:ko]
|
294
|
-
g.translated_attributes # => [:name,:description]
|
295
|
-
g.translated? # => true
|
296
|
-
|
297
|
-
g.translation_coverage
|
298
|
-
# => {"name"=>["en", "ko", "jp"] , "description"=>["en", "de", "fr", "ko", "jp", "es"]}
|
299
|
-
|
300
|
-
g.translation_coverage(:name)
|
301
|
-
# => {"name"=>["en", "ko", "jp"]}
|
302
|
-
|
303
|
-
g.translation_missing
|
304
|
-
# => {"name"=>["de", "fr", "es"]}
|
305
|
-
|
306
|
-
g.translation_missing(:display)
|
307
|
-
# => {} # this indicates that there are no missing translations for the :display attribute
|
308
|
-
|
309
|
-
g.get_localized_attribute(:name, :de)
|
310
|
-
# => nil
|
311
|
-
|
312
|
-
g.set_localized_attribute(:name, :de, "Science-Fiction")
|
313
|
-
# => "Science-Fiction"
|
314
|
-
|
315
|
-
## Changes
|
316
|
-
|
317
|
-
### 1.2.0 (2017-11-10)
|
318
|
-
* Rails 5 compatibility
|
319
|
-
* fixing tests
|
320
|
-
* updating doc
|
321
|
-
|
322
|
-
### 1.1.1 (2014-11-02)
|
323
|
-
* minor update
|
324
|
-
|
325
|
-
### 1.1.0 (2014-01-12)
|
326
|
-
* adding more rspec tests.
|
327
|
-
* improving documentation and README
|
328
|
-
|
329
|
-
### 1.0.0 (2014-01-11)
|
330
|
-
* adding rspec tests.
|
331
|
-
* fixing issue #6: translated fields for new records were not nil
|
332
|
-
* fixing issue #7: translation_missing for new records is breaking
|
333
|
-
|
301
|
+
```ruby
|
302
|
+
I18n.locale = :jp
|
303
|
+
g = Genre.first
|
304
|
+
g.name # => "サイエンスフィクション"
|
334
305
|
|
335
|
-
|
336
|
-
|
306
|
+
g.name(:en) # => 'science fiction'
|
307
|
+
g.name(:ko) # => "공상 과학 소설"
|
308
|
+
g.name(:de) # => nil
|
337
309
|
|
338
|
-
|
339
|
-
|
310
|
+
g.translated_locales # => [:en,:jp,:ko]
|
311
|
+
g.translated_attributes # => [:name,:description]
|
312
|
+
g.translated? # => true
|
340
313
|
|
341
|
-
|
342
|
-
|
314
|
+
g.translation_coverage
|
315
|
+
# => {"name"=>["en", "ko", "jp"] , "description"=>["en", "de", "fr", "ko", "jp", "es"]}
|
343
316
|
|
344
|
-
|
345
|
-
|
317
|
+
g.translation_coverage(:name)
|
318
|
+
# => {"name"=>["en", "ko", "jp"]}
|
346
319
|
|
347
|
-
|
348
|
-
|
320
|
+
g.translation_missing
|
321
|
+
# => {"name"=>["de", "fr", "es"]}
|
349
322
|
|
350
|
-
|
351
|
-
|
323
|
+
g.translation_missing(:display)
|
324
|
+
# => {} # this indicates that there are no missing translations for the :display attribute
|
352
325
|
|
353
|
-
|
354
|
-
|
355
|
-
* renamed #fallback? to #fallbacks?
|
326
|
+
g.get_localized_attribute(:name, :de)
|
327
|
+
# => nil
|
356
328
|
|
357
|
-
|
358
|
-
|
329
|
+
g.set_localized_attribute(:name, :de, "Science-Fiction")
|
330
|
+
# => "Science-Fiction"
|
331
|
+
```
|
359
332
|
|
333
|
+
## [CHANGELOG](CHANGELOG.md)
|
360
334
|
|
361
335
|
## Alternative Solutions
|
362
336
|
|
data/Rakefile
CHANGED
@@ -2,26 +2,32 @@
|
|
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: a very lightweight tool to allow you to transparently store multiple translations of attributes directly inside each DB record -- no extra database tables needed to store the localization data!}
|
13
13
|
|
14
|
-
#
|
14
|
+
# spec.platform = Gem::Platform::RUBY
|
15
|
+
spec.required_ruby_version = ">= 2.5.0"
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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"
|
20
|
+
|
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']
|
21
26
|
# specify any dependencies here; for example:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
spec.add_development_dependency "codecov"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "activerecord", ">= 6"
|
30
|
+
spec.add_development_dependency "i18n"
|
31
|
+
spec.add_development_dependency "sqlite3"
|
32
|
+
# spec.add_runtime_dependency "rest-client"
|
27
33
|
end
|
@@ -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/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'active_record'
|
3
2
|
require 'i18n'
|
4
|
-
require 'bundler/setup'
|
5
3
|
|
6
|
-
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter '/spec/'
|
7
|
+
add_filter "/pkg/"
|
8
|
+
end
|
9
|
+
|
10
|
+
if ENV['CI'] == 'true' || ENV['CODECOV_TOKEN']
|
11
|
+
require 'codecov'
|
12
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
13
|
+
end
|
7
14
|
|
8
15
|
require 'embedded_localization'
|
9
16
|
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tilo Sloboda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: codecov
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -28,16 +42,16 @@ dependencies:
|
|
28
42
|
name: activerecord
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '6'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '6'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: i18n
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,17 +80,21 @@ dependencies:
|
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
|
-
description: 'Rails I18n:
|
70
|
-
|
71
|
-
|
83
|
+
description: 'Rails I18n: a very lightweight tool to allow you to transparently store
|
84
|
+
multiple translations of attributes directly inside each DB record -- no extra database
|
85
|
+
tables needed to store the localization data!'
|
72
86
|
email:
|
73
87
|
- tilo.sloboda@gmail.com
|
74
88
|
executables: []
|
75
89
|
extensions: []
|
76
90
|
extra_rdoc_files: []
|
77
91
|
files:
|
92
|
+
- ".github/dependabot.yml"
|
93
|
+
- ".github/workflows/codeql-analysis.yml"
|
94
|
+
- ".github/workflows/ruby.yml"
|
78
95
|
- ".gitignore"
|
79
|
-
- ".
|
96
|
+
- ".rspec"
|
97
|
+
- CHANGELOG.md
|
80
98
|
- Gemfile
|
81
99
|
- README.md
|
82
100
|
- Rakefile
|
@@ -97,8 +115,10 @@ files:
|
|
97
115
|
homepage: https://github.com/tilo/embedded_localization
|
98
116
|
licenses:
|
99
117
|
- MIT
|
100
|
-
|
101
|
-
|
118
|
+
metadata:
|
119
|
+
homepage_uri: https://github.com/tilo/embedded_localization
|
120
|
+
source_code_uri: https://github.com/tilo/embedded_localization
|
121
|
+
changelog_uri: https://github.com/tilo/embedded_localization/blob/main/CHANGELOG.md
|
102
122
|
post_install_message:
|
103
123
|
rdoc_options: []
|
104
124
|
require_paths:
|
@@ -107,14 +127,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
127
|
requirements:
|
108
128
|
- - ">="
|
109
129
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
130
|
+
version: 2.5.0
|
111
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
132
|
requirements:
|
113
133
|
- - ">="
|
114
134
|
- !ruby/object:Gem::Version
|
115
135
|
version: '0'
|
116
136
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
137
|
+
rubygems_version: 3.5.4
|
118
138
|
signing_key:
|
119
139
|
specification_version: 4
|
120
140
|
summary: 'Rails I18n: library for embedded ActiveRecord model/data translation'
|
data/.travis.yml
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
bundler_args: --without development
|
3
|
-
before_install:
|
4
|
-
- gem install bundler
|
5
|
-
- gem update --system
|
6
|
-
|
7
|
-
matrix:
|
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: jruby-9.2.19.0
|
18
|
-
- rvm: jruby-9.3.3.0
|
19
|
-
- jruby-head
|
20
|
-
- mruby
|
21
|
-
- rubinius
|
22
|
-
- ree
|
23
|
-
|
24
|
-
env:
|
25
|
-
- JRUBY_OPTS="--server -Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -J-Xms512m -J-Xmx1024m"
|
26
|
-
- rvm: ruby-head
|
27
|
-
|
28
|
-
branches:
|
29
|
-
only:
|
30
|
-
- master
|