translated 0.6.0 → 0.8.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: 8b3a7e233ad98179a153145bbb84fa38186b176351afca8ab458522c7c96148a
4
- data.tar.gz: 54a5078644d08bf413b906e7806e04fd115ac41f764b22acf2634d54fbf94b5f
3
+ metadata.gz: d39bf3bbcbb292ad9ab54256c1295e49658d40f32fb801f0ce9332121d4a860e
4
+ data.tar.gz: e8e5d9cee7ec307d166f40aff02d8a7ff3e81f52bb88e0e64fe7ef6a901090ff
5
5
  SHA512:
6
- metadata.gz: 2123c8e5f8b4448d7eb30881e310523492e51bdcab03a0ef032afa825b7d1e3c37274a56eeede9c4189db7e22116d4af82af66952f0ea715c6848ac6e3914474
7
- data.tar.gz: ba6d3f9885d7d3de4f300dd86c3c61165124f2cb8b3f4393cc9f23319834d2223d66f4b757f51af04c22372cce853d201d50d164301e6330bf29233d23c5dc2f
6
+ metadata.gz: e7d098cefe5de5b9009539b5d9c71cdbd8d8c4884336a823c7e57b033a077311ad1de46898eeb68009b0253b6de7079270e2b8203a153ab4ea1d50f08dc9774b
7
+ data.tar.gz: 25c6d9b05735855f2e33aec1530a3b397fc928e3b7164f7da657573f25a01279b2eeb67e8efe5f2a55a52e447d421cbd2f9cf7caeddeb5611674fe99ae5b2cd6
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Translated
4
+ class SyncAllTranslationsJob < ApplicationJob
5
+ queue_as :default
6
+
7
+ def perform
8
+ TranslatedTextField.sync_all
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Translated
4
+ class SyncMissingTranslationsJob < ApplicationJob
5
+ queue_as :default
6
+
7
+ def perform
8
+ TranslatedTextField.sync_missing
9
+ end
10
+ end
11
+ end
@@ -8,8 +8,19 @@ 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))
11
+ scope :with_missing_translations, lambda {
12
+ json_length_expression = case connection.adapter_name
13
+ when /mysql/i
14
+ 'JSON_LENGTH(content)'
15
+ when /sqlite/i
16
+ "(SELECT count(*) FROM json_each(#{table_name}.content))"
17
+ when /postgres/i
18
+ '(SELECT count(*) FROM jsonb_each_text(content::jsonb))'
19
+ else
20
+ 'JSON_LENGTH(content)'
21
+ end
22
+
23
+ where.not(id: where("#{json_length_expression} >= ?", I18n.available_locales.size))
13
24
  }
14
25
 
15
26
  after_commit :update_translations_later, if: :needs_translations?
@@ -18,20 +29,12 @@ module Translated
18
29
  self.content ||= {}
19
30
  end
20
31
 
21
- # Sync translations for a single record by ID.
22
- # Designed for use with delayable pattern: TranslatedTextField.delay.sync_record(id)
23
- def self.sync_record(id)
24
- find(id).update_translations
25
- end
26
-
27
32
  # Sync only records that are missing translations.
28
- # Designed for use with delayable pattern: TranslatedTextField.delay.sync_missing
29
33
  def self.sync_missing
30
34
  with_missing_translations.find_each(&:update_translations)
31
35
  end
32
36
 
33
37
  # Re-translate all records. Useful after adding a new locale.
34
- # Designed for use with delayable pattern: TranslatedTextField.delay.sync_all
35
38
  def self.sync_all
36
39
  find_each(&:update_translations)
37
40
  end
@@ -1,4 +1,6 @@
1
- class CreateTranslatedTranslatedTextFields < ActiveRecord::Migration[7.2]
1
+ # frozen_string_literal: true
2
+
3
+ class CreateTranslatedTranslatedTextFields < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :translated_translated_text_fields do |t|
4
6
  t.references :translatable, polymorphic: true, null: false
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Translated
4
- VERSION = '0.6.0'
4
+ VERSION = '0.8.0'
5
5
  end
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.6.0
4
+ version: 0.8.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-02-03 00:00:00.000000000 Z
12
+ date: 2026-03-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activejob
@@ -92,13 +92,14 @@ files:
92
92
  - MIT-LICENSE
93
93
  - README.md
94
94
  - Rakefile
95
+ - app/jobs/translated/sync_all_translations_job.rb
96
+ - app/jobs/translated/sync_missing_translations_job.rb
95
97
  - app/jobs/translated/update_rich_translations_job.rb
96
98
  - app/jobs/translated/update_translations_job.rb
97
99
  - app/models/concerns/translated/translatable.rb
98
100
  - app/models/translated/translated_text_field.rb
99
101
  - app/models/translated/translator.rb
100
102
  - db/migrate/202405031152_create_translated_translated_text_fields.rb
101
- - lib/tasks/translated.rake
102
103
  - lib/tasks/translated_tasks.rake
103
104
  - lib/translated.rb
104
105
  - lib/translated/configuration.rb
@@ -1,17 +0,0 @@
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
- puts "Syncing records with missing translations..."
7
- Translated::TranslatedTextField.sync_missing
8
- puts "Done."
9
- end
10
-
11
- desc "Re-translate all TranslatedTextField records (useful after adding a new locale)"
12
- task sync_all: :environment do
13
- puts "Syncing all #{Translated::TranslatedTextField.count} record(s)..."
14
- Translated::TranslatedTextField.sync_all
15
- puts "Done."
16
- end
17
- end