Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnps committed Nov 20, 2012
0 parents commit f68bc71
Show file tree
Hide file tree
Showing 148 changed files with 28,133 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.*.swp
8 changes: 8 additions & 0 deletions .travis.yml
@@ -0,0 +1,8 @@
language: php
php:
- 5.4
- 5.3
env:
global:
- secure: "AADiWYLLOB6+4pzxN5EQnxlz1wTV1193cv8ROC7MaoyW91M1goshxQWqVjr+\nyYJvoxx/nht/8vNvtxI13B8IcDpVjuATbw/5TUk2obbUHqbcUnsFI1WO/HyN\nxtrcWuKCB0vU6scChzubQiMR8iJYWTG59x+BjLUakjQGlcWnywA="
- GENGO_PUBKEY='pubkeyfortests'
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Copyright (c) 2009-2012, myGengo, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of myGengo, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 changes: 25 additions & 0 deletions README.md
@@ -0,0 +1,25 @@
Gengo PHP Library (for the [Gengo API](http://gengo.com/))
==========================================================================================================================
Translating your tools and products helps people all over the world access them; this is, of course, a
somewhat tricky problem to solve. **[Gengo](http://gengo.com/)** is a service that offers human-translation
(which is often a higher quality than machine translation), and an API to manage sending in work and watching
jobs. This is a PHP interface to make using the API simpler (some would say incredibly easy).

This package contains both a client library for accessing the Gengo Translate API, as well as some example code showing how to
use the library.

Full documentation **[is here.](http://developers.gengo.com)**

Basic configuration
---------------------------------------------------------------------------------------------------------------------------
When using this library, please be sure to check config.ini and ensure that baseurl is set to use the environment that you match your API keys.

Question, Comments, Complaints, Praise?
---------------------------------------------------------------------------------------------------------------------------
If you have questions or comments and would like to reach us directly, please feel free to do
so at the following outlets. We love hearing from developers!

Email: api [at] gengo dot com
Twitter: **[@gengo_dev](http://twitter.com/gengoit)**

If you come across any issues, please file them on the **[Github project issue tracker](https://github.com/gengo/gengo-php/issues)**. Thanks!
44 changes: 44 additions & 0 deletions config.ini
@@ -0,0 +1,44 @@
;; api client config file

;; api url (must end with forward slash)
baseurl=http://api.sandbox.mygengo.com/v2/
;; for live API, switch to the following url:
;; baseurl=http://api.mygengo.com/v2/

;; returned format
;; can be json or xml
format=json

;; set to 1 to echo urls and other debug messages; 0 to turn off
debug=1

;; your api public and secret keys
api_key=""
private_key=""

;; -- the following are hard-coded values to simplify testing.
;; -- these are optional and likely won't be needed when your
;; -- application is deployed

;; group_id
;;
;; when translation jobs are submitted with the "as_group" parameter set
;; to 1, a "group_id" parameter is returned with the response. If you
;; set this returned value to the group_id variable below, it will be
;; used to retrieve the respective grouped jobs
group_id=

;; job_id
;; a valid (existing) job_id
;;
;; job ids can be optained by submitting translation jobs
job_id=

;; rev_id
;; a revision id
;;
;; returning a job back to the translator for corrections creates a revision id
rev_id=

;; local timezone @see http://www.php.net/manual/en/timezones.php
timezone=Asia/Tokyo
28 changes: 28 additions & 0 deletions examples/deleteTranslateJob.php
@@ -0,0 +1,28 @@
<?php

/**
* Delete a job already sent into Gengo.
*/

require_once '../init.php';

// TODO: this example assumes you replaced the 3 values below.
$api_key = 'your-public-api-key';
$private_key = 'your private-api-key';
$job_id = 1;

// Get an instance of Job Client
$job_client = Gengo_Api::factory('job', $api_key, $private_key);

// Cancel a job which has not been started by a translator.
$job_client->cancel($job_id);

// Display the server response.
echo $job_client->getResponseBody();

/**
* Typical response:
{"opstat":"ok","response":{}}
*/

?>
27 changes: 27 additions & 0 deletions examples/getAccountBalance.php
@@ -0,0 +1,27 @@
<?php

/**
* Retrieve account balance in credits.
*/

require_once '../init.php';

// TODO: this example assumes you set the 2 values below.
$api_key = 'your-public-api-key';
$private_key = 'your private-api-key';

// Get an instance of an Account Client
$account = Gengo_Api::factory('account', $api_key, $private_key);

// Request the balance.
$account->getBalance();

// Show the server response in depth if you need it.
echo $account->getResponseBody();

/*
* Typical answer:
{"opstat":"ok","response":{"credits":"100.29"}}
*/

?>
27 changes: 27 additions & 0 deletions examples/getAccountStats.php
@@ -0,0 +1,27 @@
<?php

/**
* Retrieves account stats, such as credits spend and date of subscription.
*/

require_once '../init.php';

// TODO: this example assumes you set the 2 values below.
$api_key = 'your-public-api-key';
$private_key = 'your private-api-key';

// Get an instance of an Account Client
$account = Gengo_Api::factory('account', $api_key, $private_key);

// Actually requests the stats.
$account->getStats();

// Display server response.
echo $account->getResponseBody();

/*
* Typical answer: credits spent and date of subscription (as a timestamp).
{"opstat":"ok","response":{"credits_spent":"1095.95","user_since":1234089500}}
*/

?>
37 changes: 37 additions & 0 deletions examples/getServiceLanguagePairs.php
@@ -0,0 +1,37 @@
<?php

/**
* Returns supported translation language pairs, tiers, and credit prices.
*/

require_once '../init.php';

// TODO: this example assumes you set the 2 values below.
$api_key = 'your-public-api-key';
$private_key = 'your private-api-key';

// Get an instance of an Service Client
$service = Gengo_Api::factory('service', $api_key, $private_key);

// Request the language pairs.
$service->getLanguagePair();

// Display server response.
echo $service->getResponseBody();

/*
* Typical partial response:
{"opstat":"ok","response":[
{"lc_src":"de","lc_tgt":"en","tier":"standard","unit_price":"0.0500"},
{"lc_src":"de","lc_tgt":"en","tier":"pro","unit_price":"0.1000"},
{"lc_src":"de","lc_tgt":"en","tier":"ultra","unit_price":"0.1500"},
{"lc_src":"en","lc_tgt":"de","tier":"standard","unit_price":"0.0500"},
{"lc_src":"en","lc_tgt":"de","tier":"pro","unit_price":"0.1000"},
{"lc_src":"en","lc_tgt":"de","tier":"ultra","unit_price":"0.1500"},
{"lc_src":"en","lc_tgt":"de","tier":"machine","unit_price":"0.0000"},
{"lc_src":"en","lc_tgt":"es","tier":"standard","unit_price":"0.0500"},
...
]}
*/

?>
38 changes: 38 additions & 0 deletions examples/getServiceLanguages.php
@@ -0,0 +1,38 @@
<?php

/**
* Returns a list of supported languages and their language codes.
*/

require_once '../init.php';

// TODO: this example assumes you set the 2 values below.
$api_key = 'your-public-api-key';
$private_key = 'your private-api-key';

// Get an instance of an Service Client
$service = Gengo_Api::factory('service', $api_key, $private_key);

// Request the languages.
$service->getLanguages();

// Display server response.
echo $service->getResponseBody();

/**
* Typical response: a list of language, their name in English and in the locale
* itself, their language code (RFC-4656) and the unit type (word or character).
{"opstat":"ok","response":[
{"language":"English","localized_name":"English","lc":"en","unit_type":"word"},
{"language":"Japanese","localized_name":"\u65e5\u672c\u8a9e","lc":"ja","unit_type":"character"},
{"language":"Spanish (Spain)","localized_name":"Espa\u00f1ol","lc":"es","unit_type":"word"},
{"language":"Chinese (Simplified)","localized_name":"\u4e2d\u6587","lc":"zh","unit_type":"character"},
{"language":"German","localized_name":"Deutsch","lc":"de","unit_type":"word"},
{"language":"French","localized_name":"Fran\u00e7ais","lc":"fr","unit_type":"word"},
{"language":"Italian","localized_name":"Italiano","lc":"it","unit_type":"word"},
{"language":"Portuguese (Brazil)","localized_name":"Portugu\u00eas Brasileiro","lc":"pt-br","unit_type":"word"},
{"language":"Spanish (Latin America)","localized_name":"Espa\u00f1ol (Am\u00e9rica Latina)","lc":"es-la","unit_type":"word"},
{"language":"Portuguese (Europe)","localized_name":"Portugu\u00eas Europeu","lc":"pt","unit_type":"word"}]}
*/

?>
51 changes: 51 additions & 0 deletions examples/getServiceQuote.php
@@ -0,0 +1,51 @@
<?php

/**
* Returns credit quote and unit count for text based on content, tier, and
* language pair for job or jobs submitted.
*/

require_once '../init.php';

// TODO: this example assumes you set the 2 values below.
$api_key = 'your-public-api-key';
$private_key = 'your private-api-key';

// Get an instance of an Service Client
$service = Gengo_Api::factory('service', $api_key, $private_key);

$job1 = array(
'type' => 'text',
'body_src' => 'plop!',
'lc_src' => 'en',
'lc_tgt' => 'es',
'tier' => 'standard',
);

$job2 = array(
'type' => 'text',
'body_src' => 'plop plop!',
'lc_src' => 'en',
'lc_tgt' => 'es',
'tier' => 'pro',
);

// The parameter is an array of jobs. If you set custom keys, they will be
// mirrored in the response. Otherwise, default numerical keying applies. This
// helps to keep track of which job corresponds to which quote.
$jobs = array("key 1" => $job1, "key 2" => $job2);

// Request quotes.
$service->quote($jobs);

// Display server response.
echo $service->getResponseBody();

/**
* Typical response: a list with unit count and credits the job would cost.
{"opstat":"ok","response":{"jobs":{
"key 1":{"unit_count":1,"credits":0.05},
"key 2":{"unit_count":2,"credits":0.2}}}}j
*/

?>
32 changes: 32 additions & 0 deletions examples/getTranslateJobComments.php
@@ -0,0 +1,32 @@
<?php

/**
* Retrieves the comment thread for a job.
*/

require_once '../init.php';

// TODO: this example assumes you replaced the 3 values below.
$api_key = 'your-public-api-key';
$private_key = 'your private-api-key';
$job_id = 1;

// Get an instance of Job Client
$job_client = Gengo_Api::factory('job', $api_key, $private_key);

// Get all the comments for this job.
$job_client->getComments($job_id);

// Display the server response.
echo $job_client->getResponseBody();

/**
* Typical response:
{"opstat":"ok","response":{"thread":[
{"body":"By the way, the context of this text is a game for kids!","author":"customer","ctime":1313498703},
{"body":"I see. So I guess I'll have to take care of vocabulary.","author":"worker","ctime":1313498803}
]}}
*/

?>

30 changes: 30 additions & 0 deletions examples/getTranslateJobFeedback.php
@@ -0,0 +1,30 @@
<?php

/**
* Retrieves the feedback you have submitted for a particular job.
*/

require_once '../init.php';

// TODO: this example assumes you replaced the 3 values below.
$api_key = 'your-public-api-key';
$private_key = 'your private-api-key';
$job_id = 1;

// Get an instance of Job Client
$job_client = Gengo_Api::factory('job', $api_key, $private_key);

// Get the feedback.
$job_client->getFeedback($job_id);

// Display the server response.
echo $job_client->getResponseBody();

/**
* Typical response: a list of revisions id and their timestamp.
{"opstat":"ok","response":{"feedback":{"rating":"3.0","for_translator":"Thanks, nice translation."}}}
*/

?>


0 comments on commit f68bc71

Please sign in to comment.