Module: PolylingoChat::Translator

Defined in:
lib/polylingo_chat/translator.rb,
lib/polylingo_chat/translator/base.rb,
lib/polylingo_chat/translator/gemini_client.rb,
lib/polylingo_chat/translator/openai_client.rb,
lib/polylingo_chat/translator/anthropic_client.rb

Defined Under Namespace

Classes: AnthropicClient, Base, GeminiClient, OpenAIClient

Class Method Summary collapse

Class Method Details

.configure_providerObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/polylingo_chat/translator.rb', line 21

def configure_provider
  case PolylingoChat.config.provider
  when :openai
    PolylingoChat::Translator::OpenAIClient
  when :anthropic
    PolylingoChat::Translator::AnthropicClient
  when :gemini
    PolylingoChat::Translator::GeminiClient
  else
    PolylingoChat::Translator::OpenAIClient
  end
end

.detect_language(text) ⇒ Object



9
10
11
# File 'lib/polylingo_chat/translator.rb', line 9

def detect_language(text)
  provider_client.detect_language(text)
end

.provider_clientObject



17
18
19
# File 'lib/polylingo_chat/translator.rb', line 17

def provider_client
  @provider_client ||= configure_provider
end

.reset_provider!Object



34
35
36
37
# File 'lib/polylingo_chat/translator.rb', line 34

def reset_provider!
  @provider_client = nil
  configure_provider
end

.translate(text:, from: nil, to:, context: nil) ⇒ Object



13
14
15
# File 'lib/polylingo_chat/translator.rb', line 13

def translate(text:, from: nil, to:, context: nil)
  provider_client.translate(text: text, from: from, to: to, context: context)
end