Translator API - Ruby Gem

Translator is a simple tool for translating text. It returns the translated text.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_translator'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_translator

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_translator'

# Initialize the client
client = APIVerve::Translator::Client.new(api_key: "YOUR_API_KEY")

# Make a request
response = client.execute({
  text: "I'm so excited that tomorrow is going to be sunny! Can't wait!",
  source: "en",
  target: "es"
})

# Print the response
puts response

Error Handling

begin
  response = client.execute({ text: "I'm so excited that tomorrow is going to be sunny! Can't wait!", source: "en", target: "es" })
  puts response["data"]
rescue APIVerve::Translator::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Translator::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

# Enable debug logging
client = APIVerve::Translator::Client.new(
  api_key: "YOUR_API_KEY",
  debug: true
)

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "sourceLang": "en",
    "targetLang": "es",
    "translatedText": "¡Qué emoción que mañana hará sol! ¡Qué ganas!"
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.