Class: Fastlane::Helper::Providers::AnthropicProvider

Inherits:
BaseProvider
  • Object
show all
Defined in:
lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb

Overview

Provider implementation for Anthropic Claude translation API. Uses the Claude models for high-quality text translation with strong reasoning capabilities.

Constant Summary collapse

DEFAULT_MODEL =

Default model for Anthropic translations

'claude-sonnet-4.5'.freeze
DEFAULT_MAX_TOKENS =

Default maximum tokens for translation response

1024
DEFAULT_TEMPERATURE =

Default temperature for translation generation (0.5 = balanced creativity)

0.5
DEFAULT_TIMEOUT =

Default request timeout in seconds

60

Constants inherited from BaseProvider

BaseProvider::ANDROID_CHAR_LIMIT

Instance Attribute Summary

Attributes inherited from BaseProvider

#config_errors, #params

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseProvider

#valid?

Constructor Details

#initialize(params) ⇒ AnthropicProvider

Initializes the Anthropic provider with configuration parameters. Sets up the Anthropic::Client with appropriate credentials and timeout.

Parameters:

  • params (Hash)

    Configuration parameters for the provider



59
60
61
62
63
64
65
66
67
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 59

def initialize(params)
  super

  timeout = @params[:request_timeout] || DEFAULT_TIMEOUT
  @client = Anthropic::Client.new(
    api_key: credential(:api_token),
    timeout: timeout.to_i
  )
end

Class Method Details

.display_nameString

Returns the human-readable display name for the provider.

Returns:

  • (String)

    Human-readable name



32
33
34
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 32

def self.display_name
  'Anthropic Claude'
end

.optional_paramsHash

Returns a hash of optional parameter definitions for this provider.

Returns:

  • (Hash)

    Optional parameter definitions



46
47
48
49
50
51
52
53
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 46

def self.optional_params
  {
    model_name: { default: DEFAULT_MODEL, description: 'Anthropic model to use', env: 'ANTHROPIC_MODEL_NAME' },
    max_tokens: { default: DEFAULT_MAX_TOKENS, description: 'Maximum tokens in response', env: 'ANTHROPIC_MAX_TOKENS' },
    temperature: { default: DEFAULT_TEMPERATURE, description: 'Sampling temperature (0-1)', env: 'ANTHROPIC_TEMPERATURE' },
    request_timeout: { default: DEFAULT_TIMEOUT, description: 'Request timeout in seconds', env: 'ANTHROPIC_REQUEST_TIMEOUT' }
  }
end

.provider_nameString

Returns the provider identifier string.

Returns:

  • (String)

    Provider identifier



25
26
27
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 25

def self.provider_name
  'anthropic'
end

.required_credentialsArray<Symbol>

Returns the list of required credential symbols for this provider.

Returns:

  • (Array<Symbol>)

    Array of required credential keys



39
40
41
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 39

def self.required_credentials
  [:api_token]
end

Instance Method Details

#translate(text, source_locale, target_locale, glossary_terms: {}) ⇒ String?

Translates text from source locale to target locale using Anthropic’s API.

Parameters:

  • text (String)

    The text to translate

  • source_locale (String)

    Source language code (e.g., ‘en’, ‘de’)

  • target_locale (String)

    Target language code (e.g., ‘es’, ‘fr’)

  • glossary_terms (Hash) (defaults to: {})

    Optional glossary { source_term => target_translation }

Returns:

  • (String, nil)

    Translated text or nil on error



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 84

def translate(text, source_locale, target_locale, glossary_terms: {})
  system_instruction = build_system_instruction(
    source_locale, target_locale,
    glossary_terms: glossary_terms,
    platform: @params[:platform]
  )
  response = @client.messages.create(build_create_params(system_instruction, text))
  enforce_android_limit(extract_text_from_response(response))
rescue StandardError => e
  UI.error "Anthropic provider error: #{e.message}"
  nil
end

#validate_config!void

This method returns an undefined value.

Validates the provider configuration. Ensures that the required api_token credential is present.



73
74
75
# File 'lib/fastlane/plugin/translate_gpt_release_notes/helper/providers/anthropic_provider.rb', line 73

def validate_config!
  require_credential(:api_token)
end