cyberspectrum/php-transifex

transifex API client written 100% in PHP

2.0.3 2023-08-16 10:38 UTC

This package is auto-updated.

Last update: 2024-12-16 16:56:31 UTC


README

Build Status Latest Version tagged Latest Version on Packagist Installations via composer per month

Transifex client written in PHP.

This uses php-http base interfaces.

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.

You may also install any other adapter instead of php-http/guzzle7-adapter, just make sure one is installed.

Usage

We have two layers of API.

  1. Low level API in the namespace CyberSpectrum\PhpTransifex\ApiClient
  2. High level entity based API in the namespace CyberSpectrum\PhpTransifex\Model

1. Low level API.

Quick start - create an API client:

$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());