translated 0.2.0 → 0.3.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: d8e76f6a921836b0f1eaab3a9c216876050d70b2376b936c641863c88aa8979c
|
4
|
+
data.tar.gz: 6e2cb9f18f06f3d0408812eb42bd57053ccc9b2acc766a2d5f78dd249e503c7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6bc895fb490fac8fe2c23a9bf7e000dde58330909c36a956d288a0b325583d21cf45dc6c7a897f0752a38e904f33486033e22b4f80efc4c7a7d548d4a79479b
|
7
|
+
data.tar.gz: c4912b58c78943cdf884be2d3bc5a993fdd7b04984adfba97eca41e00a999cf27e40e81e799f793966fe7f5ff8000a0780b1ce40a2c67565e3eeed1f8a9f886e
|
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
|
@@ -55,32 +55,30 @@ module Translated
|
|
55
55
|
|
56
56
|
def #{name}=(body)
|
57
57
|
self.public_send(:"#{name}_\#{I18n.locale}=", body)
|
58
|
-
@
|
58
|
+
@_#{name}_translation_changed = true
|
59
|
+
body
|
60
|
+
end
|
59
61
|
|
62
|
+
def generate_translations_for_#{name}
|
60
63
|
I18n.available_locales.each do |locale|
|
61
64
|
next if locale == I18n.locale
|
62
65
|
|
63
|
-
|
66
|
+
from = I18n.locale
|
67
|
+
to = locale
|
68
|
+
content = public_send(:"#{name}_\#{from}").body&.to_html
|
69
|
+
translation = content.present? ? Translator.new.translate(content, from:, to:) : nil
|
70
|
+
update("#{name}_\#{to}" => translation)
|
64
71
|
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
72
|
end
|
73
73
|
|
74
74
|
private
|
75
75
|
|
76
|
-
def
|
77
|
-
defined?(:@
|
76
|
+
def #{name}_translation_changed?
|
77
|
+
defined?(:@_#{name}_translation_changed) && @_#{name}_translation_changed
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
81
|
-
|
82
|
-
UpdateRichTranslationsJob.perform_later(self, *args)
|
83
|
-
end
|
80
|
+
def generate_translations_for_#{name}_later
|
81
|
+
UpdateRichTranslationsJob.perform_later(self, :#{name})
|
84
82
|
end
|
85
83
|
CODE
|
86
84
|
|
@@ -88,7 +86,7 @@ module Translated
|
|
88
86
|
has_rich_text :"#{name}_#{locale}"
|
89
87
|
end
|
90
88
|
|
91
|
-
|
89
|
+
after_save :"generate_translations_for_#{name}_later", if: :"#{name}_translation_changed?"
|
92
90
|
|
93
91
|
scope :"with_rich_text_#{name}", lambda {
|
94
92
|
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.3.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
|