translated 0.4.1 → 0.5.0
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ea73e657d1f76d4cc23907d816cb02b7f0f7d58aa1c6d16ab569ee76c3bb9b2
|
|
4
|
+
data.tar.gz: e505082236651a2f7dce2e7d194901fe48ce89df2effc8a5ace44bc380388a3d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 723730d263ccf589e01cf0143c405efebbf5d54a70277c2eab99d25a4a33d49cc0af42f478ab800a1e3e1264c86c9155f84d09006532697a4b851073fce9f792
|
|
7
|
+
data.tar.gz: f1456fc3c0006c2c1b0912ad7a59188a741c2ea1bb1dfaf6c1d281dca8db992ce2547caf6a4fb2071d2c6e9d04f661173029d57889f860ec61df5b4e6b170dbe
|
|
@@ -42,7 +42,7 @@ module Translated
|
|
|
42
42
|
inverse_of: :translatable
|
|
43
43
|
after_save -> { public_send(:"#{name}_translation").save }, if: :"#{name}_translation_changed?"
|
|
44
44
|
|
|
45
|
-
validates name, validates if validates.present?
|
|
45
|
+
validates name, validates.merge(if: :"#{name}_translation_changed?") if validates.present?
|
|
46
46
|
|
|
47
47
|
scope :"with_#{name}_translation", -> { includes(:"#{name}_translation") }
|
|
48
48
|
end
|
|
@@ -8,6 +8,10 @@ module Translated
|
|
|
8
8
|
|
|
9
9
|
validates :language, presence: true, inclusion: { in: I18n.available_locales.map(&:to_s) }
|
|
10
10
|
|
|
11
|
+
scope :with_missing_translations, -> {
|
|
12
|
+
where.not(id: where("json_array_length(content) >= ?", I18n.available_locales.size))
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
after_commit :update_translations_later, if: :needs_translations?
|
|
12
16
|
|
|
13
17
|
after_initialize do
|
|
@@ -15,7 +19,11 @@ module Translated
|
|
|
15
19
|
end
|
|
16
20
|
|
|
17
21
|
def for_locale(locale)
|
|
18
|
-
content.fetch(locale.to_s
|
|
22
|
+
content.fetch(locale.to_s) { content[language] }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def missing_translations?
|
|
26
|
+
(I18n.available_locales.map(&:to_s) - content.keys).any?
|
|
19
27
|
end
|
|
20
28
|
|
|
21
29
|
def set_locale(locale, value)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :translated do
|
|
4
|
+
desc "Sync missing translations for all TranslatedTextField records"
|
|
5
|
+
task sync_missing: :environment do
|
|
6
|
+
count = 0
|
|
7
|
+
Translated::TranslatedTextField.find_each do |field|
|
|
8
|
+
if field.missing_translations?
|
|
9
|
+
puts "Syncing translations for TranslatedTextField ##{field.id} (#{field.translatable_type}##{field.translatable_id})"
|
|
10
|
+
field.update_translations
|
|
11
|
+
count += 1
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
puts "Done. Synced #{count} record(s)."
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "Re-translate all TranslatedTextField records (useful after adding a new locale)"
|
|
18
|
+
task sync_all: :environment do
|
|
19
|
+
count = Translated::TranslatedTextField.count
|
|
20
|
+
Translated::TranslatedTextField.find_each.with_index do |field, index|
|
|
21
|
+
puts "[#{index + 1}/#{count}] Syncing TranslatedTextField ##{field.id} (#{field.translatable_type}##{field.translatable_id})"
|
|
22
|
+
field.update_translations
|
|
23
|
+
end
|
|
24
|
+
puts "Done. Synced #{count} record(s)."
|
|
25
|
+
end
|
|
26
|
+
end
|
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.5.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: 2026-
|
|
12
|
+
date: 2026-02-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activejob
|
|
@@ -98,6 +98,7 @@ files:
|
|
|
98
98
|
- app/models/translated/translated_text_field.rb
|
|
99
99
|
- app/models/translated/translator.rb
|
|
100
100
|
- db/migrate/202405031152_create_translated_translated_text_fields.rb
|
|
101
|
+
- lib/tasks/translated.rake
|
|
101
102
|
- lib/tasks/translated_tasks.rake
|
|
102
103
|
- lib/translated.rb
|
|
103
104
|
- lib/translated/configuration.rb
|