Class: RosettAi::Documentation::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/documentation/translator.rb

Overview

Produces draft translations of documentation files using the Claude API.

Reads source documentation, sends to API with a translation prompt, and writes the result to doc/locales/locale/.

Constant Summary collapse

MODEL =

Returns AI model used for documentation translation.

Returns:

  • (String)

    AI model used for documentation translation.

'claude-sonnet-4-20250514'

Instance Method Summary collapse

Constructor Details

#initialize(doc_dir: nil) ⇒ Translator

Returns a new instance of Translator.



19
20
21
# File 'lib/rosett_ai/documentation/translator.rb', line 19

def initialize(doc_dir: nil)
  @doc_dir = doc_dir || RosettAi.root.join('doc')
end

Instance Method Details

#translate(source_file, from:, to:) ⇒ void

This method returns an undefined value.

Translate documentation to the target locale.

Parameters:

  • source_file (Object)

    the source file

  • from (Object)

    the from

  • to (Object)

    the to



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rosett_ai/documentation/translator.rb', line 29

def translate(source_file, from:, to:)
  content = File.read(source_file)
  basename = File.basename(source_file)

  translated = call_api(content, from: from, to: to)

  output_dir = @doc_dir.join('locales', to)
  FileUtils.mkdir_p(output_dir)
  output_path = output_dir.join(basename)
  File.open(output_path, 'w', 0o644) { |f| f.write(translated) }

  output_path.to_s
end