![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Ruby Library for the languagelayer API, powerful language detection, https://languagelayer.com/
Offering a uniquely simple way to automate language detection using any programming language, accurate, efficient, and lightning fast.
Add this line to your application's Gemfile:
gem 'languagedetection'
And then execute:
$ bundle
Or install it yourself as:
$ gem install languagedetection
Before using the languagelayer API client you have to setup your account and obtain your API Access Key.
You can get it by signing up at https://languagelayer.com/product.
All endpoints in the public API is available through this library.
The general API is documented here: https://languagelayer.com/documentation.
You can find parameters, result set definitions and status codes documented here as well.
In the examples directory you can find demos and samples of general usage of all the API functions.
First we require the module
require 'languagedetection'
Second we instantiate the client
@client = LanguageLayer::Client.new( [access_key] )
Your unique key that you can find on the dashboard of your account under the languagelayer account.
Boolean value to indicate if the calls to the API should use a secure protocol or insecure (HTTP/HTTPS). Defaults to false (HTTP, insecure).
Takes a query string and detects the language.
First we get a reference to the string that needs to be detected
query = 'Good afternoon, sir. How are you today?'
Second we define an options object. All the options are documented here: https://languagelayer.com/documentation
options = LanguageLayer::DetectOptions.new()
We then place the actual call to the API, passing in the email we wish to check and the options we defined above.
response = @client.detect( [query] [, options] )
If we pass the email Good afternoon, sir. How are you today?
as the query argument above, we get the following result:
{
"success": true,
"results":[
{
"language_code": "en",
"language_name": "English",
"probability": 12.141682269266,
"percentage": 100,
"reliable_result": true
}
]
}
Takes an array of strings and detects the language with a corresponding list of detections for each string.
First we get a reference to the string that needs to be detected
query: [
'Good afternoon, how are you today?',
'Guten Tag mein Herr, wie geht es Ihnen?',
'Buenos días señor, cómo está hoy?'
],
Second we define an options object.
In this example we are passing the show_query
option so each of elements in the result will contain the original query.
All the options are documented here: https://languagelayer.com/documentation
options = LanguageLayer::BatchOptions.new({
show_query: 1
})
We then place the actual call to the API, passing in the email we wish to check and the options we defined above.
response = @client.batch( [query] [, options] )
{
"success": true,
"results": [
[
{
"query": "Good afternoon, how are you today?",
"language_code": "en",
"language_name": "English",
"probability": 12.141682269266,
"percentage": 100,
"reliable_result": true
}
],
[
{
"query": "Guten Tag mein Herr, wie geht es Ihnen?",
"language_code": "de",
"language_name": "German",
"probability": 23.045066185021,
"percentage": 100,
"reliable_result": false
}
],
[
{
"query": "Buenos días señor, cómo está hoy?",
"language_code": "es",
"language_name": "Spanish",
"probability": 14.560273752505,
"percentage": 100,
"reliable_result": false
},
{
"query": "Buenos días señor, cómo está hoy?",
"language_code": "pt",
"language_name": "Portuguese",
"probability": 13.98519485076,
"percentage": 96.05035652818,
"reliable_result": false
},
{
"query": "Buenos días señor, cómo está hoy?",
"language_code": "gl",
"language_name": "Galician",
"probability": 13.585199932687,
"percentage": 93.30319033562,
"reliable_result": false
}
]
]
}
Returns the list of Supported Languages, similar to the list found here:
https://languagelayer.com/languages
For this endpoint, we dont pass any primary argument, just the control options, so we define an options object.
There are currently no options for the languages
endpoint, so we could omit it, however we use it with an empty options object here to stay aligned with the standard for the library.
options = LanguageLayer::LanguagesOptions.new()
We then place the actual call to the API, passing in the email we wish to check and the options we defined above.
response = @client.languages([options] )
{
"success": true,
"languages": [
{
"language_code": "en",
"language_name": "English"
},
{
"language_code": "af",
"language_name": "Afrikaans"
},
{
"language_code": "ar",
"language_name": "Arabic"
},
...
]
}
In the [rootdir]/example directory there is a fully functional application which runs all requests against all the endpoints in the API, the examples above can be seen there as source code.
The example application uses a process.env variable to hold the access key.
The tests are written using the rspec testing library.
RSpec http://rspec.info/
In order to run the tests, the following environment variables needs to be set:
ACCESS_KEY = [access_key]
Need any assistance? Get in touch with Customer Support.
Stay up to date by following @apilayernet on Twitter.
All usage of the languagelayer website, API, and services is subject to the languagelayer Terms & Conditions and all annexed legal documents and agreements.
Peter Andreas Moelgaard (GitHub, Twitter)
Licensed under the The MIT License (MIT)
Copyright (©) 2016 Peter Andreas Moelgaard & apilayer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Unknown package
We found that languagedetection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.