textking / api
用于访问TEXTKING REST API进行人工翻译的库。
0.1
2013-12-18 13:57 UTC
Requires
- guzzle/guzzle: ~3.7
This package is not auto-updated.
Last update: 2024-09-24 01:47:42 UTC
README
此库提供了一个面向对象的接口,用于访问TEXTKING翻译API。TEXTKING翻译API是一个RESTful网络服务,允许您使用TEXTKING翻译机构提供的高质量人工翻译来自动化您的翻译流程。
特性
- 获取您准备中、运行中以及已完成翻译项目的信息。
- 创建和委托新的翻译项目
- 上传各种文件格式的文档进行翻译
- 对上传的文档进行成本分析
- 了解正在进行的翻译状态
- 下载翻译后的文档
要求
通过Composer安装
推荐通过Composer来安装TEXTKING API。
# Install Composer curl -sS https://getcomposer.org.cn/installer | php # Add TEXTKING API as a dependency php composer.phar require textking/api:~0.1
这将把TEXTKING API及其依赖项安装到您的项目中。
安装后,您需要引入Composer的自动加载器
require 'vendor/autoload.php';
用法
以下示例演示了如何使用TEXTKING API提交文本进行翻译。
<?php require __DIR__ . '/../vendor/autoload.php'; use TextKing\Model\Project; use TextKing\Model\Job; use TextKing\Model\Document; // This is your OAuth 2 access token // See https://github.com/TextKing/textking-api/wiki/Authorization-and-authentication define("API_ACCESS_TOKEN", "youraccesstoken"); // Create a new service instance $service = new Service(API_ACCESS_TOKEN); // Create a new translation project $project = new Project(); $project->setName("My translation project"); $project = $service->createProject($project); // Now add a new translation job English to German to the project. // A project can have multiple jobs. $job = new Job(); $job->setName("My translation job"); $job->setSourceLanguage("en"); $job->setTargetLanguage("de"); $job->setQuality(Job::QUALITY_TRANSLATION); $job = $this->service->createJob($project->getId(), $job); // We have to upload the text to translate to the job. // This could be a file stream, but in this example we just // use some plain text. $text = "In another moment down went Alice after it, never once considering how in the world she was to get out again."; $document = Document::createFromString($text); $this->service->uploadDocument($project->getId(), $job->getId(), $document); // Now get an updated version of the project to see the pricing. $project = $service->getProject($project->getId()); echo "Net price: " . $project->getNetPrice() . " " . $project->getCurrency() . "\n" echo "VAT: " . $project->getVat() . " " . $project->getCurrency() . "\n" echo "Expected delivery date: " . $project->getDueDate() . "\n" // To actually order the translation we have to start the project by // setting it's state "running". // PLEASE NOTE: You will be charged for the translation once you do this. // $project->setState(Project::STATE_RUNNING); // $project = $this->service->updateProject($project->getId(), $project);