romaten1/php-lokalise-api

Lokalise API 客户端

3.2 2020-12-25 07:33 UTC

README

这是 Lokalise API 2.0 的客户端库,用 PHP5 编写。提供完整的 API 参考。[完整 API 参考](https://lokalise.com/api2docs/curl/).

变更日志位于 [此处](https://github.com/romaten1/php-lokalise-api/blob/HEAD/CHANGELOG.md).

入门指南

  1. 需要 PHP 7.2.x 或更高版本
  2. 使用 Composer (推荐) 或手动安装 LokaliseApiClient

Composer 安装

  1. 获取 [Composer](https://getcomposer.org.cn/)
  2. 使用 php composer.phar require lokalise/php-lokalise-api 安装 LokaliseApiClient
  3. 将以下内容添加到应用程序的主 PHP 文件中: require 'vendor/autoload.php';

构造 LokaliseApiClient

Lokalise 个人资料 中创建并获取您的 API 令牌

$client = new \Lokalise\LokaliseApiClient($apiToken);

请求

评论

贡献者

文件

语言

支付卡

项目

队列中的进程

屏幕截图

快照

任务

团队

团队用户

团队用户组

翻译

翻译提供者

订单

Webhooks

响应

/** @var \Lokalise\LokaliseApiResponse $response */
$response = $client->languages->listSystem();

$response->
    headers                // Associative array of Lokalise headers received
    getContent()           // Return response data as associative array
    __toArray()            // getContent() alias. Return response data as associative array
    __toString()           // Return JSON encoded response data
    getTotalCount()        // Return total count of filtered items in List methods
    getPageCount()         // Return count of pages in List methods (based on limit parameter)
    getPaginationLimit()   // Return pagination limit used in the request
    getPaginationPage()    // Return current page of the request

工具

\Lokalise\Utils::
    base64FileEncode($filePath)    // Get base64 encoded contents with leading mime type

异常和错误

\Lokalise\Exceptions\LokaliseApiException       // Exception throws when Lokalise API can't be reached using Guzzle
\Lokalise\Exceptions\LokaliseResponseException  // Exception throws when Lokalise API responded with a single error

最佳实践

$client = new \Lokalise\LokaliseApiClient($apiToken);

try {
    $language = $client->languages->retrieve($projectId, $languageId)->getContent();
} catch (\Lokalise\Exceptions\LokaliseApiException $e) {
    // try again later or break
} catch (\Lokalise\Exceptions\LokaliseResponseException $e) {
    // Request cannot be completed. More details in {$e->getCode()} and {$e->getMessage()}
    // break
}