buddy_translatable 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +15 -15
- data/README.md +6 -43
- data/buddy_translatable.gemspec +2 -2
- data/lib/buddy_translatable.rb +0 -5
- data/lib/buddy_translatable/core.rb +10 -26
- data/lib/buddy_translatable/version.rb +1 -1
- metadata +9 -10
- data/lib/buddy_translatable/configuration.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7400068f6a44cecc838b666b11a3d04e2379bd0e10f3ef64e92b62bb70438d8d
|
4
|
+
data.tar.gz: e41ee4fbe96d09530663597c37114f9dac7375e45008eeb4bafa3325b3790520
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9efbcbc8f420ebd9011528e0d086d2836f8be5dfb6b0946c2911ba4c6089c6237ddb0e6b2f22542bdfecc95398df7a94483847a68430d9d6cd55e5a17adf3f7d
|
7
|
+
data.tar.gz: 41c4c3a915c831689e52088cf6b44c3fa1e0274283b33bfe55bc4e61bf6324f8a9d06e88410c3b647340807a5f1c51e3814a8e7131e0fe35c70d3309b1f956eb
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
buddy_translatable (0.
|
4
|
+
buddy_translatable (0.2.0)
|
5
5
|
activerecord (>= 5.0)
|
6
6
|
activesupport (>= 5.0)
|
7
7
|
i18n
|
@@ -10,24 +10,23 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activemodel (
|
14
|
-
activesupport (=
|
15
|
-
activerecord (
|
16
|
-
activemodel (=
|
17
|
-
activesupport (=
|
18
|
-
|
19
|
-
activesupport (5.2.3)
|
13
|
+
activemodel (6.0.3.2)
|
14
|
+
activesupport (= 6.0.3.2)
|
15
|
+
activerecord (6.0.3.2)
|
16
|
+
activemodel (= 6.0.3.2)
|
17
|
+
activesupport (= 6.0.3.2)
|
18
|
+
activesupport (6.0.3.2)
|
20
19
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
20
|
i18n (>= 0.7, < 2)
|
22
21
|
minitest (~> 5.1)
|
23
22
|
tzinfo (~> 1.1)
|
24
|
-
|
25
|
-
concurrent-ruby (1.1.
|
23
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
24
|
+
concurrent-ruby (1.1.7)
|
26
25
|
diff-lcs (1.3)
|
27
|
-
i18n (1.
|
26
|
+
i18n (1.8.5)
|
28
27
|
concurrent-ruby (~> 1.0)
|
29
|
-
minitest (5.
|
30
|
-
pg (1.
|
28
|
+
minitest (5.14.1)
|
29
|
+
pg (1.2.3)
|
31
30
|
rake (10.5.0)
|
32
31
|
rspec (3.8.0)
|
33
32
|
rspec-core (~> 3.8.0)
|
@@ -43,8 +42,9 @@ GEM
|
|
43
42
|
rspec-support (~> 3.8.0)
|
44
43
|
rspec-support (3.8.2)
|
45
44
|
thread_safe (0.3.6)
|
46
|
-
tzinfo (1.2.
|
45
|
+
tzinfo (1.2.7)
|
47
46
|
thread_safe (~> 0.1)
|
47
|
+
zeitwerk (2.4.0)
|
48
48
|
|
49
49
|
PLATFORMS
|
50
50
|
ruby
|
@@ -56,4 +56,4 @@ DEPENDENCIES
|
|
56
56
|
rspec (~> 3.0)
|
57
57
|
|
58
58
|
BUNDLED WITH
|
59
|
-
1.
|
59
|
+
1.17.3
|
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# JSON Buddy Translatable
|
2
2
|
|
3
|
-
Allows you to store text data in multiple languages
|
3
|
+
Allows you to store text data in multiple languages. Based on [translateable](https://github.com/olegantonyan/translateable), but with a few differences:
|
4
4
|
|
5
5
|
1. Support for key methods
|
6
|
-
2.
|
6
|
+
2. No extra table dependency
|
7
|
+
3. Single attribute
|
7
8
|
|
8
9
|
### Translations
|
9
10
|
```ruby
|
@@ -37,40 +38,7 @@ post.title_es # => Hallo (return default key if not found)
|
|
37
38
|
# Replace all data
|
38
39
|
post.update(title: { en: 'En val', de: 'De val' })
|
39
40
|
post.title_en # => En val
|
40
|
-
|
41
|
-
|
42
|
-
### Sales Channels
|
43
|
-
```ruby
|
44
|
-
class Post < ActiveRecord::Base
|
45
|
-
include BuddyTranslatable
|
46
|
-
sales_datable :key, default_key: :vev
|
47
|
-
end
|
48
|
-
post = Post.create(key: { vev: 'vev', ebay: 'ebay' })
|
49
|
-
|
50
|
-
# getter
|
51
|
-
post.key #=> vev # return default key
|
52
|
-
BuddyTranslatable.config.current_sales_key = :ebay
|
53
|
-
post.key #=> ebay
|
54
|
-
|
55
|
-
# you can reset current sales channel by
|
56
|
-
BuddyTranslatable.config.reset_current_sales_key
|
57
|
-
|
58
|
-
# Getter using methods
|
59
|
-
post.key_vev #=> vev
|
60
|
-
post.key_ebay #=> ebay
|
61
|
-
post.key_for(:ebay) #=> ebay
|
62
|
-
post.key_data_for(:vev) #=> vev
|
63
|
-
post.key_data # => return all data (Hash)
|
64
|
-
|
65
|
-
# Update current sales key (if empty will use default_key) and maintain others
|
66
|
-
BuddyTranslatable.config.current_sales_key = :ebay
|
67
|
-
post.update(key: 'Ebay changed')
|
68
|
-
post.key_ebay # => Ebay changed
|
69
|
-
post.key_vev # => vev
|
70
|
-
|
71
|
-
# Replace all data
|
72
|
-
post.update(key: { vev: 'vev val', ebay: 'ebay val' })
|
73
|
-
post.key_vev # => vev val
|
41
|
+
post.title_es # => De val # default_key value is used when not defined
|
74
42
|
```
|
75
43
|
|
76
44
|
## Requirements
|
@@ -87,12 +55,8 @@ Add this line to your application's Gemfile:
|
|
87
55
|
gem 'buddy_translatable'
|
88
56
|
```
|
89
57
|
|
90
|
-
|
91
|
-
```
|
92
|
-
# config/initializers/translatable.rb
|
93
|
-
BuddyTranslatable.config.available_sales_keys = %i[de ebay]
|
94
|
-
I18n.available_locales = %i[de en es]
|
95
|
-
```
|
58
|
+
Configure your available locales in your rails app, like:
|
59
|
+
```I18n.available_locales = %i[de en es]```
|
96
60
|
|
97
61
|
And then execute:
|
98
62
|
``` bundle install ```
|
@@ -104,7 +68,6 @@ class TestModel < ActiveRecord::Base
|
|
104
68
|
include BuddyTranslatable
|
105
69
|
|
106
70
|
translatable :title, default_key: :de
|
107
|
-
sales_datable :key, default_key: :vev #, available_keys: [:ebay, :amazon, :vev]
|
108
71
|
end
|
109
72
|
```
|
110
73
|
|
data/buddy_translatable.gemspec
CHANGED
@@ -11,8 +11,8 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.authors = ['Owen']
|
12
12
|
spec.email = ['owenperedo@gmail.com']
|
13
13
|
|
14
|
-
spec.summary = 'Manages translations
|
15
|
-
spec.description = 'Manages translations
|
14
|
+
spec.summary = 'Manages attribute translations translations'
|
15
|
+
spec.description = 'Manages attribute translations translations'
|
16
16
|
spec.homepage = 'https://github.com/owen2345/buddy_translatable'
|
17
17
|
spec.license = 'MIT'
|
18
18
|
|
data/lib/buddy_translatable.rb
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'buddy_translatable/version'
|
4
|
-
require 'buddy_translatable/configuration'
|
5
4
|
require 'buddy_translatable/core'
|
6
5
|
module BuddyTranslatable
|
7
|
-
def self.config
|
8
|
-
@config ||= Configuration.new
|
9
|
-
end
|
10
|
-
|
11
6
|
def self.included(base)
|
12
7
|
base.extend BuddyTranslatable::Core
|
13
8
|
end
|
@@ -2,40 +2,24 @@
|
|
2
2
|
|
3
3
|
module BuddyTranslatable
|
4
4
|
module Core
|
5
|
-
def translatable(*attrs, default_key: :
|
6
|
-
available_keys
|
5
|
+
def translatable(*attrs, default_key: :en, available_keys: nil)
|
6
|
+
available_keys ||= I18n.available_locales
|
7
7
|
attrs.each do |attr|
|
8
8
|
define_translatable_methods(attr, default_key)
|
9
9
|
define_translatable_key_methods(attr, available_keys)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
available_keys = BuddyTranslatable.config.available_sales_keys
|
16
|
-
end
|
17
|
-
attrs.each do |attr|
|
18
|
-
define_translatable_methods(attr, default_key, is_locale: false)
|
19
|
-
define_translatable_key_methods(attr, available_keys)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def define_translatable_methods(attr, default_key, is_locale: true)
|
24
|
-
current_key = lambda do
|
25
|
-
res = I18n.locale
|
26
|
-
current_sales_key = BuddyTranslatable.config.current_sales_key
|
27
|
-
res = current_sales_key || default_key unless is_locale
|
28
|
-
res.to_sym
|
29
|
-
end
|
30
|
-
define_translatable_setters(attr, current_key)
|
13
|
+
def define_translatable_methods(attr, default_key)
|
14
|
+
define_translatable_setters(attr)
|
31
15
|
define_translatable_key_getters(attr, default_key)
|
32
|
-
define_translatable_getters(attr
|
16
|
+
define_translatable_getters(attr)
|
33
17
|
end
|
34
18
|
|
35
|
-
def define_translatable_setters(attr
|
19
|
+
def define_translatable_setters(attr)
|
36
20
|
define_method("#{attr}_data=") do |arg|
|
37
21
|
data = send("#{attr}_data")
|
38
|
-
self[attr] = arg.is_a?(Hash) ? arg : data.merge(
|
22
|
+
self[attr] = arg.is_a?(Hash) ? arg : data.merge(I18n.locale => arg)
|
39
23
|
end
|
40
24
|
|
41
25
|
define_method("#{attr}=") do |arg|
|
@@ -56,15 +40,15 @@ module BuddyTranslatable
|
|
56
40
|
end
|
57
41
|
end
|
58
42
|
|
59
|
-
def define_translatable_getters(attr
|
43
|
+
def define_translatable_getters(attr)
|
60
44
|
define_method("#{attr}_data") do
|
61
45
|
res = self[attr]
|
62
|
-
res = new_record? ? {
|
46
|
+
res = new_record? ? { I18n.locale => '' } : {} unless res.present?
|
63
47
|
res.symbolize_keys.with_indifferent_access
|
64
48
|
end
|
65
49
|
|
66
50
|
define_method(attr) do |**_args|
|
67
|
-
send("#{attr}_data_for",
|
51
|
+
send("#{attr}_data_for", I18n.locale)
|
68
52
|
end
|
69
53
|
end
|
70
54
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buddy_translatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description: Manages translations
|
111
|
+
description: Manages attribute translations translations
|
112
112
|
email:
|
113
113
|
- owenperedo@gmail.com
|
114
114
|
executables: []
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- ".gitignore"
|
119
119
|
- ".rspec"
|
120
120
|
- ".travis.yml"
|
121
|
+
- CHANGELOG.md
|
121
122
|
- CODE_OF_CONDUCT.md
|
122
123
|
- Gemfile
|
123
124
|
- Gemfile.lock
|
@@ -128,14 +129,13 @@ files:
|
|
128
129
|
- bin/setup
|
129
130
|
- buddy_translatable.gemspec
|
130
131
|
- lib/buddy_translatable.rb
|
131
|
-
- lib/buddy_translatable/configuration.rb
|
132
132
|
- lib/buddy_translatable/core.rb
|
133
133
|
- lib/buddy_translatable/version.rb
|
134
134
|
homepage: https://github.com/owen2345/buddy_translatable
|
135
135
|
licenses:
|
136
136
|
- MIT
|
137
137
|
metadata: {}
|
138
|
-
post_install_message:
|
138
|
+
post_install_message:
|
139
139
|
rdoc_options: []
|
140
140
|
require_paths:
|
141
141
|
- lib
|
@@ -150,9 +150,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
152
|
requirements: []
|
153
|
-
|
154
|
-
|
155
|
-
signing_key:
|
153
|
+
rubygems_version: 3.0.8
|
154
|
+
signing_key:
|
156
155
|
specification_version: 4
|
157
|
-
summary: Manages translations
|
156
|
+
summary: Manages attribute translations translations
|
158
157
|
test_files: []
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module BuddyTranslatable
|
4
|
-
class Configuration
|
5
|
-
attr_accessor :available_sales_keys, :current_sales_key
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@available_sales_keys = %i[vev ebay]
|
9
|
-
end
|
10
|
-
|
11
|
-
def reset_current_sales_key
|
12
|
-
@current_sales_key = nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|