Language Detector API - Ruby Gem

Language Detector is a simple tool for detecting the language of a text. It returns the language code and the confidence level.

Installation

Add this line to your application's Gemfile:

gem 'apiverve_languagedetector'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install apiverve_languagedetector

Getting Started

Get your API key at APIVerve

Basic Usage

require 'apiverve_languagedetector'

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

# Make a request
response = client.execute({ text: "esta es una frase en español. esta API puede detectar fácilmente el idioma" })

# Print the response
puts response

Error Handling

begin
  response = client.execute({ text: "esta es una frase en español. esta API puede detectar fácilmente el idioma" })
  puts response["data"]
rescue APIVerve::Languagedetector::ValidationError => e
  puts "Validation error: #{e.errors.join(', ')}"
rescue APIVerve::Languagedetector::APIError => e
  puts "API error: #{e.message}"
  puts "Status code: #{e.status_code}"
end

Debug Mode

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

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "primaryLanguage": "spanish",
    "primaryCode": "es",
    "confidenceLevel": "medium",
    "detectedLanguages": [
      {
        "language": "spanish",
        "confidence": 0.38471794871794873,
        "code": "es"
      },
      {
        "language": "portuguese",
        "confidence": 0.2946153846153846,
        "code": "pt"
      },
      {
        "language": "danish",
        "confidence": 0.2464615384615384,
        "code": "da"
      }
    ]
  }
}

Documentation

For more information, visit the API Documentation.

Support

License

This gem is available under the MIT License.