Code Monkey home page Code Monkey logo

googlecloudtranslation's Introduction

GoogleCloudTranslation

Implements Google Cloud Translation Api for Coldbox Coldfusion See https://cloud.google.com/translate/ as well https://cloud.google.com/translate/docs/

You might want to try instead of this Api the Deepl Api which delivers much better results https://github.com/akitogo/cbDeepl

The API supports two authentication methods: API Key or oAuth2 Currently API Key only is supported

Installation

You will need a Google Account to work with this API As well you need to set up Google Cloud APIs See here: https://cloud.google.com/translate/docs/getting-started

This API can be installed as standalone or as a ColdBox Module. Either approach requires a simple CommandBox command:

box install GoogleCloudTranslation

Then follow either the standalone or module instructions below.

Standalone

This API will be installed into a directory called GoogleCloudTranslation and then the API can be instantiated via new GoogleCloudTranslation.models.GoogleCloudTranslation() with the following constructor arguments:

<cfargument name="apiKey" 			required="true">

ColdBox Module

This package also is a ColdBox module as well. The module can be configured by adding GoogleApiKey in your application configuration file: config/Coldbox.cfc with the following settings:

	settings = {

		// Your Google API Key
		GoogleApiKey = "",
		
		// Your settings....

	};

Then you can leverage the API CFC via the injection DSL: GoogleTranslation@GoogleCloudTranslation

Usage

/**
* A normal ColdBox Event Handler
*/
component{
	property name="ggl" inject="GoogleTranslation@GoogleCloudTranslation";
	
	function index(event,rc,prc){

		
		// returns an array of supported language codes
		var l=ggl.getLanguages();
		writeDump(l);
		
		// returns true
		writeDump(ggl.isSupportedLanguage('de'));
		
		// returns false
		writeDump(ggl.isSupportedLanguage('XX'));

		// returns translated text as string
		var t=ggl.translate('Italy, Tuscany, View out of window to the garden of land house','en','de');
		writeDump(t);
		
		// detects language of a text
		// returns a struct with three values
		var t=ggl.detect('Italy, Tuscany, View out of window to the garden of land house.');
		writeDump(t);

		var t=ggl.detect('Dies ist ein kurzer deutscher Text');
		writeDump(t);		

		abort;
	}
}

Written by

www.akitogo.com

Disclaimer

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.

googlecloudtranslation's People

Contributors

gunnarlieb avatar

Watchers

 avatar  avatar  avatar

googlecloudtranslation's Issues

Usage w/out coldbox

Hi,
I am wondering if there is a way to use it without using the coldbox?

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.