pervozdanniy/translation-storage

v2.2.0 2020-07-06 12:25 UTC

This package is auto-updated.

Last update: 2024-11-06 22:11:46 UTC


README

Latest Stable Version Total Downloads Software License

API Documentation

Installation

The recommended way to install is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version of Guzzle:

composer require pervozdanniy/translation-storage

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

You can then later update Guzzle using composer:

composer update

Usage

  1. Create an api adapter
class ApiAdapter implements \Translate\StorageManager\Contracts\Api
{
    // MUST return data compatible with storage's data structure
    public function fetch(array $params = [], int $page = 1) : array
    {
        // TODO: Implement fetch() method.
        return [];
    }
}
  1. Initialize Storage Manager
/** @var \Translate\StorageManager\Contracts\Api $api */
$api = new ApiAdapter();

$builder = \Elasticsearch\ClientBuilder::create();
// set all options for elastic client you need
$elastic = $builder->build();
$storage = new \Translate\StorageManager\Storage\ElasticStorage($elastic);
// you can pass any storage you want that implements \Translate\StorageManager\Contracts\TranslationStorage interface
$manager = new \Translate\StorageManager\Manager($api, $storage);
$manager->update(['en', 'es', 'ru']);
  1. Update your translations whenever you need
/** @var \Translate\StorageManager\Manager $manager*/
//update all translation groups for specified languages
$manager->update(['en', 'es', 'ru']);

//update specified group
$manager->updateGroup('app', ['en', 'es', 'ru']);

Configuration Options