pervozdanniy / translation-storage
Storage for translations
v2.2.0
2020-07-06 12:25 UTC
Requires
- php: ^7.2
- elasticsearch/elasticsearch: ^7.2
Requires (Dev)
README
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
- 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 []; } }
- 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']);
- 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']);