Flash applicative Translate - client component
This package is auto-updated.
Last update: 2022-06-21 17:26:58 UTC
- Step by step installation
- Link to documentation
This client permit to use the
Translate Api. Thanks to it, you could request the API to :
- Fetch data
- Create data
- Update data
- Delete data
- PHP 5.5
for all purposes (devlopment, contribution and production)
- Cloning repository
git clone https://github.com/flash-global/translate-client.git
- Run Composer depedencies installation
The Translate client needs some options to work properly. The available options that can be passed to the
setOptions() methods are :
|OPTION_BASEURL||This is the server to which send the requests.||string||Any URL, including protocol but excluding path||--|
|OPTION_HEADER_AUTHORIZATION||Api Key for authentification||string||Any string value||''|
Don't forget to set the right
<?php $translate = new Translate([Translate::OPTION_BASEURL => 'http://translate.dev']); $translate->setTransport(new BasicTransport());
Running Beanstalkd is very simple. However, you must pay attention to the
z option which set the maximum job (or message) size in bytes. So, if you want send multiple translations to Translate API, you should allow enough bytes according to the length of your translations.
Start the docker with
docker-compose up -d
docker exec -ti translateclient_php_1 /var/html/vendor/bin/codecept run unit
You could see below an example of running
php /path/to/translate-client/vendor/bin/api-client-worker.php --host 127.0.0.1 --port 11300 --delay 3
||The host of Beanstalkd instance||
||The port which Beanstalkd instance listening||
||The delay between two treatment of the worker||3 seconds|
||Print verbose information||-|
You can control the api-client-worker.php process by using Supervisor.
In order to make the client working properly, you need to configure a couple of paramaters :.
The configuration takes place in the
config/config.php file. Here is a complete example of the configurations :
<?php return [ 'lock_file' => dirname(__DIR__) . '/.translations.lock', 'data_path' => dirname(__DIR__) . '/data', 'translations_path' => dirname(__DIR__) . '/translations', 'servers' => [ 'http://10.5.0.1:8010' => [ 'namespaces' => ['/a/b/c/d'] ] ], 'url' => 'http://10.6.0.1:8040/examples/handleRequest.php/update' ];
lock_file: this configuration is used to locate the
lockused to determine if you have already subscribed to an API server
data_path: this configuration is used to set one directory that will be used to store temporary data when updating the translation cache of your client
translations_path: this configuration is used to set one directory that will be used to store your translation cache files
servers: this is an array defining all the servers you want to subscribe when calling the
Translate::subscribemethod without any
$serverin the parameter of the method.
url: this is the url used to listen the requests coming from the Translate API server when sending new translation cache files. Do not forget this parameter otherwise you will not receive any translations
No known issue at this time.
As FEI Service, designed and made by OpCoding. The contribution workflow will involve both technical teams. Feel free to contribute, to improve features and apply patches, but keep in mind to carefully deal with pull request. Merging must be the product of complete discussions between Flash and OpCoding teams :)
You can test this client easily thanks to the folder examples
Here, an example on how to use example :
In order to consume
Translate methods, you have to define a new
Translate instance and set the right transport (Asynchronously or Synchronously).
<?php use Fei\Service\Translate\Client\ Translate; use Fei\ApiClient\Transport\BasicTransport; use Fei\ApiClient\Transport\BeanstalkProxyTransport; use Pheanstalk\Pheanstalk; $translate = new Translate([Translate::OPTION_BASEURL => 'https://translate.api']); // Put your translate API base URL here $translate->setTransport(new BasicTransport()); $proxy = new BeanstalkProxyTransport(); $proxy->setPheanstalk(new Pheanstalk('127.0.0.1')); $translate->setAsyncTransport($proxy); // Use the translate client methods...
Translate client instance will first attempt to transfer the messages with Beanstalkd, if the process fail then the client will try to send I18nString payload directly to the right API endpoint.
There are several methods in Translate class, all listed in the following table: