translated 0.2.0 → 0.4.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b0fa395bf9d6140de846cf8198420887598969f58cbff6b2f8e76e34dd59849
|
4
|
+
data.tar.gz: f3540086ff6da0902232e25ab62f340c58f6a16b96b3eecfecabf665f7732eff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77eaf5e0c292f4b52a034ca2fb2ec492bd9dbf770dab1bd2f2b71c394ff98888a733c84fabcca7feb8984398f2d8e6c5a8d6cdf06d795336789e9d95d7437163
|
7
|
+
data.tar.gz: 7eab53083e0a4c1aa3b1edb1dd69536780220e45d377e70749681585a5f41c57ca7be4ffdb8bfd31c82ef39ac7f7247c3e8f52233d00b32b8420d8a4cf11be93
|
data/README.md
CHANGED
@@ -54,5 +54,9 @@ Translated.api_key = 'API KEY from translatedrb.com'
|
|
54
54
|
# Translated.environments = %w(development production)
|
55
55
|
```
|
56
56
|
|
57
|
+
## Example Project
|
58
|
+
|
59
|
+
Check out an example Rails project with Translated already installed [here](https://github.com/getcomfortly/translated-example).
|
60
|
+
|
57
61
|
## License
|
58
62
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -4,8 +4,8 @@ module Translated
|
|
4
4
|
class UpdateRichTranslationsJob < ApplicationJob
|
5
5
|
queue_as :default
|
6
6
|
|
7
|
-
def perform(record, attribute_name
|
8
|
-
record.public_send(:"
|
7
|
+
def perform(record, attribute_name)
|
8
|
+
record.public_send(:"generate_translations_for_#{attribute_name}")
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -23,6 +23,10 @@ module Translated
|
|
23
23
|
content
|
24
24
|
end
|
25
25
|
|
26
|
+
def #{name}_changed?
|
27
|
+
#{name}_translation_changed? || super
|
28
|
+
end
|
29
|
+
|
26
30
|
private
|
27
31
|
|
28
32
|
def #{name}_translation_changed?
|
@@ -40,7 +44,15 @@ module Translated
|
|
40
44
|
|
41
45
|
validates name, validates if validates.present?
|
42
46
|
|
43
|
-
scope :
|
47
|
+
scope :"with_#{name}_translation", -> { includes(:"#{name}_translation") }
|
48
|
+
end
|
49
|
+
|
50
|
+
def with_translations
|
51
|
+
includes(translation_association_names)
|
52
|
+
end
|
53
|
+
|
54
|
+
def translation_association_names
|
55
|
+
reflect_on_all_associations(:has_one).map(&:name).select { |n| n.ends_with?('_translation') }
|
44
56
|
end
|
45
57
|
|
46
58
|
def has_translated_rich_text(name) # rubocop:disable Naming/PredicateName
|
@@ -55,32 +67,30 @@ module Translated
|
|
55
67
|
|
56
68
|
def #{name}=(body)
|
57
69
|
self.public_send(:"#{name}_\#{I18n.locale}=", body)
|
58
|
-
@
|
70
|
+
@_#{name}_translation_changed = true
|
71
|
+
body
|
72
|
+
end
|
59
73
|
|
74
|
+
def generate_translations_for_#{name}
|
60
75
|
I18n.available_locales.each do |locale|
|
61
76
|
next if locale == I18n.locale
|
62
77
|
|
63
|
-
|
78
|
+
from = I18n.locale
|
79
|
+
to = locale
|
80
|
+
content = public_send(:"#{name}_\#{from}").body&.to_html
|
81
|
+
translation = content.present? ? Translator.new.translate(content, from:, to:) : nil
|
82
|
+
update("#{name}_\#{to}" => translation)
|
64
83
|
end
|
65
|
-
|
66
|
-
body
|
67
|
-
end
|
68
|
-
|
69
|
-
def generate_translation_for_#{name}(from, to)
|
70
|
-
self.public_send(:"#{name}_\#{to}=", Translator.new.translate(public_send(:"#{name}_\#{from}").body.to_html, from:, to:))
|
71
|
-
save!
|
72
84
|
end
|
73
85
|
|
74
86
|
private
|
75
87
|
|
76
|
-
def
|
77
|
-
defined?(:@
|
88
|
+
def #{name}_translation_changed?
|
89
|
+
defined?(:@_#{name}_translation_changed) && @_#{name}_translation_changed
|
78
90
|
end
|
79
91
|
|
80
|
-
def
|
81
|
-
|
82
|
-
UpdateRichTranslationsJob.perform_later(self, *args)
|
83
|
-
end
|
92
|
+
def generate_translations_for_#{name}_later
|
93
|
+
UpdateRichTranslationsJob.perform_later(self, :#{name})
|
84
94
|
end
|
85
95
|
CODE
|
86
96
|
|
@@ -88,7 +98,7 @@ module Translated
|
|
88
98
|
has_rich_text :"#{name}_#{locale}"
|
89
99
|
end
|
90
100
|
|
91
|
-
|
101
|
+
after_save :"generate_translations_for_#{name}_later", if: :"#{name}_translation_changed?"
|
92
102
|
|
93
103
|
scope :"with_rich_text_#{name}", lambda {
|
94
104
|
includes(I18n.available_locales.map do |locale|
|
data/lib/translated/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translated
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trae Robrock
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activejob
|