romaten1 / php-lokalise-api
Lokalise API 客户端
3.2
2020-12-25 07:33 UTC
Requires
- php: ~7.2 || ~8.0
- ext-fileinfo: *
- ext-json: *
- php-http/guzzle7-adapter: ^0.1.1
Requires (Dev)
- guzzlehttp/psr7: ^1.2
- php-http/mock-client: ^1.0
- phpunit/phpunit: ^8.0 || ^9.0
This package is not auto-updated.
Last update: 2024-09-28 23:27:32 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).
入门指南
- 需要 PHP 7.2.x 或更高版本
- 使用 Composer (推荐) 或手动安装 LokaliseApiClient
Composer 安装
- 获取 [Composer](https://getcomposer.org.cn/)
- 使用
php composer.phar require lokalise/php-lokalise-api
安装 LokaliseApiClient - 将以下内容添加到应用程序的主 PHP 文件中:
require 'vendor/autoload.php';
构造 LokaliseApiClient
在 Lokalise 个人资料 中创建并获取您的 API 令牌
$client = new \Lokalise\LokaliseApiClient($apiToken);
请求
响应
/** @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 }