romaten1 / php-lokalise-api
Lokalise API client
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: 2025-03-02 01:28:05 UTC
README
Client library for Lokalise API 2.0, written with PHP5. Full API reference.
Changelog is located here.
Getting started
- PHP 7.2.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
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 }