lokalise/php-lokalise-api
Composer 安装命令:
composer require lokalise/php-lokalise-api
包简介
Lokalise API client
README 文档
README
Client library for Lokalise API 2.0, written with PHP. Full API reference.
Changelog is located here.
Getting started
- PHP 7.4.x or greater is required
- Install LokaliseApiClient using Composer (recommended) or manually
Composer installation
- Get Composer
- Require LokaliseApiClient with
php composer.phar require lokalise/php-lokalise-api - Add the following to your application's main PHP file:
require 'vendor/autoload.php';
Construct LokaliseApiClient
Create and grab your API token at Lokalise profile
$client = new \Lokalise\LokaliseApiClient($apiToken);
Request
Response
/** @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 getNextCursor() // Return next cursor for cursor based pagination hasNextCursor() // Return true if next cursor is present for cursor based pagination
Utils
\Lokalise\Utils:: base64FileEncode($filePath) // Get base64 encoded contents with leading mime type
Exceptions and errors
\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
Best practice
$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 }
Rate limits
Access to all endpoints is limited to 6 requests per second from 14 September, 2021. This limit is applied per API token and per IP address. If you exceed the limit, a 429 HTTP status code will be returned and the corresponding exception will be raised that you should handle properly. To handle such errors, we recommend an exponential backoff mechanism with a limited number of retries.
Only one concurrent request per token is allowed.
lokalise/php-lokalise-api 适用场景与选型建议
lokalise/php-lokalise-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.36M 次下载、GitHub Stars 达 18, 最近一次更新时间为 2018 年 10 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「api」 「lokalise」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lokalise/php-lokalise-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lokalise/php-lokalise-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lokalise/php-lokalise-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony Lokalise Translation Provider Bridge
A Symfony Lokalise translation bundle
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Automatically translate and review your content via Lokalise.
Handle Lokalise webhooks in a Laravel app
统计信息
- 总下载量: 2.36M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 9
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-02