polylingo_chat 0.1.0 → 0.1.1
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 +4 -4
- data/lib/generators/polylingo_chat/install/install_generator.rb +1 -1
- data/lib/polylingo_chat/translate_job.rb +6 -4
- data/lib/polylingo_chat/translator/anthropic_client.rb +2 -2
- data/lib/polylingo_chat/translator/gemini_client.rb +2 -2
- data/lib/polylingo_chat/translator/openai_client.rb +2 -2
- data/lib/polylingo_chat/version.rb +1 -1
- metadata +7 -26
- data/lib/generators/polylingo_chat/install_generator.rb +0 -38
- data/lib/generators/polylingo_chat/templates/INSTALL_README.md +0 -124
- data/lib/generators/polylingo_chat/templates/chat_channel_example.js +0 -18
- data/lib/generators/polylingo_chat/templates/create_polyglot_conversations.rb +0 -9
- data/lib/generators/polylingo_chat/templates/create_polyglot_messages.rb +0 -13
- data/lib/generators/polylingo_chat/templates/create_polyglot_participants.rb +0 -12
- data/lib/generators/polylingo_chat/templates/models/conversation.rb +0 -7
- data/lib/generators/polylingo_chat/templates/models/message.rb +0 -14
- data/lib/generators/polylingo_chat/templates/models/participant.rb +0 -6
- data/lib/generators/polylingo_chat/templates/polyglot.rb +0 -53
- data/lib/generators/polylingo_chat/templates/polylingo_chat_channel.rb +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c6491b6c4c4efb8f3a036ca5b603cf6d383d7ffd60804cf080dcb3cde055360d
|
|
4
|
+
data.tar.gz: 9998d94782b87daf3a3546221f9f16be51bcd74a959f2eb4b2a823de97222fec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 24c88ccebf1bf762ae31ed874a1d88e1afc45f6f0866c62a5f7ac61ae3b759528bd81738f147f275e0e29d458adf6f34c984b1e94b48f8ebc0760c4131f592be
|
|
7
|
+
data.tar.gz: c361b6cfdca10f5952a848d57cc94f32775d0fb85594b0044c7ba277b180571c4bc8cad23bc77b0a012fbd132138716b14242a46673794f1ea8b03854db4d114
|
|
@@ -31,7 +31,7 @@ module PolylingoChat
|
|
|
31
31
|
empty_directory "app/channels/application_cable"
|
|
32
32
|
template "channels/application_cable/channel.rb", "app/channels/application_cable/channel.rb"
|
|
33
33
|
template "channels/application_cable/connection.rb", "app/channels/application_cable/connection.rb"
|
|
34
|
-
template "channels/
|
|
34
|
+
template "channels/polylingo_chat_channel.rb", "app/channels/polylingo_chat_channel.rb"
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def create_javascript_files
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module PolylingoChat
|
|
2
|
-
class TranslateJob <
|
|
2
|
+
class TranslateJob < ApplicationJob
|
|
3
3
|
queue_as :polylingo_chat_translations
|
|
4
4
|
|
|
5
5
|
def perform(message_id)
|
|
@@ -52,12 +52,14 @@ module PolylingoChat
|
|
|
52
52
|
translated: translation_enabled,
|
|
53
53
|
recipient_id: recipient.id
|
|
54
54
|
})
|
|
55
|
-
rescue => e
|
|
56
|
-
|
|
55
|
+
rescue StandardError => e
|
|
56
|
+
Rails.logger.error("PolylingoChat: Broadcast failed - #{e.message}")
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
message.update(translated: translation_enabled)
|
|
60
|
+
message.update(translated: translation_enabled)
|
|
61
|
+
rescue StandardError => e
|
|
62
|
+
Rails.logger.error("PolylingoChat: Failed to update message translation status - #{e.message}")
|
|
61
63
|
end
|
|
62
64
|
end
|
|
63
65
|
end
|
|
@@ -21,7 +21,7 @@ module PolylingoChat
|
|
|
21
21
|
# caching
|
|
22
22
|
cache_key = "polylingo_chat:#{Digest::SHA1.hexdigest([text, from, to, context].join(':'))}"
|
|
23
23
|
if (cache = PolylingoChat.config.cache_store)
|
|
24
|
-
cached = cache.get(cache_key) rescue nil
|
|
24
|
+
cached = cache.get(cache_key) rescue StandardError; nil
|
|
25
25
|
return JSON.parse(cached)['translated'] if cached
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -31,7 +31,7 @@ module PolylingoChat
|
|
|
31
31
|
if (cache = PolylingoChat.config.cache_store)
|
|
32
32
|
begin
|
|
33
33
|
cache.set(cache_key, { translated: translated }.to_json)
|
|
34
|
-
rescue => e
|
|
34
|
+
rescue StandardError => e
|
|
35
35
|
# ignore cache failures
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -21,7 +21,7 @@ module PolylingoChat
|
|
|
21
21
|
# caching
|
|
22
22
|
cache_key = "polylingo_chat:#{Digest::SHA1.hexdigest([text, from, to, context].join(':'))}"
|
|
23
23
|
if (cache = PolylingoChat.config.cache_store)
|
|
24
|
-
cached = cache.get(cache_key) rescue nil
|
|
24
|
+
cached = cache.get(cache_key) rescue StandardError; nil
|
|
25
25
|
return JSON.parse(cached)['translated'] if cached
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -31,7 +31,7 @@ module PolylingoChat
|
|
|
31
31
|
if (cache = PolylingoChat.config.cache_store)
|
|
32
32
|
begin
|
|
33
33
|
cache.set(cache_key, { translated: translated }.to_json)
|
|
34
|
-
rescue => e
|
|
34
|
+
rescue StandardError => e
|
|
35
35
|
# ignore cache failures
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -23,7 +23,7 @@ module PolylingoChat
|
|
|
23
23
|
# caching
|
|
24
24
|
cache_key = "polylingo_chat:#{Digest::SHA1.hexdigest([text, from, to, context].join(':'))}"
|
|
25
25
|
if (cache = PolylingoChat.config.cache_store)
|
|
26
|
-
cached = cache.get(cache_key) rescue nil
|
|
26
|
+
cached = cache.get(cache_key) rescue StandardError; nil
|
|
27
27
|
return JSON.parse(cached)['translated'] if cached
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ module PolylingoChat
|
|
|
33
33
|
if (cache = PolylingoChat.config.cache_store)
|
|
34
34
|
begin
|
|
35
35
|
cache.set(cache_key, { translated: translated }.to_json)
|
|
36
|
-
rescue => e
|
|
36
|
+
rescue StandardError => e
|
|
37
37
|
# ignore cache failures
|
|
38
38
|
end
|
|
39
39
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: polylingo_chat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shoaib Malik
|
|
@@ -17,6 +17,9 @@ dependencies:
|
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '6.0'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '9'
|
|
20
23
|
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -24,6 +27,9 @@ dependencies:
|
|
|
24
27
|
- - ">="
|
|
25
28
|
- !ruby/object:Gem::Version
|
|
26
29
|
version: '6.0'
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '9'
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
34
|
name: faraday
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -52,20 +58,6 @@ dependencies:
|
|
|
52
58
|
- - "~>"
|
|
53
59
|
- !ruby/object:Gem::Version
|
|
54
60
|
version: '1.2'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: json
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - ">="
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0'
|
|
62
|
-
type: :runtime
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - ">="
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0'
|
|
69
61
|
description:
|
|
70
62
|
email:
|
|
71
63
|
- shoaib2109@gmail.com
|
|
@@ -89,17 +81,6 @@ files:
|
|
|
89
81
|
- lib/generators/polylingo_chat/install/templates/models/conversation.rb
|
|
90
82
|
- lib/generators/polylingo_chat/install/templates/models/message.rb
|
|
91
83
|
- lib/generators/polylingo_chat/install/templates/models/participant.rb
|
|
92
|
-
- lib/generators/polylingo_chat/install_generator.rb
|
|
93
|
-
- lib/generators/polylingo_chat/templates/INSTALL_README.md
|
|
94
|
-
- lib/generators/polylingo_chat/templates/chat_channel_example.js
|
|
95
|
-
- lib/generators/polylingo_chat/templates/create_polyglot_conversations.rb
|
|
96
|
-
- lib/generators/polylingo_chat/templates/create_polyglot_messages.rb
|
|
97
|
-
- lib/generators/polylingo_chat/templates/create_polyglot_participants.rb
|
|
98
|
-
- lib/generators/polylingo_chat/templates/models/conversation.rb
|
|
99
|
-
- lib/generators/polylingo_chat/templates/models/message.rb
|
|
100
|
-
- lib/generators/polylingo_chat/templates/models/participant.rb
|
|
101
|
-
- lib/generators/polylingo_chat/templates/polyglot.rb
|
|
102
|
-
- lib/generators/polylingo_chat/templates/polylingo_chat_channel.rb
|
|
103
84
|
- lib/polylingo_chat.rb
|
|
104
85
|
- lib/polylingo_chat/config.rb
|
|
105
86
|
- lib/polylingo_chat/engine.rb
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
require 'rails/generators'
|
|
2
|
-
module PolylingoChat
|
|
3
|
-
module Generators
|
|
4
|
-
class InstallGenerator < Rails::Generators::Base
|
|
5
|
-
source_root File.expand_path('templates', __dir__)
|
|
6
|
-
|
|
7
|
-
def copy_initializer
|
|
8
|
-
template 'polylingo_chat.rb', 'config/initializers/polylingo_chat.rb'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def copy_channel
|
|
12
|
-
template 'polylingo_chat_chat_channel.rb', 'app/channels/polylingo_chat_chat_channel.rb'
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def copy_js_example
|
|
16
|
-
template 'chat_channel_example.js', 'app/javascript/channels/polylingo_chat_chat_channel.js'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def copy_models
|
|
20
|
-
template 'models/conversation.rb', 'app/models/conversation.rb'
|
|
21
|
-
template 'models/participant.rb', 'app/models/participant.rb'
|
|
22
|
-
template 'models/message.rb', 'app/models/message.rb'
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def copy_migrations
|
|
26
|
-
migration_template 'create_polylingo_chat_conversations.rb', 'db/migrate/create_polylingo_chat_conversations.rb'
|
|
27
|
-
migration_template 'create_polylingo_chat_participants.rb', 'db/migrate/create_polylingo_chat_participants.rb'
|
|
28
|
-
migration_template 'create_polylingo_chat_messages.rb', 'db/migrate/create_polylingo_chat_messages.rb'
|
|
29
|
-
rescue => e
|
|
30
|
-
say_status('warning', 'Skipping migrations: ensure you add your own Message/Conversation models or run generator again with --migrate', :yellow)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def show_readme
|
|
34
|
-
readme 'INSTALL_README.md' if behavior == :invoke
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
## PolylingoChat Installation Complete!
|
|
2
|
-
|
|
3
|
-
### Next Steps:
|
|
4
|
-
|
|
5
|
-
**PolylingoChat can work in TWO modes:**
|
|
6
|
-
1. **Chat-Only Mode:** Real-time chat without translation (no API key needed)
|
|
7
|
-
2. **With Translation:** AI-powered translation (API key required)
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
### 1. Run migrations
|
|
12
|
-
```bash
|
|
13
|
-
bin/rails db:migrate
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
### 2. Configure ActiveJob
|
|
17
|
-
|
|
18
|
-
```ruby
|
|
19
|
-
# config/application.rb or config/environments/production.rb
|
|
20
|
-
config.active_job.queue_adapter = :sidekiq # or :solid_queue, :delayed_job, :async
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### 3. Install your background job processor
|
|
24
|
-
|
|
25
|
-
**Sidekiq:**
|
|
26
|
-
```ruby
|
|
27
|
-
# Gemfile
|
|
28
|
-
gem 'sidekiq'
|
|
29
|
-
```
|
|
30
|
-
Then: `bundle install && bundle exec sidekiq`
|
|
31
|
-
|
|
32
|
-
**Solid Queue:**
|
|
33
|
-
```ruby
|
|
34
|
-
# Gemfile
|
|
35
|
-
gem 'solid_queue'
|
|
36
|
-
```
|
|
37
|
-
Then: `bundle install && bin/rails solid_queue:install && bin/rails db:migrate && bin/rails solid_queue:start`
|
|
38
|
-
|
|
39
|
-
**Delayed Job:**
|
|
40
|
-
```ruby
|
|
41
|
-
# Gemfile
|
|
42
|
-
gem 'delayed_job_active_record'
|
|
43
|
-
```
|
|
44
|
-
Then: `bundle install && bin/rails generate delayed_job:active_record && bin/rails db:migrate && bin/rails jobs:work`
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
### 4. Configure PolylingoChat
|
|
49
|
-
|
|
50
|
-
Edit `config/initializers/polylingo_chat.rb`:
|
|
51
|
-
|
|
52
|
-
**Option A: Chat-Only (No Translation)**
|
|
53
|
-
```ruby
|
|
54
|
-
PolylingoChat.configure do |config|
|
|
55
|
-
# Leave api_key as nil for chat-only mode
|
|
56
|
-
config.api_key = nil
|
|
57
|
-
config.queue_adapter = :sidekiq
|
|
58
|
-
config.async = true
|
|
59
|
-
end
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
**Option B: With AI Translation**
|
|
63
|
-
```ruby
|
|
64
|
-
PolylingoChat.configure do |config|
|
|
65
|
-
# Enable translation
|
|
66
|
-
config.provider = :openai # or :anthropic, :gemini
|
|
67
|
-
config.api_key = ENV['POLYGLOT_API_KEY']
|
|
68
|
-
config.model = 'gpt-4o-mini'
|
|
69
|
-
|
|
70
|
-
config.queue_adapter = :sidekiq
|
|
71
|
-
config.default_language = 'en'
|
|
72
|
-
config.cache_store = Rails.cache
|
|
73
|
-
end
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
### 5. (Optional) Add preferred_language to User
|
|
79
|
-
|
|
80
|
-
**Only needed if using translation:**
|
|
81
|
-
```bash
|
|
82
|
-
bin/rails generate migration AddPreferredLanguageToUsers preferred_language:string
|
|
83
|
-
bin/rails db:migrate
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
### 6. Get API Key (Optional)
|
|
89
|
-
|
|
90
|
-
**Only if you want translation:**
|
|
91
|
-
- OpenAI: https://platform.openai.com/api-keys
|
|
92
|
-
- Anthropic: https://console.anthropic.com/
|
|
93
|
-
- Gemini: https://ai.google.dev/
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
# .env
|
|
97
|
-
POLYGLOT_API_KEY=your-key-here
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
### Testing
|
|
103
|
-
|
|
104
|
-
```ruby
|
|
105
|
-
conversation = Conversation.create!(title: "Test")
|
|
106
|
-
Participant.create!(conversation: conversation, user: user1)
|
|
107
|
-
Participant.create!(conversation: conversation, user: user2)
|
|
108
|
-
|
|
109
|
-
Message.create!(
|
|
110
|
-
conversation: conversation,
|
|
111
|
-
sender: user1,
|
|
112
|
-
body: "Hello!"
|
|
113
|
-
)
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
- **Without API key:** Message sent as-is
|
|
117
|
-
- **With API key:** Message translated to each user's language
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
### Need Help?
|
|
122
|
-
|
|
123
|
-
- 📖 Documentation: https://github.com/shoaibmalik786/polylingo_chat
|
|
124
|
-
- 🐛 Issues: https://github.com/shoaibmalik786/polylingo_chat/issues
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import consumer from "@rails/actioncable"
|
|
2
|
-
|
|
3
|
-
const cable = consumer.createConsumer();
|
|
4
|
-
|
|
5
|
-
export default function subscribe(conversationId, handleReceive) {
|
|
6
|
-
const subscription = cable.subscriptions.create({ channel: 'PolylinguoChatChannel', conversation_id: conversationId }, {
|
|
7
|
-
connected() {},
|
|
8
|
-
disconnected() {},
|
|
9
|
-
received(data) {
|
|
10
|
-
handleReceive(data)
|
|
11
|
-
},
|
|
12
|
-
sendMessage(text, conversationId) {
|
|
13
|
-
this.perform('receive', { message: text, conversation_id: conversationId });
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return subscription;
|
|
18
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class CreatePolylingoChatMessages < ActiveRecord::Migration[6.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table :messages do |t|
|
|
4
|
-
t.references :sender, null: false, foreign_key: { to_table: :users }
|
|
5
|
-
t.references :conversation, null: false, foreign_key: true
|
|
6
|
-
t.text :body
|
|
7
|
-
t.string :language
|
|
8
|
-
t.text :translated_body
|
|
9
|
-
t.boolean :translated, default: false
|
|
10
|
-
t.timestamps
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
class CreatePolylingoChatParticipants < ActiveRecord::Migration[6.0]
|
|
2
|
-
def change
|
|
3
|
-
create_table :participants do |t|
|
|
4
|
-
t.references :user, null: false, foreign_key: true
|
|
5
|
-
t.references :conversation, null: false, foreign_key: true
|
|
6
|
-
t.string :role
|
|
7
|
-
t.timestamps
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
add_index :participants, [:user_id, :conversation_id], unique: true
|
|
11
|
-
end
|
|
12
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class Message < ApplicationRecord
|
|
2
|
-
belongs_to :conversation
|
|
3
|
-
belongs_to :sender, class_name: 'User', foreign_key: 'sender_id'
|
|
4
|
-
|
|
5
|
-
validates :body, presence: true
|
|
6
|
-
|
|
7
|
-
after_create_commit :enqueue_translation_job
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
def enqueue_translation_job
|
|
12
|
-
PolylingoChat::TranslateJob.perform_later(id) if PolylingoChat.config.async
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# PolylingoChat Configuration
|
|
2
|
-
# For more information, see: https://github.com/shoaibmalik786/polylingo_chat
|
|
3
|
-
|
|
4
|
-
PolylingoChat.configure do |config|
|
|
5
|
-
# ========================================
|
|
6
|
-
# AI Provider Configuration (OPTIONAL)
|
|
7
|
-
# ========================================
|
|
8
|
-
|
|
9
|
-
# Translation is OPTIONAL! If you don't set an API key, PolylingoChat works as a
|
|
10
|
-
# real-time chat engine without translation (messages sent as-is).
|
|
11
|
-
|
|
12
|
-
# To enable translation, choose your AI provider: :openai, :anthropic, or :gemini
|
|
13
|
-
config.provider = :openai
|
|
14
|
-
|
|
15
|
-
# Set your API key (leave nil to use chat-only mode without translation)
|
|
16
|
-
config.api_key = ENV['POLYGLOT_API_KEY'] # or set to nil for chat-only mode
|
|
17
|
-
|
|
18
|
-
# Choose your model based on provider:
|
|
19
|
-
# OpenAI: 'gpt-4o-mini', 'gpt-4o', 'gpt-3.5-turbo'
|
|
20
|
-
# Anthropic: 'claude-3-5-sonnet-20241022', 'claude-3-5-haiku-20241022', 'claude-3-opus-20240229'
|
|
21
|
-
# Gemini: 'gemini-1.5-flash', 'gemini-1.5-pro'
|
|
22
|
-
config.model = 'gpt-4o-mini'
|
|
23
|
-
|
|
24
|
-
# ========================================
|
|
25
|
-
# Background Job Configuration
|
|
26
|
-
# ========================================
|
|
27
|
-
|
|
28
|
-
# Specify which ActiveJob adapter you're using (OPTIONAL, for documentation purposes)
|
|
29
|
-
# You still need to configure ActiveJob in your Rails app as normal
|
|
30
|
-
# Options: :sidekiq, :solid_queue, :delayed_job, :async, :inline, etc.
|
|
31
|
-
#
|
|
32
|
-
# Example ActiveJob configuration (in config/application.rb or config/environments/*.rb):
|
|
33
|
-
# config.active_job.queue_adapter = :sidekiq
|
|
34
|
-
#
|
|
35
|
-
# Then tell PolylingoChat which adapter you're using:
|
|
36
|
-
config.queue_adapter = :sidekiq # Change this to match your ActiveJob setup
|
|
37
|
-
|
|
38
|
-
# Enable/disable async processing
|
|
39
|
-
config.async = true
|
|
40
|
-
|
|
41
|
-
# ========================================
|
|
42
|
-
# Translation Configuration
|
|
43
|
-
# ========================================
|
|
44
|
-
|
|
45
|
-
# Default language for translations (ISO 639-1 code)
|
|
46
|
-
config.default_language = 'en'
|
|
47
|
-
|
|
48
|
-
# Enable caching for translations (recommended for production)
|
|
49
|
-
config.cache_store = Rails.cache
|
|
50
|
-
|
|
51
|
-
# Request timeout in seconds
|
|
52
|
-
config.timeout = 15
|
|
53
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
class PolylinguoChatChannel < ApplicationCable::Channel
|
|
2
|
-
def subscribed
|
|
3
|
-
# stream for the current user
|
|
4
|
-
stream_from "polylingo_chat_recipient_#{current_user.id}"
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def receive(data)
|
|
8
|
-
# data: { message: 'Hola', conversation_id: 1 }
|
|
9
|
-
message_text = data['message']
|
|
10
|
-
conversation = Conversation.find(data['conversation_id'])
|
|
11
|
-
|
|
12
|
-
msg = Message.create!(conversation: conversation, sender: current_user, body: message_text, language: current_user.preferred_language)
|
|
13
|
-
# enqueue translation job
|
|
14
|
-
PolylingoChat::TranslateJob.perform_async(msg.id)
|
|
15
|
-
|
|
16
|
-
# broadcast original to sender's stream if you want
|
|
17
|
-
ActionCable.server.broadcast("polylingo_chat_recipient_#{current_user.id}", { message: message_text, original: message_text, sender_id: current_user.id, message_id: msg.id, original:true })
|
|
18
|
-
end
|
|
19
|
-
end
|