, (*1)
Transifex client written in PHP.
This uses php-http
base interfaces., (*2)
Installation
$ php composer.phar require cyberspectrum/php-transifex php-http/guzzle7-adapter
Why php-http/guzzle7-adapter
?
We are decoupled form any HTTP messaging client with help by HTTPlug., (*3)
You may also install any other adapter instead of php-http/guzzle7-adapter
, just make sure one is installed., (*4)
Usage
We have two layers of API., (*5)
- Low level API in the namespace
CyberSpectrum\PhpTransifex\ApiClient
- High level entity based API in the namespace
CyberSpectrum\PhpTransifex\Model
1. Low level API.
Quick start - create an API client:, (*6)
$factory = new CyberSpectrum\PhpTransifex\ApiClient\ClientFactory(
$logger,
[new CyberSpectrum\PhpTransifex\ApiClient\Generated\Authentication\BearerAuthAuthentication($apiKey)]
);
$client = $factory->create($factory->createHttpClient());
// Fetch a project:
$project = $client->getProjectByProjectId('project-id');
2. High level API.
Create an API client:
$factory = new CyberSpectrum\PhpTransifex\ApiClient\ClientFactory(
$logger,
[new CyberSpectrum\PhpTransifex\ApiClient\Generated\Authentication\BearerAuthAuthentication($apiKey)]
);
$client = $factory->create($factory->createHttpClient());
$transifex = new CyberSpectrum\PhpTransifex\PhpTransifex($client);
Fetch an organization:
$organization = $transifex->organizations()->getBySlug('organization');
Create a project:
$project = $organization->projects()->add(
'project-slug',
'My Project description',
'en', // source language code.
'https://example.org' // the repository URL for open source projects or false for private.
);
$project->save();
Fetch a project:
$project = $transifex->organizations()->getBySlug('organization')->projects()->getBySlug('some-project');
Add a language
$project->languages()->add('de')->coordinators()->add('transifex-username');
$project->save();
// Show all language codes for the project.
var_export($project->languages()->codes());