PHPackages                             mautic/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. mautic/transifex

ActiveLibrary[API Development](/categories/api)

mautic/transifex
================

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

5.0.0(3y ago)2689.8k—3.2%12GPL-2.0+PHPPHP ~7.4|^8.0|^8.1

Since Oct 20Pushed 3y agoCompare

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

READMEChangelog (3)Dependencies (8)Versions (14)Used By (2)

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

Transifex API Package [![Scrutinizer Code Quality](https://camo.githubusercontent.com/239674be77388761e811673208cb07822dfc35491b01c727ae5eaf9e6d614a64/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d61757469632f5472616e73696665782d4150492f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mautic/Transifex-API/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/dad456e849f843290bfb8f1f76a2543af0222be4eaca5335027510a4ff650ac2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d61757469632f5472616e73696665782d4150492f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mautic/Transifex-API/?branch=master) [![Build Status](https://camo.githubusercontent.com/49d68fb43785968d6c750b006c16e7d29affe488963030c3915c2891b8ac5c3e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d61757469632f5472616e73696665782d4150492f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mautic/Transifex-API/build-status/master) [![Build Status](https://camo.githubusercontent.com/338411eb031a2fe5d3c2aa428b04887ef2869a8ab94d3fce326011c948da9d2c/68747470733a2f2f7472617669732d63692e6f72672f6d61757469632f5472616e73696665782d4150492e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mautic/Transifex-API)
=========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

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

[![Latest Stable Version](https://camo.githubusercontent.com/aca0d6d6be2d1ebb144ed8d354b07940cdfda6ebbecc28904e1e1c41241ba493/68747470733a2f2f706f7365722e707567782e6f72672f6d61757469632f7472616e73696665782f762f737461626c652e737667)](https://packagist.org/packages/mautic/transifex)[![Total Downloads](https://camo.githubusercontent.com/be741274f7ff20ee1373100cb863ca084fbed39351740371e4ac17f3aa7c6fce/68747470733a2f2f706f7365722e707567782e6f72672f6d61757469632f7472616e73696665782f646f776e6c6f6164732e737667)](https://packagist.org/packages/mautic/transifex)[![Latest Unstable Version](https://camo.githubusercontent.com/043400f9dad914838fadc64f71e7b397df2b5a699633bb32f9e108f14c4cdeee/68747470733a2f2f706f7365722e707567782e6f72672f6d61757469632f7472616e73696665782f762f756e737461626c652e737667)](https://packagist.org/packages/mautic/transifex)[![License](https://camo.githubusercontent.com/7c02e5839d766d53dee5ae9662fffe1b63fc98e6aae03fc834c2ea89f57ae298/68747470733a2f2f706f7365722e707567782e6f72672f6d61757469632f7472616e73696665782f6c6963656e73652e737667)](https://packagist.org/packages/mautic/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/mautic/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 mautic/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 Mautic\Transifex\ApiFactory;
use Mautic\Transifex\Config;
use Mautic\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 Mautic\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 \Mautic\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 `Mautic\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 Mautic\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 Mautic\Transifex\Promise;
use Mautic\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 Mautic\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

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 84.7% 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.

###  Release Activity

Cadence

Every ~246 days

Recently: every ~373 days

Total

13

Last Release

1268d ago

Major Versions

1.x-dev → 2.0.02016-12-21

2.x-dev → 3.0.02019-11-20

3.0.0 → 4.0.02020-01-07

4.1.0 → 5.0.02022-11-28

PHP version history (6 changes)1.0.0PHP &gt;=5.3.10

1.3.0PHP ^5.3.10|~7.0

2.0.0PHP ~7.0

3.0.0PHP ~7.2

4.1.0PHP ~7.2|^8.0

5.0.0PHP ~7.4|^8.0|^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/514789?v=4)[Acquia](/maintainers/acquia)[@acquia](https://github.com/acquia)

![](https://avatars.githubusercontent.com/u/718028?v=4)[Don Gilbert](/maintainers/dongilbert)[@dongilbert](https://github.com/dongilbert)

![](https://avatars.githubusercontent.com/u/2930593?v=4)[Ruth Cheesley](/maintainers/rcheesley)[@RCheesley](https://github.com/RCheesley)

---

Top Contributors

[![mbabker](https://avatars.githubusercontent.com/u/368545?v=4)](https://github.com/mbabker "mbabker (310 commits)")[![escopecz](https://avatars.githubusercontent.com/u/1235442?v=4)](https://github.com/escopecz "escopecz (42 commits)")[![elkuku](https://avatars.githubusercontent.com/u/33978?v=4)](https://github.com/elkuku "elkuku (5 commits)")[![wilsonge](https://avatars.githubusercontent.com/u/1986000?v=4)](https://github.com/wilsonge "wilsonge (5 commits)")[![dennisameling](https://avatars.githubusercontent.com/u/17739158?v=4)](https://github.com/dennisameling "dennisameling (2 commits)")[![leofeyer](https://avatars.githubusercontent.com/u/1192057?v=4)](https://github.com/leofeyer "leofeyer (1 commits)")[![RCheesley](https://avatars.githubusercontent.com/u/2930593?v=4)](https://github.com/RCheesley "RCheesley (1 commits)")

---

Tags

phptransifex

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k22.6M232](/packages/openai-php-client)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

963.1M35](/packages/getbrevo-brevo-php)[swisnl/json-api-client

A PHP package for mapping remote JSON:API resources to Eloquent like models and collections.

211473.2k12](/packages/swisnl-json-api-client)[wordpress/php-ai-client

A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.

26236.6k14](/packages/wordpress-php-ai-client)[mozex/anthropic-php

Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.

46365.1k13](/packages/mozex-anthropic-php)

PHPackages © 2026

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