PHPackages                             autoborna/transifex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. autoborna/transifex

ActiveLibrary[API Development](/categories/api)

autoborna/transifex
===================

The Transifex API Package is a wrapper of the Transifex API available for PHP developers

03PHP

Since Sep 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/abbassian/Transifex-API)[ Packagist](https://packagist.org/packages/autoborna/transifex)[ RSS](/packages/autoborna-transifex/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

*This is fork of [archived repository](https://github.com/autoborna/Transifex-API) by [Michael Babker](https://github.com/mbabker). Autoborna use this library and so we decided to maintain it.*

Transifex API Package [![Scrutinizer Code Quality](https://camo.githubusercontent.com/409003065f88035436cde291a809a445a18b2aaa706e2da9ad309abd0853966c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6175746f626f726e612f5472616e73696665782d4150492f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/autoborna/Transifex-API/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/4c16794640665daeb0ac0382fd989bf0ade2d03db5be526662276d9a6860ae7c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6175746f626f726e612f5472616e73696665782d4150492f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/autoborna/Transifex-API/?branch=master) [![Build Status](https://camo.githubusercontent.com/60b114765f251082c1dad67426f11a82b07eaa6d1b2c37c88fc98c6fd9c81bc4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6175746f626f726e612f5472616e73696665782d4150492f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/autoborna/Transifex-API/build-status/master) [![Build Status](https://camo.githubusercontent.com/2fa5d5425446071417193eba81b5bf6c4e08d7294a846c40ac16da218ff45c80/68747470733a2f2f7472617669732d63692e6f72672f6175746f626f726e612f5472616e73696665782d4150492e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/autoborna/Transifex-API)
=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#transifex-api-package----)

[![Latest Stable Version](https://camo.githubusercontent.com/94aa6181de0afec53bcd8ffac29d1051c70e7379f71048d49a9da91b0b5bac5a/68747470733a2f2f706f7365722e707567782e6f72672f6175746f626f726e612f7472616e73696665782f762f737461626c652e737667)](https://packagist.org/packages/autoborna/transifex)[![Total Downloads](https://camo.githubusercontent.com/04fb62d9487867d8e4b46ab9230e0faa142de0e642c4404332d055a6fa288e80/68747470733a2f2f706f7365722e707567782e6f72672f6175746f626f726e612f7472616e73696665782f646f776e6c6f6164732e737667)](https://packagist.org/packages/autoborna/transifex)[![Latest Unstable Version](https://camo.githubusercontent.com/224f540858f3a358346f8ab2966cb02b62a2d7b2bc06a4f9d83af47d4a84b14d/68747470733a2f2f706f7365722e707567782e6f72672f6175746f626f726e612f7472616e73696665782f762f756e737461626c652e737667)](https://packagist.org/packages/autoborna/transifex)[![License](https://camo.githubusercontent.com/1996243e78dbc852db70a3e9dbf2b7823530827eee1bd3b440081118ec1c4762/68747470733a2f2f706f7365722e707567782e6f72672f6175746f626f726e612f7472616e73696665782f6c6963656e73652e737667)](https://packagist.org/packages/autoborna/transifex)

The *Transifex API Package* is a PHP client for accessing the [Transifex API](http://docs.transifex.com/api/).

Requirements
------------

[](#requirements)

- PHP 7.4 or later
- Any [PSR-17 compatible](https://www.php-fig.org/psr/psr-17/) factories
- Any [PSR-18 compatible](https://www.php-fig.org/psr/psr-18/) HTTP client

Installation
------------

[](#installation)

Installation via GIT
--------------------

[](#installation-via-git)

Get the source code from GIT:

```
git clone git://github.com/autoborna/Transifex-API.git
```

Installation via Composer
-------------------------

[](#installation-via-composer)

To include this package in your Composer project, run the following command from the command line:

```
composer require autoborna/transifex
```

Documentation
-------------

[](#documentation)

The Transifex API package provides a PHP interface for interacting with the [Transifex API](https://developers.transifex.com/reference/api-introduction).

### Basic Use

[](#basic-use)

The primary interface for interacting with the Transifex package is the `Transifex` class. This class serves as the API factory and allows developers to manage the options used by the API objects and HTTP connector as well as retrieve instances of the API objects. To create a `Transifex` object, you only need to instantiate it with the appropriate dependencies.

```
use Autoborna\Transifex\ApiFactory;
use Autoborna\Transifex\Config;
use Autoborna\Transifex\Transifex;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;

$client = new ClientInterface(); // or any PSR-18 HTTP client
$requestFactory = new RequestFactoryInterface(); // or any PSR-17 Request factory
$streamFactory = new StreamFactoryInterface(); // or any PSR-17 Stream factory
$uriFactory = new UriFactoryInterface(); // or any PSR-17 URI factory
$config = new Config();
$config->setApiToken('some-api-token');
$config->setOrganization('some-organization');
$config->setProject('some-project');
$transifex = new Transifex($client, $requestFactory, $streamFactory, $uriFactory, $config);
```

[Follow the Transifex documentation on how to get the API Token.](https://developers.transifex.com/reference/api-authentication)

The `Config` object can be also created from environmental variables:

```
use Autoborna\Transifex\Config;
putenv('TRANSIFEX_API_TOKEN=some-api-token');
putenv('TRANSIFEX_ORGANIZATION=some-organization');
putenv('TRANSIFEX_PROJECT=some-project');
$config = Config::fromEnv();
```

To retrieve an instance of an API object, you would use the `get()` method. API objects are named based on the documented sections of the Transifex API. To retrieve an object that can interface with the "resources" API section, you would use the following code:

```
use \Autoborna\Transifex\Connector\Resources;
$resources = $transifex->getConnector(Resources::class);
\assert($resources instanceof Resources);
```

### API Responses

[](#api-responses)

This package returns a [PSR-7 compatible](https://www.php-fig.org/psr/psr-7/) response created by the underlying [PSR-18 HTTP client](https://www.php-fig.org/psr/psr-18/).

This package is not catching Exceptions thrown by the HTTP client so users implementing this package should implement appropriate error handling mechanisms.

An exception of `Autoborna\Transifex\Exception\ResponseException` will be thrown when the response code is &gt; 400. The error message contains the URI, request and response. This simplifies debugging. The Request and Response object can be retreived from this exception.

### Resources

[](#resources)

Resources are the basic files that should be translated.

Get the Resource connector for the bellow examples like so:

```
use Autoborna\Transifex\Connector\Resources;

$resources = $transifex->getConnector(Resources::class);
\assert($resources instanceof Resources);
```

#### Get all resources

[](#get-all-resources)

Docs: [https://developers.transifex.com/reference/get\_resources](https://developers.transifex.com/reference/get_resources)

```
$response = $resources->getAll();
$body     = json_decode($response->getBody()->__toString(), true);
```

#### Create a resource

[](#create-a-resource)

This is a syncronous operation so you get the response rightaway. You need another request to upload a content to this resource though. See the [docs](https://developers.transifex.com/reference/post_resources) for example responses.

For the list of available i18n formats (the third param) trigger [this endpoint](https://developers.transifex.com/reference/get_i18n-formats).

```
$response = $resources->create('Resource A', 'resource-a', 'INI');
$body     = json_decode($response->getBody()->__toString(), true);
```

#### Upload resource content

[](#upload-resource-content)

This is an asynchronous operation so the first request will just add the task to the queue and returns a unique ID See the [docs](https://developers.transifex.com/reference/post_resource-strings-async-uploads). Then we have to poll another endpoint for the status of this task.

```
use Autoborna\Transifex\Promise;
use Autoborna\Transifex\Exception\ResponseException;
use Psr\Http\Message\ResponseInterface;

$response = $resources->uploadContent('resource-a', "something=\"Something\"\nsomething.else=\"Something Else\"\n");
$promise  = $transifex->getApiConnector()->createPromise($response);
$promises = new \SplQueue();
$promise->setFilePath('/some/file.ini'); // In the real world it is useful to map your file to this promise. Useful for later processing.
$promises->enqueue($promise); // In the real world, there would be multiple promises.
usleep(500000); // Give Transifex a 1/2 second so we make 1 request instead of 2.
$transifex->getApiConnector()->fulfillPromises(
    $promises,
    function (ResponseInterface $response, Promise $promise) {
        echo "Resource for {$promise->getFilePath()} was uploaded successfully";
    },
    function (ResponseException $exception, Promise $promise) {
        echo "Resource upload for {$promise->getFilePath()} failed with {$exception->getMessage()}";
    }
);
```

The polling for promise status happens automatically every 0.5 seconds.

As fetching for the promise status happens asynchronously and the order of processed promises is not cretain there are callbacks for your implementation to react on successful and failed statuses. Another perk is that further processing is not blocked until all promisses are resolved.

#### Deleting a resource

[](#deleting-a-resource)

Docs: [https://developers.transifex.com/reference/delete\_resources-resource-id](https://developers.transifex.com/reference/delete_resources-resource-id)

```
$response = $resources->delete('resource-a');
```

### Translations

[](#translations)

Translations translate the resource content to another languages.

Get the Translations connector for the bellow examples like so:

```
use Autoborna\Transifex\Connector\Translations;

$translations = $transifex->getConnector(Translations::class);
\assert($translations instanceof Translations);
```

#### Upload a translation

[](#upload-a-translation)

[Uploading a translation](https://developers.transifex.com/reference/post_resource-translations-async-uploads) is also asynchronous. The worflow is similar to downloading translations or resources.

```
$response = $translations->upload(self::RESOURCE_SLUG, 'cs', "something=\"Něco\"\n");
$promise  = $transifex->getApiConnector()->createPromise($response);
$promises = new SplQueue();
$promise->setFilePath('/some/file.ini'); // In the real world it is useful to map your file to this promise. Useful for later processing.
$promises->enqueue($promise); // In the real world, there would be multiple promises.
usleep(500000); // Give Transifex a 1/2 second so we make 1 request instead of 2.
$transifex->getApiConnector()->fulfillPromises(
    $promises,
    function (ResponseInterface $response, Promise $promise) {
        echo "Translation for {$promise->getFilePath()} was uploaded successfully";
    },
    function (ResponseException $exception, Promise $promise) {
        echo "Translation upload for {$promise->getFilePath()} failed with {$exception->getMessage()}";
    }
);
```

#### Download a translation

[](#download-a-translation)

This is the endpoint you need to get the work of the translators back to your app. Also an async operation. [Check the docs](https://developers.transifex.com/reference/post_resource-translations-async-downloads). It uses the same pattern as the others:

```
$response = $translations->download(self::RESOURCE_SLUG, 'cs');
$promise  = $transifex->getApiConnector()->createPromise($response);
$promises = new SplQueue();
$promise->setFilePath('/some/file.ini'); // In the real world it is useful to map your file to this promise. Useful for later processing.
$promises->enqueue($promise); // In the real world, there would be multiple promises.

usleep(500000); // Give Transifex a 1/2 second so we make 1 request instead of 2.

// Assert that the translation content was downloaded successfully.
$transifex->getApiConnector()->fulfillPromises(
    $promises,
    function (ResponseInterface $response) use (&$successCounter, &$translationContent) {
        $translationContent = $response->getBody()->__toString();
        echo "Translation for {$promise->getFilePath()} was downloaded successfully. Here's the content:\n{$translationContent}";
    },
    function (ResponseException $exception) {
        echo "Translation download for {$promise->getFilePath()} failed with {$exception->getMessage()}";
    }
);
```

### Tests

[](#tests)

There is one functional test that can run all the covered API requests against an existing Transifex project. It needs a configuration to connect to that project. Copy the `phpunit.xml.dist` file and rename it to `phpunit.xml`. This creates an override of the default PHPUNIT configuration. Fill in the organization, project and API token values. The test project must have the `cs` translation available.

To run the live test execute `composer test -- --testsuite=Functional`To run the unit tests execute `composer test -- --testsuite=Unit`

Run the whole test suite: `composer test`Run static analysis checks: `composer phpstan`Run code style checks: `composer cs`Fix code style issues: `composer fixcs`

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/413e73a8de99572f990e17eb0a3f84160e41de1968b1fb0dbacbf6ceb9cba95a?d=identicon)[abbassian](/maintainers/abbassian)

---

Top Contributors

[![abbassian](https://avatars.githubusercontent.com/u/21334422?v=4)](https://github.com/abbassian "abbassian (1 commits)")

### Embed Badge

![Health badge](/badges/autoborna-transifex/health.svg)

```
[![Health](https://phpackages.com/badges/autoborna-transifex/health.svg)](https://phpackages.com/packages/autoborna-transifex)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M271](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
