Giter Site home page Giter Site logo

scala-translate-api's Introduction

Scala-translate-API

Scala-translate-API is a very simple API for some of the online translation APIs such as Bing Translate API or Google Translate. So far, given that the future of Google Translate is unclear, only the Bing Translate API is supported.

The API is currently fully synchronous, but using the asynchronous capabilities of the Dispatch library is one of the TODO items for future releases. For the time being, please encapsulate the API calls within a simple actor to obtain asynchronous capabilities.

Bing API Usage

The Bing API implementation is currently based on the HTTP version of the Microsoft Translator V2 as described here: http://msdn.microsoft.com/en-us/library/ff512419.aspx. Only the Microsoft.Translator.Translate method (http://msdn.microsoft.com/en-us/library/ff512419.aspx) is supported.

Please note that Bing requires its own application id in order to use the translation API.

API usage:

val translator = new Translate with Bing with new BingConfig {
	val appId = "your-bing-app-id-goes-here"
}
val result = translator.translate("text to translate", English, Spanish)

Translation results are returned as an Either object, where Left indicates an error, wrapped in a TranslationFailure object and Right indicates success, wrapped in a TranslationResult object. Therefore, results can be processed as follows:

result match {
  case Left(TranslationFailure(_, message, _)) => println("There was an error: " + message)
  case Right(TranslationResult(text)) => println("translation result: " + text)
}

Project setup

The library is cross-compiled for Scala 2.9.0 and 2.9.0-1, and can be declared as a dependency in your project with SBT or Maven.

Using SBT:

val renalias_repo = "Renalias.net Maven Repository" at "http://phunkphorce.github.com/maven"
val translate_lib = "net.renalias" %% "scala-translate-api" % "1.0-SNAPSHOT"

Using Maven, first declare the repository:

<repository>
  <id>renaliasnetRepository</id>
  <name>renalias.net Repository</name>
  <url>http://phunkphorce.github.com/maven/</url>
</repository>

And then declare the dependency:

<dependency>
  <groupId>net.renalias</groupId>
  <artifactId>scala-translate-api_2.9.0-1</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>

scala-translate-api's People

Contributors

oscarrenalias avatar

Watchers

James Cloos avatar Aayush Kumar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.