BoxLang 🚀 A New JVM Dynamic Language Learn More...

GoogleCloudTranslation

v1.0.1 Modules

GoogleCloudTranslation

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

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 GoogleCloudStoreage.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.

$ box install GoogleCloudTranslation

No collaborators yet.
 
  • {{ getFullDate("2017-04-06T03:03:13Z") }}
  • {{ getFullDate("2017-08-09T06:05:11Z") }}
  • 2,094
  • 2,827