Class: GAI18n::LocaleFile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gai18n/locale_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale) ⇒ LocaleFile

Returns a new instance of LocaleFile.



10
11
12
13
14
# File 'lib/gai18n/locale_file.rb', line 10

def initialize(locale)
  @locale = locale
  @assistant_id = GAI18n.config.openai_assistant_id
  @skip_keys = []
end

Instance Attribute Details

#assistant_idObject (readonly)

Returns the value of attribute assistant_id.



5
6
7
# File 'lib/gai18n/locale_file.rb', line 5

def assistant_id
  @assistant_id
end

#localeObject (readonly)

Returns the value of attribute locale.



5
6
7
# File 'lib/gai18n/locale_file.rb', line 5

def locale
  @locale
end

#skip_keysObject (readonly)

Returns the value of attribute skip_keys.



5
6
7
# File 'lib/gai18n/locale_file.rb', line 5

def skip_keys
  @skip_keys
end

Instance Method Details

#translate(skip_keys = []) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gai18n/locale_file.rb', line 16

def translate(skip_keys = [])
  @skip_keys = skip_keys
  write_file and return if translatable_key_values.empty?
  thread = GAI18n::OpenAI::Thread.create
  OpenAI::Message.create thread_id: thread.id, content: message_content
  run = OpenAI::Run.create assistant_id: assistant_id, thread_id: thread.id
  run = run.wait_until_done
  if run.requires_action?
    run.accept_translations.each {|translation| insert translation}
    write_file
    locale_file = self.class.new locale
    locale_file.translate(skip_keys + translatable_keys)
  else
    msg = ['Either the Run took too long or received incorrect',
           "Run status from OpenAI: #{run.status}"].join(' ')
    raise IncorrectResponseError, msg
  end
end