Coder Social home page Coder Social logo

php-lokalise-api's Introduction

Lokalise API v2 official PHP library

Client library for Lokalise API 2.0, written with PHP. Full API reference.

Changelog is located here.

Getting started

  1. PHP 7.4.x or greater is required
  2. Install LokaliseApiClient using Composer (recommended) or manually

Composer installation

  1. Get Composer
  2. Require LokaliseApiClient with php composer.phar require lokalise/php-lokalise-api
  3. 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

Comments

Contributors

Files

Keys

Languages

Payment Cards

Projects

Queued Processes

Screenshots

Snapshots

Tasks

Teams

Team Users

Team User Groups

Translations

Translation Providers

Orders

Webhooks

Branches

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.

php-lokalise-api's People

Contributors

akankov avatar andrewi-wd avatar ansisblodnieks avatar beinarovic avatar masuichig avatar motassem-mk avatar nickustinov avatar ronnylv avatar thelevti avatar yarlson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-lokalise-api's Issues

Do not use "list" as method name

All classes in the "API" namespace have a method named "list".

This causes an error lower to PHP5.6: Tag 3.0.0 is allowed to work with php5.6 but have "list"

PHP Parse error:  syntax error, unexpected 'list' (T_LIST), expecting '('

Because "list" is a keyword in PHP, it could not be used as a method name.

See Documentation

Laravel 8 support

Laravel 8 requires guzzlehttp/guzzle ^7.0.1

Problem 1
    - php-http/guzzle6-adapter[dev-master, v1.0.0, ..., v1.1.1, v2.0.0, ..., v2.0.1] require guzzlehttp/guzzle ^6.0 -> found guzzlehttp/guzzle[6.0.0, ..., 6.5.x-dev] but it conflicts with your root composer.json require (^7.0.1).
    - lokalise/php-lokalise-api 3.1.0 requires php-http/guzzle6-adapter ^1.0 || ^2.0 -> satisfiable by php-http/guzzle6-adapter[v1.0.0, v1.1.0, v1.1.1, v2.0.0, v2.0.1, 2.x-dev (alias of dev-master)].
    - php-http/guzzle6-adapter 2.x-dev is an alias of php-http/guzzle6-adapter dev-master and thus requires it to be installed too.
    - Root composer.json requires lokalise/php-lokalise-api 3.1.* -> satisfiable by lokalise/php-lokalise-api[3.1.0].

Open up guzzle client setter

Would it be possible to make the Lokalise\Endpoints\Endpoints::setClient method public? Otherwise this method makes no sense and is not really usable. I would like to configure my own guzzle client with several middlewares and custom config (logging, timeout, etc.) so that it is used by all the Endpoint implementations.

Thank you in advance.

Suggestion :: Move similar URI parts in a single method

Hi Team,
While going through all the Classes under the namespace \Lokalise\Endpoints almost every method has the same URI referenced. I believe it will be good if it is moved in a single method under the same Class to build the base of the URI and calling the method inside the Guzzle->request() call.

Example :: Class Webhooks

  1. URI under the method create = "projects/$projectId/webhooks/$webhookId"
  2. URI under the method retrieve = "projects/$projectId/webhooks/$webhookId"

Upgrade Guzzle7 adapter to 1.0

Your library fixes php-http/guzzle7-adapter to 0.1.1. Can you upgrade it to "^1.0" ? There are basically no changes between 0.1 and 1.0.

Base endpoint is not valid

Lokalise seems to change the base URL for request and https://api.lokalise.co/api2/ does not work for us anymore. We did not find any information about it in the change log of API but we needed to change base URL to https://api.lokalise.com/api2/.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.